Skip to content

Commit

Permalink
Merge pull request #800 from gucio321/layout-to-tooltip
Browse files Browse the repository at this point in the history
tooltip: add possibility to set layout to which the tooltip will be a…
  • Loading branch information
gucio321 authored Jul 7, 2024
2 parents 0651ee5 + 28ab27f commit ceed22f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ var _ Widget = &TooltipWidget{}
type TooltipWidget struct {
tip string
layout Layout
to Layout
}

// Tooltip creates new tooltip with given label
Expand All @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions examples/widgets/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ceed22f

Please sign in to comment.