pub struct ObjectBuilder<'a, ID: ObjectID> {
world: &'a mut World<ID>,
id: ID,
hitbox: Option<Polygon>,
zorder: usize,
draw_normal: Option<ToggleZoomedBuilder>,
draw_hover: Option<ToggleZoomedBuilder>,
tooltip: Option<Text>,
clickable: bool,
draggable: bool,
keybindings: Vec<(MultiKey, &'static str)>,
}
Expand description
This provides a builder API for adding objects to a World
.
Fields
world: &'a mut World<ID>
id: ID
hitbox: Option<Polygon>
zorder: usize
draw_normal: Option<ToggleZoomedBuilder>
draw_hover: Option<ToggleZoomedBuilder>
tooltip: Option<Text>
clickable: bool
draggable: bool
keybindings: Vec<(MultiKey, &'static str)>
Implementations
sourceimpl<'a, ID: ObjectID> ObjectBuilder<'a, ID>
impl<'a, ID: ObjectID> ObjectBuilder<'a, ID>
sourcepub fn zorder(self, zorder: usize) -> Self
pub fn zorder(self, zorder: usize) -> Self
Provides ordering for overlapping objects. Higher values are “on top” of lower values.
sourcepub fn draw<I: Into<ToggleZoomedBuilder>>(self, normal: I) -> Self
pub fn draw<I: Into<ToggleZoomedBuilder>>(self, normal: I) -> Self
Specifies how to draw this object normally (while not hovering on it)
sourcepub fn draw_color(self, color: Color) -> Self
pub fn draw_color(self, color: Color) -> Self
Draw the object by coloring its hitbox
sourcepub fn draw_color_unzoomed(self, color: Color) -> Self
pub fn draw_color_unzoomed(self, color: Color) -> Self
Draw the object by coloring its hitbox, only when unzoomed. Show nothing when zoomed.
sourcepub fn drawn_in_master_batch(self) -> Self
pub fn drawn_in_master_batch(self) -> Self
Indicate that an object doesn’t need to be drawn individually. A call to
draw_master_batch
covers it.
sourcepub fn draw_hovered<I: Into<ToggleZoomedBuilder>>(self, hovered: I) -> Self
pub fn draw_hovered<I: Into<ToggleZoomedBuilder>>(self, hovered: I) -> Self
Specifies how to draw the object while the cursor is hovering on it. Note that an object isn’t considered hoverable unless this is specified!
sourcepub fn draw_hover_rewrite(self, rewrite: RewriteColor) -> Self
pub fn draw_hover_rewrite(self, rewrite: RewriteColor) -> Self
Draw the object in a hovered state by transforming the normal drawing.
sourcepub fn hover_alpha(self, alpha: f32) -> Self
pub fn hover_alpha(self, alpha: f32) -> Self
Draw the object in a hovered state by changing the alpha value of the normal drawing.
sourcepub fn hover_outline(self, color: Color, thickness: Distance) -> Self
pub fn hover_outline(self, color: Color, thickness: Distance) -> Self
Draw the object in a hovered state by adding an outline to the normal drawing. The
specified color
and thickness
will be used when unzoomed. For the zoomed view, the
color’s opacity and the thickness will be halved.
sourcepub fn hover_color(self, color: Color) -> Self
pub fn hover_color(self, color: Color) -> Self
Draw the object in a hovered state by coloring its hitbox. Useful when
drawn_in_master_batch
is used and there’s no normal drawn polygon.
sourcepub fn invisibly_hoverable(self) -> Self
pub fn invisibly_hoverable(self) -> Self
Mark that an object is hoverable, but don’t actually draw anything while hovering on it
sourcepub fn clickable(self) -> Self
pub fn clickable(self) -> Self
Mark the object as clickable. WorldOutcome::ClickedObject
will be fired.
sourcepub fn set_clickable(self, clickable: bool) -> Self
pub fn set_clickable(self, clickable: bool) -> Self
Mark the object as clickable or not. WorldOutcome::ClickedObject
will be fired.
sourcepub fn draggable(self) -> Self
pub fn draggable(self) -> Self
Mark the object as draggable. The user can hover on this object, then click and drag it.
WorldOutcome::Dragging
events will be fired.
Note that dragging an object doesn’t transform it at all (for example, by translating its hitbox). The caller is responsible for doing that.
Auto Trait Implementations
impl<'a, ID> RefUnwindSafe for ObjectBuilder<'a, ID> where
ID: RefUnwindSafe,
impl<'a, ID> !Send for ObjectBuilder<'a, ID>
impl<'a, ID> !Sync for ObjectBuilder<'a, ID>
impl<'a, ID> Unpin for ObjectBuilder<'a, ID> where
ID: Unpin,
impl<'a, ID> !UnwindSafe for ObjectBuilder<'a, ID>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
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
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more