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>

source

pub fn hitbox(self, polygon: Polygon) -> Self

Specifies the geometry of the object. Required.

source

pub fn hitboxes(self, polygons: Vec<Polygon>) -> Self

Specifies the geometry of the object as a multipolygon.

source

pub fn zorder(self, zorder: usize) -> Self

Provides ordering for overlapping objects. Higher values are “on top” of lower values.

source

pub fn draw<I: Into<ToggleZoomedBuilder>>(self, normal: I) -> Self

Specifies how to draw this object normally (while not hovering on it)

source

pub fn draw_color(self, color: Color) -> Self

Draw the object by coloring its hitbox

source

pub fn draw_color_unzoomed(self, color: Color) -> Self

Draw the object by coloring its hitbox, only when unzoomed. Show nothing when zoomed.

source

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.

source

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!

source

pub fn draw_hover_rewrite(self, rewrite: RewriteColor) -> Self

Draw the object in a hovered state by transforming the normal drawing.

source

pub fn hover_alpha(self, alpha: f32) -> Self

Draw the object in a hovered state by changing the alpha value of the normal drawing.

source

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.

source

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.

source

pub fn invisibly_hoverable(self) -> Self

Mark that an object is hoverable, but don’t actually draw anything while hovering on it

source

pub fn maybe_tooltip(self, txt: Option<Text>) -> Self

Maybe draw a tooltip while hovering over this object.

source

pub fn tooltip(self, txt: Text) -> Self

Draw a tooltip while hovering over this object.

source

pub fn clickable(self) -> Self

Mark the object as clickable. WorldOutcome::ClickedObject will be fired.

source

pub fn set_clickable(self, clickable: bool) -> Self

Mark the object as clickable or not. WorldOutcome::ClickedObject will be fired.

source

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.

source

pub fn hotkey<I: Into<MultiKey>>(self, key: I, action: &'static str) -> Self

While the user hovers over this object, they can press a key to perform the specified action. WorldOutcome::Keypress will be fired.

source

pub fn build(self, ctx: &EventCtx<'_>)

Finalize the object, adding it to the World.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn 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.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert 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)

Convert &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)

Convert &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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool