pub struct Scene {
pub viewport_width: f32,
pub viewport_height: f32,
pub zoom: f32,
pub pan_x: f32,
pub pan_y: f32,
/* private fields */
}Expand description
A scene containing all canvas elements.
Fields§
§viewport_width: f32Viewport width in pixels.
viewport_height: f32Viewport height in pixels.
zoom: f32Current zoom level (1.0 = 100%).
pan_x: f32Pan offset X.
pan_y: f32Pan offset Y.
Implementations§
Source§impl Scene
impl Scene
Sourcepub fn new(width: f32, height: f32) -> Self
pub fn new(width: f32, height: f32) -> Self
Create a new empty scene with the given viewport size.
Sourcepub fn add_element(&mut self, element: Element) -> ElementId
pub fn add_element(&mut self, element: Element) -> ElementId
Add an element to the scene.
Sourcepub fn remove_element(&mut self, id: &ElementId) -> CanvasResult<Element>
pub fn remove_element(&mut self, id: &ElementId) -> CanvasResult<Element>
Sourcepub fn get_element(&self, id: ElementId) -> Option<&Element>
pub fn get_element(&self, id: ElementId) -> Option<&Element>
Get an element by ID.
Sourcepub fn get_element_mut(&mut self, id: ElementId) -> Option<&mut Element>
pub fn get_element_mut(&mut self, id: ElementId) -> Option<&mut Element>
Get a mutable reference to an element by ID.
Sourcepub fn elements_mut(&mut self) -> impl Iterator<Item = &mut Element>
pub fn elements_mut(&mut self) -> impl Iterator<Item = &mut Element>
Get mutable references to all elements in the scene.
Sourcepub fn root_elements(&self) -> impl Iterator<Item = &Element>
pub fn root_elements(&self) -> impl Iterator<Item = &Element>
Get root-level elements (not children of groups).
Sourcepub fn set_viewport(&mut self, width: f32, height: f32)
pub fn set_viewport(&mut self, width: f32, height: f32)
Set the viewport dimensions.
Sourcepub fn element_at(&self, x: f32, y: f32) -> Option<ElementId>
pub fn element_at(&self, x: f32, y: f32) -> Option<ElementId>
Find the element at the given canvas coordinates. Returns the ID of the topmost (highest z-index) interactive element.
Sourcepub fn select(&mut self, id: ElementId) -> CanvasResult<()>
pub fn select(&mut self, id: ElementId) -> CanvasResult<()>
Sourcepub fn deselect_all(&mut self)
pub fn deselect_all(&mut self)
Deselect all elements.
Sourcepub fn selected_elements(&self) -> impl Iterator<Item = &Element>
pub fn selected_elements(&self) -> impl Iterator<Item = &Element>
Get currently selected elements.
Sourcepub fn element_count(&self) -> usize
pub fn element_count(&self) -> usize
Get the number of elements in the scene.
Sourcepub fn to_json(&self) -> CanvasResult<String>
pub fn to_json(&self) -> CanvasResult<String>
Sourcepub fn from_json(json: &str) -> CanvasResult<Self>
pub fn from_json(json: &str) -> CanvasResult<Self>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Scene
impl<'de> Deserialize<'de> for Scene
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&Scene> for ViewportDocument
impl From<&Scene> for ViewportDocument
Auto Trait Implementations§
impl Freeze for Scene
impl RefUnwindSafe for Scene
impl Send for Scene
impl Sync for Scene
impl Unpin for Scene
impl UnwindSafe 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
Mutably borrows from an owned value. Read more