diff --git a/src/interaction/inspector.jl b/src/interaction/inspector.jl index 8f94d9393ad..bd9fbd8bd87 100644 --- a/src/interaction/inspector.jl +++ b/src/interaction/inspector.jl @@ -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) diff --git a/src/scenes.jl b/src/scenes.jl index 12dd94625f9..516b4b84f52 100644 --- a/src/scenes.jl +++ b/src/scenes.jl @@ -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. @@ -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}, @@ -125,6 +127,7 @@ mutable struct Scene <: AbstractScene plots, theme, children, + overlay_start, current_screens, backgroundcolor, visible, @@ -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), @@ -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) @@ -307,6 +311,7 @@ function Scene( visible=parent.visible, camera_controls=parent.camera_controls, transformation=Transformation(parent), + overlay::Bool = false, kw... ) @@ -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 @@ -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 @@ -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! @@ -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)