Skip to content

Commit

Permalink
add default to theme methods (#3214)
Browse files Browse the repository at this point in the history
* add default to theme methods

* add test

---------

Co-authored-by: Pepijn de Vos <pepijn.devos@juliacomputing.com>
  • Loading branch information
pepijndevos and Pepijn de Vos authored Sep 7, 2023
1 parent 882c827 commit 7ebe960
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions MakieCore/src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ end
# Since we can use Combined like a scene in some circumstances, we define this alias
theme(x::SceneLike, args...) = theme(x.parent, args...)
theme(x::AbstractScene) = x.theme
theme(x::AbstractScene, key) = deepcopy(x.theme[key])
theme(x::AbstractPlot, key) = deepcopy(x.attributes[key])
theme(x::AbstractScene, key; default=nothing) = deepcopy(get(x.theme, key, default))
theme(x::AbstractPlot, key; default=nothing) = deepcopy(get(x.attributes, key, default))

Attributes(x::AbstractPlot) = x.attributes

Expand Down
2 changes: 1 addition & 1 deletion src/theming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function with_theme(f, theme = Theme(); kwargs...)
end
end

theme(::Nothing, key::Symbol) = theme(key)
theme(::Nothing, key::Symbol; default=nothing) = theme(key; default)
function theme(key::Symbol; default=nothing)
if haskey(CURRENT_DEFAULT_THEME, key)
val = to_value(CURRENT_DEFAULT_THEME[key])
Expand Down
2 changes: 2 additions & 0 deletions test/scenes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
@testset "getproperty(scene, :$field)" for field in fieldnames(Scene)
@test getproperty(scene, field) !== missing # well, just don't error
end
@test theme(nothing, :nonexistant, default=1) == 1
@test theme(scene, :nonexistant, default=1) == 1
end

0 comments on commit 7ebe960

Please sign in to comment.