diff --git a/CHANGELOG.md b/CHANGELOG.md index 33c4f39a06d..15373ccfb63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- add vertically oriented Toggle [#4445](https://github.com/MakieOrg/Makie.jl/pull/4445) - Optimize SpecApi, re-use Blocks better and add API to access the created block objects [#4354](https://github.com/MakieOrg/Makie.jl/pull/4354). - Fix `merge(attr1, attr2)` modifying nested attributes in `attr1` [#4416](https://github.com/MakieOrg/Makie.jl/pull/4416) - Fixed issue with CairoMakie rendering scene backgrounds at the wrong position [#4425](https://github.com/MakieOrg/Makie.jl/pull/4425) diff --git a/ReferenceTests/src/tests/figures_and_makielayout.jl b/ReferenceTests/src/tests/figures_and_makielayout.jl index b61da7b1348..fb99f3205dc 100644 --- a/ReferenceTests/src/tests/figures_and_makielayout.jl +++ b/ReferenceTests/src/tests/figures_and_makielayout.jl @@ -410,4 +410,13 @@ end Makie.Checkbox(f[2, 4], checked = false, checkboxcolor_unchecked = :yellow) Makie.Checkbox(f[2, 5], checked = true, checkboxcolor_checked = :orange) f -end \ No newline at end of file +end + +@reference_test "Toggle" begin + f = Figure() + th = Makie.Toggle(f[1,1]) + th.orientation[] = :vertical + tv = Makie.Toggle(f[2,1], orientation=:vertical) + tv.orientation[] = :horizontal + f +end diff --git a/src/makielayout/blocks/toggle.jl b/src/makielayout/blocks/toggle.jl index 2c37f8d38ba..32092d32210 100644 --- a/src/makielayout/blocks/toggle.jl +++ b/src/makielayout/blocks/toggle.jl @@ -2,18 +2,39 @@ function initialize_block!(t::Toggle) topscene = t.blockscene + on(t.orientation) do or + if or == :horizontal + t.width[] = 32 + t.height[] = 18 + elseif or == :vertical + t.width[] = 18 + t.height[] = 32 + else + error("orientation must be either :horizontal or :vertical") + end + end + notify(t.orientation) + markersize = lift(topscene, t.layoutobservables.computedbbox) do bbox min(width(bbox), height(bbox)) end - button_endpoint_inactive = lift(topscene, markersize) do ms + button_endpoint_inactive = lift(topscene, markersize, t.orientation) do ms, or bbox = t.layoutobservables.computedbbox[] - Point2f(left(bbox) + ms / 2, bottom(bbox) + ms / 2) + if or == :horizontal + Point2f(left(bbox) + ms / 2, bottom(bbox) + ms / 2) + elseif or == :vertical + Point2f(left(bbox) + ms / 2, bottom(bbox) + ms / 2) + end end - button_endpoint_active = lift(topscene, markersize) do ms + button_endpoint_active = lift(topscene, markersize, t.orientation) do ms, or bbox = t.layoutobservables.computedbbox[] - Point2f(right(bbox) - ms / 2, bottom(bbox) + ms / 2) + if or == :horizontal + Point2f(right(bbox) - ms / 2, bottom(bbox) + ms / 2) + elseif or == :vertical + Point2f(left(bbox) + ms / 2, top(bbox) - ms / 2) + end end buttonvertices = lift(topscene, markersize, t.cornersegments) do ms, cs diff --git a/src/makielayout/types.jl b/src/makielayout/types.jl index 4da455bf423..8f9f2fe572f 100644 --- a/src/makielayout/types.jl +++ b/src/makielayout/types.jl @@ -1159,9 +1159,9 @@ end "The vertical alignment of the toggle in its suggested bounding box." valign = :center "The width of the toggle." - width = 32 + width = Auto() "The height of the toggle." - height = 18 + height = Auto() "Controls if the parent layout can adjust to this element's width" tellwidth = true "Controls if the parent layout can adjust to this element's height" @@ -1185,6 +1185,8 @@ end rimfraction = 0.33 "The align mode of the toggle in its parent GridLayout." alignmode = Inside() + "The orientation of the toggle (:horizontal or :vertical)." + orientation = :horizontal end end diff --git a/test/makielayout.jl b/test/makielayout.jl index 6c266f0b2a2..3f97a87bdd4 100644 --- a/test/makielayout.jl +++ b/test/makielayout.jl @@ -541,3 +541,10 @@ end end @test isempty(limits.listeners) end + +@testset "Toggle" begin + f = Figure() + Toggle(f[1,1]) + Toggle(f[2,1], orientation=:vertical) + @test_throws ErrorException Toggle(f[3,1], orientation=:diagonal) +end