Skip to content

Commit

Permalink
add tooltips to Textboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Sep 23, 2024
1 parent da86824 commit e682516
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/makielayout/blocks/textbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ function initialize_block!(tbox::Textbox)
# trigger bbox
tbox.layoutobservables.suggestedbbox[] = tbox.layoutobservables.suggestedbbox[]

ttposition = lift(tbox.tooltip_placement, tbox.layoutobservables.computedbbox) do placement, bbox
if placement == :above
bbox.origin + Point2f((bbox.widths[1]/2, bbox.widths[2]))
elseif placement == :below
bbox.origin + Point2f((bbox.widths[1]/2, 0))
elseif placement == :left
bbox.origin + Point2f((0, bbox.widths[2]/2))
elseif placement == :right
bbox.origin + Point2f((bbox.widths[1], bbox.widths[2]/2))

Check warning on line 124 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L119-L124

Added lines #L119 - L124 were not covered by tests
end
end
ttvisible = lift((x,y)->x && y, tbox.tooltip_enable, hovering)
tt = tooltip!(topscene, ttposition, tbox.tooltip_text,
visible=ttvisible, placement=tbox.tooltip_placement, overdraw=true;
tbox.tooltip_kwargs[]...)

mouseevents = addmouseevents!(scene)

onmouseleftdown(mouseevents) do state
Expand Down
8 changes: 8 additions & 0 deletions src/makielayout/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,14 @@ end
restriction = nothing
"The color of the cursor."
cursorcolor = :transparent
"The String displayed by the tooltip."
tooltip_text = ""
"Sets where the tooltip should be placed relative to the Textbox. Can be :above, :below, :left, :right."
tooltip_placement = :above
"Controls whether the tooltip will be rendered or not."
tooltip_enable = false
"Keyword arguments to pass to the tooltip. See the tooltip docstring for valid attributes."
tooltip_kwargs = ()
end
end

Expand Down

0 comments on commit e682516

Please sign in to comment.