Skip to content

Commit

Permalink
Improve inferrability and use enums rather than types for some settings
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Jul 31, 2021
1 parent 6076b9c commit 96f3309
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 283 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
[compat]
GeometryBasics = "0.4.1"
Match = "^1"
Observables = "0.3, 0.4"
Observables = "0.4"
julia = "1"

[extras]
Expand Down
8 changes: 6 additions & 2 deletions src/GridLayoutBase.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module GridLayoutBase

if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@compiler_options"))
@eval Base.Experimental.@compiler_options compile=min optimize=1
end

using GeometryBasics
using Observables
using Match

const DEFAULT_COLGAP = Ref{Any}(20.0)
const DEFAULT_ROWGAP = Ref{Any}(20.0)
const DEFAULT_COLGAP = Ref{Float64}(20.0)
const DEFAULT_ROWGAP = Ref{Float64}(20.0)
# These function refs can be mutated by other packages to override the default
# way of retrieving default column and row gap sizes
const DEFAULT_ROWGAP_GETTER = Ref{Function}(() -> DEFAULT_ROWGAP[])
Expand Down
15 changes: 8 additions & 7 deletions src/geometry_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ width(rect::Rect{2}) = right(rect) - left(rect)
height(rect::Rect{2}) = top(rect) - bottom(rect)


function BBox(left::Number, right::Number, bottom::Number, top::Number)
function BBox(left::Float32, right::Float32, bottom::Float32, top::Float32)
mini = (left, bottom)
maxi = (right, top)
return Rect2f(mini, maxi .- mini)
end

BBox(left::Number, right::Number, bottom::Number, top::Number) =
BBox(Float32(left)::Float32, Float32(right)::Float32, Float32(bottom)::Float32, Float32(top)::Float32)

function RowCols(ncols::Int, nrows::Int)
return RowCols(
Expand All @@ -23,17 +24,17 @@ function RowCols(ncols::Int, nrows::Int)
)
end

Base.getindex(rowcols::RowCols, ::Left) = rowcols.lefts
Base.getindex(rowcols::RowCols, ::Right) = rowcols.rights
Base.getindex(rowcols::RowCols, ::Top) = rowcols.tops
Base.getindex(rowcols::RowCols, ::Bottom) = rowcols.bottoms
Base.getindex(rowcols::RowCols, side::Side) = side == Left ? rowcols.lefts :
side == Right ? rowcols.rights :
side == Top ? rowcols.tops :
side == Bottom ? rowcols.bottoms : throw_side(side)

"""
eachside(f)
Calls f over all sides (Left, Right, Top, Bottom), and creates a BBox from the result of f(side)
"""
function eachside(f)
    return BBox(f(Left()), f(Right()), f(Bottom()), f(Top()))
    return BBox(f(Left), f(Right), f(Bottom), f(Top))
end

"""
Expand Down
Loading

0 comments on commit 96f3309

Please sign in to comment.