Skip to content

Commit

Permalink
add vertical orientation option to Toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Oct 3, 2024
1 parent 2bb4de0 commit 73a3bab
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion ReferenceTests/src/tests/figures_and_makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,12 @@ end
Makie.Checkbox(f[2, 4], checked = false, checkboxcolor_unchecked = :yellow)
Makie.Checkbox(f[2, 5], checked = true, checkboxcolor_checked = :orange)
f
end
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
end
29 changes: 25 additions & 4 deletions src/makielayout/blocks/toggle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 11 in src/makielayout/blocks/toggle.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/toggle.jl#L5-L11

Added lines #L5 - L11 were not covered by tests
else
error("orientation must be either :horizontal or :vertical")

Check warning on line 13 in src/makielayout/blocks/toggle.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/toggle.jl#L13

Added line #L13 was not covered by tests
end
end
notify(t.orientation)

Check warning on line 16 in src/makielayout/blocks/toggle.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/toggle.jl#L16

Added line #L16 was not covered by tests

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

Check warning on line 22 in src/makielayout/blocks/toggle.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/toggle.jl#L22

Added line #L22 was not covered by tests
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)

Check warning on line 27 in src/makielayout/blocks/toggle.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/toggle.jl#L24-L27

Added lines #L24 - L27 were not covered by tests
end
end

button_endpoint_active = lift(topscene, markersize) do ms
button_endpoint_active = lift(topscene, markersize, t.orientation) do ms, or

Check warning on line 31 in src/makielayout/blocks/toggle.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/toggle.jl#L31

Added line #L31 was not covered by tests
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)

Check warning on line 36 in src/makielayout/blocks/toggle.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/toggle.jl#L33-L36

Added lines #L33 - L36 were not covered by tests
end
end

buttonvertices = lift(topscene, markersize, t.cornersegments) do ms, cs
Expand Down
6 changes: 4 additions & 2 deletions src/makielayout/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down
7 changes: 7 additions & 0 deletions test/makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 73a3bab

Please sign in to comment.