Skip to content

Commit

Permalink
add overlay logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Aug 19, 2024
1 parent 8150b72 commit 3607f4a
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 @@ -248,7 +248,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 @@ -105,6 +106,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 @@ -123,6 +125,7 @@ mutable struct Scene <: AbstractScene
plots,
theme,
children,
overlay_start,
current_screens,
backgroundcolor,
visible,
Expand Down Expand Up @@ -207,6 +210,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 @@ -244,7 +248,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
)
camera isa Function && camera(scene)

Expand Down Expand Up @@ -294,6 +298,7 @@ function Scene(
camera=nothing,
camera_controls=parent.camera_controls,
transformation=Transformation(parent),
overlay::Bool = false,
kw...
)

Expand Down Expand Up @@ -322,7 +327,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 @@ -415,8 +424,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 @@ -433,6 +452,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 @@ -452,12 +472,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 3607f4a

Please sign in to comment.