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

Added error messages in grid function for invalid values for heights and widths #4902

Merged
merged 2 commits into from
Mar 11, 2024
Merged
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
22 changes: 20 additions & 2 deletions src/layouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,28 @@ grid(args...; kw...) = GridLayout(args...; kw...)
function GridLayout(
dims...;
parent = RootLayout(),
widths = zeros(dims[2]),
heights = zeros(dims[1]),
widths = nothing,
heights = nothing,
kw...,
)
# Check the values for heights and widths if values are provided
if heights !== nothing && widths !== nothing
if sum(heights) != 1
error("The sum of heights must be 1!")
end
if sum(widths) != 1
error("The sum of widths must be 1!")
end
if all(x -> 0 < x < 1, widths) == false
error("Values for widths must be in the range (0, 1)!")
end
if all(x -> 0 < x < 1, heights) == false
error("Values for heights must be in the range (0, 1)!")
end
else
heights = zeros(dims[1])
widths = zeros(dims[2])
end
grid = Matrix{AbstractLayout}(undef, dims...)
layout = GridLayout(
parent,
Expand Down
Loading