@@ -617,11 +617,11 @@ function REPL.fielddoc(t::Type{<:Block}, s::Symbol)
617
617
end
618
618
619
619
"""
620
- function tooltip!(b::Block, str::AbstractString; placement=:above, kwargs...)
620
+ function tooltip!(b::Block, str::AbstractString; placement=:above, visible=:always, depth=9e3, kwargs...)
621
621
622
- Adds a tooltip to a block. See `tooltip` for more details. To make it only
623
- appear when hovering, set the `visible` property of the tooltip to the
624
- `hovering` property of the block .
622
+ Adds a tooltip to a block. `visible` can be `:always`, `:hover`, or `:never`.
623
+ `depth` should be large to ensure that the tooltip is in front. See `tooltip`
624
+ for more details .
625
625
626
626
# Examples
627
627
```julia-repl
@@ -630,20 +630,23 @@ julia> f = Figure()
630
630
julia> t = Toggle(f[1,1])
631
631
Toggle()
632
632
633
- julia> tooltip!(t, "I'm a Toggle", visible = t.hovering )
633
+ julia> tooltip!(t, "I'm a Toggle", visible = :hover )
634
634
Plot{Makie.tooltip, Tuple{Vec{2, Float32}, String}}
635
635
636
636
julia> b = Button(f[2,1])
637
637
Button()
638
638
639
- julia> tt = tooltip!(b, "I'm a Button", placement = :below)
639
+ julia> v = Observable(:never)
640
+ Observable(:never)
641
+
642
+ julia> tt = tooltip!(b, "I'm a Button", placement = :below, visible = v)
640
643
Plot{Makie.tooltip, Tuple{Vec{2, Float32}, String}}
641
644
642
- julia> on(h -> tt.visible[]=h, b.hovering)
643
- ObserverFunction defined at REPL[7]:1 operating on Observable(false)
645
+ julia> v[] = :always
646
+ :always
644
647
```
645
648
"""
646
- function tooltip! (b:: Block , str:: AbstractString ; placement= :above , kwargs... )
649
+ function tooltip! (b:: Block , str:: AbstractString ; placement= :above , visible = :always , depth = 9e3 , kwargs... )
647
650
position = lift (b. layoutobservables. computedbbox) do bbox
648
651
if placement == :above
649
652
bbox. origin + Point2f ((bbox. widths[1 ]/ 2 , bbox. widths[2 ]))
@@ -656,11 +659,21 @@ function tooltip!(b::Block, str::AbstractString; placement=:above, kwargs...)
656
659
elseif placement == :center
657
660
bbox. origin + Point2f ((bbox. widths[1 ]/ 2 , bbox. widths[2 ]/ 2 ))
658
661
else
659
- @error (" invalid value for tooltip_placement , using :above" )
662
+ @error (" invalid value for tooltip placement , using :above" )
660
663
bbox. origin + Point2f ((bbox. widths[1 ]/ 2 , bbox. widths[2 ]))
661
664
end
662
665
end
663
666
tt = tooltip! (b. blockscene, position, str; placement, kwargs... )
664
- translate! (tt, 0 , 0 , 9e3 )
667
+ translate! (tt, 0 , 0 , depth)
668
+ onany (b. blockscene. events. mouseposition, visible) do mp, v
669
+ tt. visible[] = if v == :never
670
+ false
671
+ elseif v == :hover
672
+ mp in b. layoutobservables. computedbbox[]
673
+ else
674
+ v == :always || @error (" invalid value for tooltip visible, using :always" )
675
+ true
676
+ end
677
+ end
665
678
return tt
666
679
end
0 commit comments