Struct widgetry::mapspace::world::World [−][src]
pub struct World<ID: ObjectID> {
objects: HashMap<ID, Object<ID>>,
quadtree: QuadTree<ID>,
draw_master_batches: Vec<ToggleZoomed>,
hovering: Option<ID>,
dragging_from: Option<(Pt2D, bool)>,
}
Expand description
A World
manages objects that exist in “map-space”, the zoomable and pannable canvas. These
objects can be drawn, hovered on, clicked, dragged, etc.
Fields
objects: HashMap<ID, Object<ID>>
quadtree: QuadTree<ID>
draw_master_batches: Vec<ToggleZoomed>
hovering: Option<ID>
dragging_from: Option<(Pt2D, bool)>
Implementations
Creates an empty World
, whose objects can exist anywhere from (0, 0) to the max f64.
Creates an empty World
, whose objects can exist in the provided rectangular boundary.
Start adding an object to the World
. The caller should specify the object with methods on
ObjectBuilder
, then call build
.
Delete an object. Not idempotent – this will panic if the object doesn’t exist. Will panic if the object is deleted in the middle of being dragged.
Delete an object, with the promise to recreate it with the same ID before the next call to
event
. This may be called while the object is being hovered on or dragged.
After adding all objects to a World
, call this to initially detect if the cursor is
hovering on an object.
If a drag event causes the world to be totally rebuilt, call this with the previous world to preserve the ongoing drag.
This should be called after initialize_hover
.
Important: the rebuilt world must include the same object ID that’s currently being dragged from the previous world.
pub fn draw_master_batch<I: Into<ToggleZoomedBuilder>>(
&mut self,
ctx: &EventCtx<'_>,
draw: I
)
pub fn draw_master_batch<I: Into<ToggleZoomedBuilder>>(
&mut self,
ctx: &EventCtx<'_>,
draw: I
)
Draw something underneath all objects. This is useful for performance, when a large number of objects never change appearance.
Let objects in the world respond to something happening.
Returns the object currently hovered on.
Begin adding an unnamed object to the World
.
Note: You must call build
on this object before calling add_unnamed
again. Otherwise,
the object IDs will collide.
TODO This will break when objects are deleted!
Auto Trait Implementations
impl<ID> RefUnwindSafe for World<ID> where
ID: RefUnwindSafe,
impl<ID> UnwindSafe for World<ID> where
ID: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
type Output = T
type Output = T
Should always be Self