Skip to content

Commit

Permalink
Added error messages in grid function for invalid values for heights …
Browse files Browse the repository at this point in the history
…and widths (#4902)

* add error messages in GridLayout to handle invalid values for heights and widths

* Used JuliaFormatter
  • Loading branch information
Gythre-9 authored Mar 11, 2024
1 parent 39c4fc5 commit 2e9b16c
Showing 1 changed file with 20 additions and 2 deletions.
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

0 comments on commit 2e9b16c

Please sign in to comment.