I have a newbie question. What I understand that a struct will have fields and once pass them by order. Like :
julia> struct Foo
bar
baz
end
julia> foo = Foo(1, 2)
Foo(1, 2)
In something like Makie, the main struct is Figure(). All the tutorials are showing customized arguments like backgroundcolor, resolution ...etc.
f = Figure(backgroundcolor = :tomato)
But in the docstring, there is no mentioning for these keywords.
Thank you in advance
I think this is a duplicate of: Pass arguments to @kwdef struct programmatically
But to answer your question, as shown there you can have keyword fields by placing the
Base.@kwdefmacro beforestruct, i.e.:Then doing
Foo(baz=3)returnsFoo(nothing,3)etc.To answer your question about what they do in
Makie, here is their relevant bit of code for making Figures (from their GitHub source code):They create a dictionary based on the keyword arguments, then pass those manually to the Figure struct, which is defined as:
So they use the
Figurefunction to access the keyword arguments and then pass the appropriate keywords to theFigurestruct.