diff --git a/Widgets.go b/Widgets.go index 2f12ddc3..a0bb17cd 100644 --- a/Widgets.go +++ b/Widgets.go @@ -670,6 +670,7 @@ var _ Widget = &TooltipWidget{} type TooltipWidget struct { tip string layout Layout + to Layout } // Tooltip creates new tooltip with given label @@ -692,8 +693,28 @@ func (t *TooltipWidget) Layout(widgets ...Widget) *TooltipWidget { return t } +// To sets layout to which the tooltip should be attached. +// NOTE: This is an optional approach. By default tooltip is attached to the previous widget. +func (t *TooltipWidget) To(layout ...Widget) *TooltipWidget { + t.to = Layout(layout) + return t +} + // Build implements Widget interface. func (t *TooltipWidget) Build() { + if t.to != nil { + t.to.Range(func(w Widget) { + w.Build() + t.buildTooltip() + }) + + return + } + + t.buildTooltip() +} + +func (t *TooltipWidget) buildTooltip() { if imgui.IsItemHovered() { if t.layout != nil { imgui.BeginTooltip() diff --git a/examples/widgets/widgets.go b/examples/widgets/widgets.go index 86db33f2..2046d774 100644 --- a/examples/widgets/widgets.go +++ b/examples/widgets/widgets.go @@ -78,6 +78,12 @@ func loop() { g.BulletText("I could be any widgets"), ), ), + + g.Tooltip("This tooltip is attached to a layout!").To( + g.Label("We are labels"), + g.Label("And there is the same tooltip"), + g.Label("Attached to us!"), + ), g.InputText(&name).Label("Input text with auto complete, input hw and press enter").Size(300).AutoComplete(autoCompleteCandidates), g.DatePicker("Date Picker", &date).OnChange(func() { fmt.Println(date)