App

Struct App 

Source
pub struct App<AppData, O: for<'a> FnPersist2<&'a AppData, ScopeID<'static>, HashMap<Arc<SourceID>, Option<Window>>>, T> {
    pub instance: Instance,
    pub driver: Weak<Driver>,
    pub state: StateManager,
    /* private fields */
}
Expand description

Represents a feather application with a given AppData and persistent outline function O. The outline function must always be a persistent function that takes two parameters, a copy of the AppData, and a ScopeID. It must always return [OutlineReturn].

An App creates all the top level structures needed for Feather to function. It stores all wgpu, winit, and any other global state needed. See App::new for examples.

Fields§

§instance: Instance§driver: Weak<Driver>§state: StateManager

Implementations§

Source§

impl<AppData: 'static, O: for<'a> FnPersist2<&'a AppData, ScopeID<'static>, HashMap<Arc<SourceID>, Option<Window>>>, T> App<AppData, O, T>

Source

pub fn new( appstate: AppData, inputs: Vec<AppEvent<AppData>>, outline: O, user_event: Option<Box<dyn FnMut(&mut Self, &ActiveEventLoop, T)>>, driver_init: Option<Box<dyn FnOnce(Weak<Driver>)>>, ) -> Result<(Self, EventLoop<T>, Sender<EventPair<AppData>>, AtomicU64)>

Creates a new feather application. app_state represents the initial state of the application, and will override any value returned by <O as FnPersist2>::init(). inputs must be an array of AppEvent, which can be acquired by boxing and wrapping lambdas using WrapEventEx. The outline must by a persistent function that takes two arguments (and implements FnPersist2): a copy of the AppData, and a ScopeID. It must always return [OutlineReturn].

driver_init is an optional hook used to enable hotloading of resources. user_event is also an optional handler for any user events you generate via an event_loop proxy, which can be created with EventLoop::create_proxy. This is often used to inject appdata changes outside of the input handler.

This function returns 4 values - the App object itself, the EventLoop that you must call EventLoop::run_app on to actually start the application, a channel for sending dynamic AppEvent handlers, and an atomic integer representing the current dynamic slot for any additional events. If your handlers are not going to change after the app has been created, you can ignore the last 2 returns.

§Examples
use feather_ui::component::window::Window;
use feather_ui::persist::{ FnPersist2, FnPersistStore };
use feather_ui::{ SourceID, ScopeID, App };
use std::sync::Arc;

struct MyState {
  count: i32
}

struct MyApp {}

impl FnPersistStore for MyApp { type Store = (); }

impl FnPersist2<&MyState, ScopeID<'_>, im::HashMap<Arc<SourceID>, Option<Window>>> for MyApp {
    fn init(&self) -> Self::Store { () }

    fn call(&mut self,  _: Self::Store,  _: &MyState, _: ScopeID<'_>) -> (Self::Store, im::HashMap<Arc<SourceID>, Option<Window>>) {
        ((), im::HashMap::new())
    }
}

let (mut app, event_loop, _, _) = App::<MyState, MyApp, ()>::new(MyState { count: 0 }, Vec::new(), MyApp {}, None, None).unwrap();

// You would then run the app like so (commented out because docs can't test UIs)
// event_loop.run_app(&mut app).unwrap();
Source

pub fn new_any_thread( appstate: AppData, inputs: Vec<AppEvent<AppData>>, outline: O, any_thread: bool, user_event: Option<Box<dyn FnMut(&mut Self, &ActiveEventLoop, T)>>, driver_init: Option<Box<dyn FnOnce(Weak<Driver>)>>, ) -> Result<(Self, EventLoop<T>, Sender<EventPair<AppData>>, AtomicU64)>

This is the same as App::new, but it allows overriding the main thread detection that winit uses. This is necessary for running tests, which don’t run on the main thread.

Source

pub fn with_appstate<R>( &mut self, f: impl FnOnce(AccessCell<'_, '_, AppData>) -> R, ) -> R

This allows modifying the appstate outside of feather’s handling routines. It will be correctly marked as changed if it is modified, and a new frame will be queued.

Trait Implementations§

Source§

impl<AppData: 'static, T: 'static, O: for<'a> FnPersist2<&'a AppData, ScopeID<'static>, HashMap<Arc<SourceID>, Option<Window>>>> ApplicationHandler<T> for App<AppData, O, T>

Source§

fn resumed(&mut self, event_loop: &ActiveEventLoop)

Emitted when the application has been resumed. Read more
Source§

fn window_event( &mut self, event_loop: &ActiveEventLoop, window_id: WindowId, event: WindowEvent, )

Emitted when the OS sends an event to a winit window.
Source§

fn device_event( &mut self, event_loop: &ActiveEventLoop, device_id: DeviceId, event: DeviceEvent, )

Emitted when the OS sends an event to a device.
Source§

fn user_event(&mut self, event_loop: &ActiveEventLoop, evt: T)

Emitted when an event is sent from EventLoopProxy::send_event.
Source§

fn suspended(&mut self, event_loop: &ActiveEventLoop)

Emitted when the application has been suspended. Read more
Source§

fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)

Emitted when new events arrive from the OS to be processed. Read more
Source§

fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)

Emitted when the event loop is about to block and wait for new events. Read more
Source§

fn exiting(&mut self, event_loop: &ActiveEventLoop)

Emitted when the event loop is being shut down. Read more
Source§

fn memory_warning(&mut self, event_loop: &ActiveEventLoop)

Emitted when the application has received a memory warning. Read more

Auto Trait Implementations§

§

impl<AppData, O, T> Freeze for App<AppData, O, T>
where O: Freeze, <O as FnPersistStore>::Store: Freeze,

§

impl<AppData, O, T> !RefUnwindSafe for App<AppData, O, T>

§

impl<AppData, O, T> !Send for App<AppData, O, T>

§

impl<AppData, O, T> !Sync for App<AppData, O, T>

§

impl<AppData, O, T> Unpin for App<AppData, O, T>
where O: Unpin, <O as FnPersistStore>::Store: Unpin,

§

impl<AppData, O, T> !UnwindSafe for App<AppData, O, T>

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

Source§

fn downcast(&self) -> &T

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

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

impl<T> MaybeSend for T