diff --git a/src/makielayout/blocks/textbox.jl b/src/makielayout/blocks/textbox.jl index f679c7a9222..747445a56d1 100644 --- a/src/makielayout/blocks/textbox.jl +++ b/src/makielayout/blocks/textbox.jl @@ -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)) + 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 diff --git a/src/makielayout/types.jl b/src/makielayout/types.jl index fda5d43bdac..15cf4b5f922 100644 --- a/src/makielayout/types.jl +++ b/src/makielayout/types.jl @@ -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