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>
impl<'a> Startup<'a>
Sourcepub fn saved<K: SaveKey>(&self, key: K) -> K::Value
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?
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 }Sourcepub fn window_size(&self) -> UVec2
pub fn window_size(&self) -> UVec2
The window’s drawing area, in physical pixels; zero while minimized.
Sourcepub fn font(&self, name: &str) -> Result<FontData, Error>
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?
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}Sourcepub fn set_fonts(&mut self, fonts: FontDefinitions) -> Result<(), Error>
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?
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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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