pub struct Scene { /* private fields */ }Expand description
A pan/zoom canvas hosting a single content widget subtree.
See the module docs for the coordinate model and the keyboard-focus limitation.
Implementations§
Source§impl Scene
impl Scene
Sourcepub fn new(content: Box<dyn Widget>) -> Self
pub fn new(content: Box<dyn Widget>) -> Self
Create a Scene hosting content, with the default egui zoom range.
Sourcepub fn with_zoom_range(self, min: f64, max: f64) -> Self
pub fn with_zoom_range(self, min: f64, max: f64) -> Self
Set the allowed zoom range (min, max). Values are screen-px per scene unit. Passing them reversed is tolerated.
Sourcepub fn with_content_size(self, size: Size) -> Self
pub fn with_content_size(self, size: Size) -> Self
Lay the content out against this fixed size instead of the Scene’s available size. Use when the content should occupy a definite scene-space extent regardless of the container size.
Sourcepub fn with_default_scene_rect(self, rect: Rect) -> Self
pub fn with_default_scene_rect(self, rect: Rect) -> Self
Scene-space rect that the initial fit and “reset view” target. When unset, the content’s laid-out bounds are fitted instead.
Sourcepub fn with_scene_rect_cell(self, cell: Rc<Cell<Rect>>) -> Self
pub fn with_scene_rect_cell(self, cell: Rc<Cell<Rect>>) -> Self
Publish the visible scene rect into cell on every layout.
Sourcepub fn with_reset_cell(self, cell: Rc<Cell<bool>>) -> Self
pub fn with_reset_cell(self, cell: Rc<Cell<bool>>) -> Self
Bind a cell that, when set to true, resets the view on the next layout.
pub fn with_margin(self, m: Insets) -> Self
pub fn with_h_anchor(self, h: HAnchor) -> Self
pub fn with_v_anchor(self, v: VAnchor) -> Self
pub fn with_min_size(self, s: Size) -> Self
pub fn with_max_size(self, s: Size) -> Self
Sourcepub fn scene_rect(&self) -> Rect
pub fn scene_rect(&self) -> Rect
The region of scene space currently visible in the Scene’s bounds.
Sourcepub fn transform(&self) -> SceneTransform
pub fn transform(&self) -> SceneTransform
Current pan/zoom transform (scene→screen).
Sourcepub fn reset_view(&mut self)
pub fn reset_view(&mut self)
Reset the view to fit the default scene rect (or the content bounds) centered in the container. Re-enables the auto-fit-until-interaction behaviour so the view stays fitted as the container settles.
Trait Implementations§
Source§impl Widget for Scene
impl Widget for Scene
Source§fn child_transform(&self) -> Option<TransAffine>
fn child_transform(&self) -> Option<TransAffine>
Inject the pan/zoom as the framework-level child transform. Every coordinate-mapping traversal (paint, hit-test, dispatch, inspector) composes this when descending into the content, so hosted widgets are painted, clicked, focused, and inspected at the right place.
Source§fn claims_pointer_exclusively(&self, _local_pos: Point) -> bool
fn claims_pointer_exclusively(&self, _local_pos: Point) -> bool
While a background pan is in progress the Scene owns the pointer: the drag must keep landing on the Scene even as the cursor sweeps over hosted widgets, so hit-testing stops here until the gesture ends.
Source§fn enforce_integer_bounds(&self) -> bool
fn enforce_integer_bounds(&self) -> bool
Smooth pan/zoom needs sub-pixel positioning; opt out of the crisp-UI
integer-snap default (see Widget::enforce_integer_bounds).
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Source§fn set_bounds(&mut self, b: Rect)
fn set_bounds(&mut self, b: Rect)
Source§fn children_mut(&mut self) -> &mut Vec<Box<dyn Widget>>
fn children_mut(&mut self) -> &mut Vec<Box<dyn Widget>>
Source§fn widget_base(&self) -> Option<&WidgetBase>
fn widget_base(&self) -> Option<&WidgetBase>
WidgetBase. Read moreSource§fn widget_base_mut(&mut self) -> Option<&mut WidgetBase>
fn widget_base_mut(&mut self) -> Option<&mut WidgetBase>
widget_base. Read moreSource§fn h_anchor(&self) -> HAnchor
fn h_anchor(&self) -> HAnchor
HAnchor::FIT (take natural content width).Source§fn v_anchor(&self) -> VAnchor
fn v_anchor(&self) -> VAnchor
VAnchor::FIT (take natural content height).Source§fn layout(&mut self, available: Size) -> Size
fn layout(&mut self, available: Size) -> Size
Source§fn paint(&mut self, ctx: &mut dyn DrawCtx)
fn paint(&mut self, ctx: &mut dyn DrawCtx)
ctx. Read moreSource§fn on_event(&mut self, event: &Event) -> EventResult
fn on_event(&mut self, event: &Event) -> EventResult
EventResult::Consumed to stop bubbling. Read moreSource§fn properties(&self) -> Vec<(&'static str, String)>
fn properties(&self) -> Vec<(&'static str, String)>
Source§fn hit_test(&self, local_pos: Point) -> bool
fn hit_test(&self, local_pos: Point) -> bool
true if local_pos (in this widget’s local coordinates) falls
inside this widget’s interactive area. Default: axis-aligned rect test.Source§fn blocks_child_interaction(&self) -> bool
fn blocks_child_interaction(&self) -> bool
true, this widget disables all interaction — pointer and
keyboard — within its subtree, reproducing egui’s
UiBuilder::disabled(). Unlike [claims_pointer_exclusively], this is
a position-independent state predicate: pointer hit-testing stops at
this widget (so clicks are swallowed rather than passing through), and
focus collection skips the whole subtree (so Tab cannot reach a child).
Default: false.Source§fn hit_test_global_overlay(&self, _local_pos: Point) -> bool
fn hit_test_global_overlay(&self, _local_pos: Point) -> bool
local_pos hits an app-level overlay owned by this
widget. Unlike normal hit testing, ancestors may be missed because the
overlay is painted outside their bounds.Source§fn has_active_modal(&self) -> bool
fn has_active_modal(&self) -> bool
Source§fn on_unconsumed_key(
&mut self,
_key: &Key,
_modifiers: Modifiers,
) -> EventResult
fn on_unconsumed_key( &mut self, _key: &Key, _modifiers: Modifiers, ) -> EventResult
Source§fn is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
Source§fn focus_id(&self) -> Option<FocusId>
fn focus_id(&self) -> Option<FocusId>
crate::focus::request_focus). Read moreSource§fn id(&self) -> Option<&str>
fn id(&self) -> Option<&str>
Source§fn is_visible(&self) -> bool
fn is_visible(&self) -> bool
false to suppress painting this widget and all its children.
The widget’s own paint() will not be called. Default: true.Source§fn accepts_text_input(&self) -> bool
fn accepts_text_input(&self) -> bool
true when this widget accepts free-form character input (typing
arbitrary letters, numbers, punctuation). Used by the on-screen
software keyboard (crate::widgets::on_screen_keyboard) to decide
whether to slide up when this widget gains focus. Read moreSource§fn text_input_value(&self) -> Option<String>
fn text_input_value(&self) -> Option<String>
., !, ?, newline) opens the keyboard with Shift
active. Read moreSource§fn text_input_mode(&self) -> KeyboardInputMode
fn text_input_mode(&self) -> KeyboardInputMode
KeyboardInputMode::Text;
numeric fields override to
Numeric
so the digit pad slides up instead of the letter row. Read moreSource§fn try_scroll_to_lift(&mut self, _amount: f64) -> f64
fn try_scroll_to_lift(&mut self, _amount: f64) -> f64
amount
pixels. Used by the on-screen-keyboard auto-scroll so a
focused text field doesn’t end up hidden behind the keyboard
panel: the App walks UP the focus path and asks each ancestor
to absorb some of the deficit. Read moreSource§fn set_label_color(&mut self, _color: Color)
fn set_label_color(&mut self, _color: Color)
Label), update its foreground
colour. Default is a no-op. Composite widgets call this on their
children to retint labels without rebuilding them — used by Button
when toggling between active (white text on accent) and inactive
(theme text on subtle bg) appearances.Source§fn set_label_text(&mut self, _text: &str)
fn set_label_text(&mut self, _text: &str)
Label), update its
displayed text. Default is a no-op. Composite widgets that
own a Label child use this to push live values (e.g. an FPS
counter) into the child without bypassing the standard
backbuffered glyph cache — calling this on a Label only
invalidates the cache when the text actually changed.Source§fn as_reflect(&self) -> Option<&dyn Reflect>
fn as_reflect(&self) -> Option<&dyn Reflect>
Source§fn as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
fn as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
as_reflect. Used by the
inspector to write edits back into the live widget.Source§fn has_backbuffer(&self) -> bool
fn has_backbuffer(&self) -> bool
Source§fn compositing_layer(&mut self) -> Option<CompositingLayer>
fn compositing_layer(&mut self) -> Option<CompositingLayer>
Source§fn backbuffer_spec(&mut self) -> BackbufferSpec
fn backbuffer_spec(&mut self) -> BackbufferSpec
Source§fn backbuffer_state_mut(&mut self) -> Option<&mut BackbufferState>
fn backbuffer_state_mut(&mut self) -> Option<&mut BackbufferState>
BackbufferSpec other than BackbufferKind::None.Source§fn mark_dirty(&mut self)
fn mark_dirty(&mut self)
Source§fn backbuffer_cache_mut(&mut self) -> Option<&mut BackbufferCache>
fn backbuffer_cache_mut(&mut self) -> Option<&mut BackbufferCache>
Source§fn backbuffer_band(&self) -> Option<BackbufferBand>
fn backbuffer_band(&self) -> Option<BackbufferBand>
Source§fn backbuffer_mode(&self) -> BackbufferMode
fn backbuffer_mode(&self) -> BackbufferMode
backbuffer_cache_mut] returns Some. Default
BackbufferMode::Rgba — correct for any widget.
Opt into BackbufferMode::LcdCoverage only when the widget
paints opaque content covering its full bounds.Source§fn contributes_children_to_inspector(&self) -> bool
fn contributes_children_to_inspector(&self) -> bool
Source§fn show_in_inspector(&self) -> bool
fn show_in_inspector(&self) -> bool
false to hide this widget (and its subtree) from the inspector
node snapshot entirely. Intended for zero-size utility widgets such
as layout-time watchers / tickers / invisible composers — they bloat
the inspector tree without providing user-relevant information and,
at scale, can make the inspector’s per-frame tree rebuild expensive.Source§fn lcd_preference(&self) -> Option<bool>
fn lcd_preference(&self) -> Option<bool>
Source§fn paint_overlay(&mut self, _ctx: &mut dyn DrawCtx)
fn paint_overlay(&mut self, _ctx: &mut dyn DrawCtx)
Source§fn finish_paint(&mut self, _ctx: &mut dyn DrawCtx)
fn finish_paint(&mut self, _ctx: &mut dyn DrawCtx)
paint, child painting, and optional overlay painting. Read moreSource§fn paint_global_overlay(&mut self, _ctx: &mut dyn DrawCtx)
fn paint_global_overlay(&mut self, _ctx: &mut dyn DrawCtx)
Source§fn defer_paint_to_overlay(&self) -> bool
fn defer_paint_to_overlay(&self) -> bool
paint_global_overlay
instead — the same clip-escaping global pass used by menus and tooltips. Read moreSource§fn clip_children_rect(&self) -> Option<(f64, f64, f64, f64)>
fn clip_children_rect(&self) -> Option<(f64, f64, f64, f64)>
paint_subtree applies this clip before recursing into
children, then restores the previous clip state afterward. The clip does
not affect paint_overlay, which runs after the clip is removed. Read moreSource§fn inspector_child_transform(&self) -> TransAffine
fn inspector_child_transform(&self) -> TransAffine
paint() does — e.g. a widget
that pushes pan/zoom in paint() and pops it in finish_paint()
makes the framework recurse into its children with pan/zoom active,
so collect_inspector_nodes must apply the same transform when
accumulating descendant screen bounds. Without this hook the
inspector hover overlay lands at the un-transformed canvas position
when the widget sits inside a panning/zooming container. Read moreSource§fn padding(&self) -> Insets
fn padding(&self) -> Insets
Insets::ZERO. Read moreSource§fn tooltip_text(&self) -> Option<&str>
fn tooltip_text(&self) -> Option<&str>
None. Read moreSource§fn with_tooltip(self, text: impl Into<String>) -> Selfwhere
Self: Sized,
fn with_tooltip(self, text: impl Into<String>) -> Selfwhere
Self: Sized,
self for chaining. Read moreSource§fn set_tooltip_text(&mut self, text: Option<String>)
fn set_tooltip_text(&mut self, text: Option<String>)
with_tooltip,
callable on a &mut dyn Widget / Box<dyn Widget> (used by builders
that assemble a control tree from boxed widgets, e.g. toolbars). Writes
through widget_base_mut; a no-op for widgets
without a WidgetBase. Pass None to clear.Source§fn measure_min_height(&self, _available_w: f64) -> f64
fn measure_min_height(&self, _available_w: f64) -> f64
available_w for width. Read moreSource§fn take_raise_request(&mut self) -> bool
fn take_raise_request(&mut self) -> bool
crate::widgets::Stack) call this on each
child at the start of layout(). A widget that returns true is
moved to the END of its parent’s child list — painted last, i.e.
raised to the top of the z-order. take_ semantics: the call is
also expected to clear the request so the child doesn’t keep
getting raised every frame. Read moreSource§fn needs_draw(&self) -> bool
fn needs_draw(&self) -> bool
true if this widget, or any visible descendant, has an ongoing
draw need that should keep the host drawing. Read moreSource§fn next_draw_deadline(&self) -> Option<Instant>
fn next_draw_deadline(&self) -> Option<Instant>
None = no scheduled wake.
The host loop turns a Some(t) into ControlFlow::WaitUntil(t) so
e.g. a cursor blink fires without continuous polling. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for Scene
impl !Send for Scene
impl !Sync for Scene
impl !UnwindSafe for Scene
impl Freeze for Scene
impl Unpin for Scene
impl UnsafeUnpin for Scene
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more