Struct widgetry::mapspace::world::ObjectBuilder
source · pub struct ObjectBuilder<'a, ID: ObjectID> {
world: &'a mut World<ID>,
id: ID,
hitboxes: Vec<Polygon>,
zorder: usize,
draw_normal: Option<ToggleZoomedBuilder>,
draw_hover: Option<HoverBuilder>,
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
§hitboxes: Vec<Polygon>
§zorder: usize
§draw_normal: Option<ToggleZoomedBuilder>
§draw_hover: Option<HoverBuilder>
§tooltip: Option<Text>
§clickable: bool
§draggable: bool
§keybindings: Vec<(MultiKey, &'static str)>
Implementations§
source§impl<'a, ID: ObjectID> ObjectBuilder<'a, ID>
impl<'a, ID: ObjectID> ObjectBuilder<'a, ID>
sourcepub fn hitboxes(self, polygons: Vec<Polygon>) -> Self
pub fn hitboxes(self, polygons: Vec<Polygon>) -> Self
Specifies the geometry of the object as a multipolygon.
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 maybe_tooltip(self, txt: Option<Text>) -> Self
pub fn maybe_tooltip(self, txt: Option<Text>) -> Self
Maybe draw a tooltip while hovering over this object.
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> Freeze for ObjectBuilder<'a, ID>where
ID: Freeze,
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§
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§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>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§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.§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.