Skip to main content

Startup

Struct Startup 

Source
pub struct Startup<'a> { /* private fields */ }
Expand description

The part of InitContext that is typed by no vocabulary of the game’s own, which InitContext::startup returns.

Implementations§

Source§

impl<'a> Startup<'a>

Source

pub fn saved<K: SaveKey>(&self, key: K) -> K::Value

The value the last run to save key kept, or its fallback where none did, or where what was kept no longer reads as the key’s own value, with a debug log.

Examples found in repository?
examples/sprite-adventure.rs (line 1009)
1007    fn init(ctx: &mut InitContext<'_, Keep>) -> Result<Self, Error> {
1008        let startup = ctx.startup();
1009        let gem_taken = startup.saved(Flag::GemTaken);
1010        let area = if startup.saved(Flag::InCave) {
1011            Area::Cave
1012        } else {
1013            Area::Overworld
1014        };
1015        let position = Vec3::new(
1016            startup.saved(Position::X) as f32,
1017            0.0,
1018            startup.saved(Position::Z) as f32,
1019        );
1020
1021        Ok(Self {
1022            area,
1023            position,
1024            previous: position,
1025            facing: Facing::Toward,
1026            walk_ticks: 0,
1027            simulated: Duration::ZERO,
1028            door_opening: gem_taken,
1029            swing_ticks: if gem_taken { DOOR_SWING_TICKS } else { 0 },
1030            gem_taken,
1031            ghost: 0.0,
1032            reset_requested: false,
1033        })
1034    }
Source

pub fn window_size(&self) -> UVec2

The window’s drawing area, in physical pixels; zero while minimized.

Source

pub fn config(&self) -> &Config

The configuration the engine started with.

Source

pub fn font(&self, name: &str) -> Result<FontData, Error>

The font a source loaded under name, to name in an egui::FontDefinitions.

Required if you want the UI to draw in a game’s own font: a source is a .ttf or an .otf Config::with_assets loads, named by its stem. A name no source loaded a font under, or one two sources share, is an error. The ui feature’s own.

Examples found in repository?
examples/ui-fonts.rs (line 536)
526fn install_family(
527    fonts: &mut egui::FontDefinitions,
528    startup: &mut Startup,
529    family: egui::FontFamily,
530    names: &[&str],
531) -> Result<(), Error> {
532    for &name in names {
533        if !fonts.font_data.contains_key(name) {
534            fonts
535                .font_data
536                .insert(name.to_owned(), startup.font(name)?.into());
537        }
538    }
539    let list = fonts.families.entry(family).or_default();
540    for &name in names.iter().rev() {
541        list.insert(0, name.to_owned());
542    }
543    Ok(())
544}
Source

pub fn set_fonts(&mut self, fonts: FontDefinitions) -> Result<(), Error>

Draws every frame’s UI in fonts, from the first frame on.

Required if you want the UI to draw in a game’s own font. Fails, naming the font, where an entry of font_data does not decode at its own index, and where a family lists a name font_data does not hold. egui’s own fonts stay wherever fonts keeps them, and the last call is what draws. The ui feature’s own.

Examples found in repository?
examples/ui-fonts.rs (line 623)
602    fn init(ctx: &mut InitContext<'_, Self>) -> Result<Self, Error> {
603        let startup = ctx.startup();
604        let mut fonts = egui::FontDefinitions::default();
605        for (family, names) in [
606            (egui::FontFamily::Proportional, &[PROPORTIONAL_FONT][..]),
607            (egui::FontFamily::Monospace, &[MONOSPACE_FONT][..]),
608            (
609                egui::FontFamily::Name(DISPLAY_FAMILY.into()),
610                &[DISPLAY_FONT][..],
611            ),
612            (
613                egui::FontFamily::Name(PIXEL_ONLY_FAMILY.into()),
614                &[PROPORTIONAL_FONT][..],
615            ),
616            (
617                egui::FontFamily::Name(PROMPT_FAMILY.into()),
618                &[PROMPT_FONT, PROPORTIONAL_FONT][..],
619            ),
620        ] {
621            install_family(&mut fonts, startup, family, names)?;
622        }
623        startup.set_fonts(fonts)?;
624
625        Ok(Self {
626            elapsed: Duration::ZERO,
627            orbit: Orbit::default(),
628            hailed: None,
629            dialogue: None,
630            sheet_open: false,
631        })
632    }

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Startup<'a>

§

impl<'a> !UnwindSafe for Startup<'a>

§

impl<'a> Freeze for Startup<'a>

§

impl<'a> Send for Startup<'a>

§

impl<'a> Sync for Startup<'a>

§

impl<'a> Unpin for Startup<'a>

§

impl<'a> UnsafeUnpin for Startup<'a>

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
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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.
Source§

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.
Source§

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.
Source§

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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