Skip to content

Commit

Permalink
Merge branch 'ff/render_order' of https://github.com/MakieOrg/Makie.jl
Browse files Browse the repository at this point in the history
…into ff/render_order
  • Loading branch information
ffreyer committed Nov 15, 2024
2 parents eea9e22 + 3607f4a commit 0b234ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/interaction/inspector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ end
function DataInspector(scene::Scene; priority = 100, kwargs...)
parent = root(scene)
@assert origin(viewport(parent)[]) == Vec2f(0)
scene = Scene(parent, viewport = parent.viewport, clear = false)
scene = Scene(parent, viewport = parent.viewport, clear = false, overlay = true)
campixel!(scene)

attrib_dict = Dict(kwargs)
Expand Down
39 changes: 35 additions & 4 deletions src/scenes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mutable struct Scene <: AbstractScene

"Children of the Scene inherit its transformation."
children::Vector{Scene}
overlay_start::Int

"""
The Screens which the Scene is displayed to.
Expand Down Expand Up @@ -106,6 +107,7 @@ mutable struct Scene <: AbstractScene
plots::Vector{AbstractPlot},
theme::Attributes,
children::Vector{Scene},
overlay_start::Int,
current_screens::Vector{MakieScreen},
backgroundcolor::Observable{RGBAf},
visible::Observable{Bool},
Expand All @@ -125,6 +127,7 @@ mutable struct Scene <: AbstractScene
plots,
theme,
children,
overlay_start,
current_screens,
backgroundcolor,
visible,
Expand Down Expand Up @@ -217,6 +220,7 @@ function Scene(;
transformation::Transformation = Transformation(transform_func),
plots::Vector{AbstractPlot} = AbstractPlot[],
children::Vector{Scene} = Scene[],
overlay_start::Int = length(children)+1,
current_screens::Vector{MakieScreen} = MakieScreen[],
parent = nothing,
visible = Observable(true),
Expand Down Expand Up @@ -255,7 +259,7 @@ function Scene(;
scene = Scene(
parent, events, viewport, clear, cam, camera_controls,
transformation, plots, m_theme,
children, current_screens, bg, visible, ssao, _lights;
children, overlay_start, current_screens, bg, visible, ssao, _lights;
deregister_callbacks=deregister_callbacks
)
camera isa Function && camera(scene)
Expand Down Expand Up @@ -307,6 +311,7 @@ function Scene(
visible=parent.visible,
camera_controls=parent.camera_controls,
transformation=Transformation(parent),
overlay::Bool = false,
kw...
)

Expand Down Expand Up @@ -352,7 +357,11 @@ function Scene(
error("viewport must be an Observable{Rect2} or a Rect2")
end
end
push!(parent, child)
if overlay
push_overlay!(parent, child)
else
push!(parent, child)
end
child.parent = parent
return child
end
Expand Down Expand Up @@ -445,8 +454,18 @@ function free(scene::Scene)
delete!(screen, scene)
end
# remove from parent
if !isnothing(scene.parent)
filter!(x-> x !== scene, scene.parent.children)
parent = scene.parent
if !isnothing(parent)
idx = findfirst(==(scene), parent.children)
if idx === nothing
@warn "Freed scene not a child of it's parent"
else
# if we are deletinng a normal scene we need to move the overlay start index
if !(parent.overlay_start <= idx <= length(parent.children))
parent.overlay_start -= 1
end
deleteat!(parent.children, idx)
end
end
empty!(scene.current_screens)
scene.parent = nothing
Expand All @@ -463,6 +482,7 @@ function Base.empty!(scene::Scene; free=false)
end

empty!(scene.children)
scene.overlay_start = 1
empty!(scene.plots)
empty!(scene.theme)
# conditional, since in free we dont want this!
Expand All @@ -482,12 +502,23 @@ function Base.empty!(scene::Scene; free=false)
end

function Base.push!(parent::Scene, child::Scene)
@assert isempty(child.children) "Adding a scene with children to a parent not yet implemented"
insert!(parent.children, parent.overlay_start, child)
for screen in parent.current_screens
Base.invokelatest(insert!, screen, child, parent, parent.overlay_start)
end
parent.overlay_start += 1
return
end

function push_overlay!(parent::Scene, child::Scene)
@assert isempty(child.children) "Adding a scene with children to a parent not yet implemented"
push!(parent.children, child)
idx = length(parent.children)
for screen in parent.current_screens
Base.invokelatest(insert!, screen, child, parent, idx)
end
return
end

function Base.push!(plot::Plot, subplot)
Expand Down

0 comments on commit 0b234ee

Please sign in to comment.