Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vertical orientation option to Toggle #4445

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 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,13 @@ 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
f
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 @@

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
Loading