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>
impl<AppData: 'static, O: for<'a> FnPersist2<&'a AppData, ScopeID<'static>, HashMap<Arc<SourceID>, Option<Window>>>, T> App<AppData, O, T>
Sourcepub 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)>
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();
Sourcepub 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)>
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.
Sourcepub fn with_appstate<R>(
&mut self,
f: impl FnOnce(AccessCell<'_, '_, AppData>) -> R,
) -> R
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>
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)
fn resumed(&mut self, event_loop: &ActiveEventLoop)
Source§fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
window_id: WindowId,
event: WindowEvent,
)
fn window_event( &mut self, event_loop: &ActiveEventLoop, window_id: WindowId, event: WindowEvent, )
Source§fn device_event(
&mut self,
event_loop: &ActiveEventLoop,
device_id: DeviceId,
event: DeviceEvent,
)
fn device_event( &mut self, event_loop: &ActiveEventLoop, device_id: DeviceId, event: DeviceEvent, )
Source§fn user_event(&mut self, event_loop: &ActiveEventLoop, evt: T)
fn user_event(&mut self, event_loop: &ActiveEventLoop, evt: T)
EventLoopProxy::send_event
.Source§fn suspended(&mut self, event_loop: &ActiveEventLoop)
fn suspended(&mut self, event_loop: &ActiveEventLoop)
Source§fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)
fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)
Source§fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)
Source§fn exiting(&mut self, event_loop: &ActiveEventLoop)
fn exiting(&mut self, event_loop: &ActiveEventLoop)
Source§fn memory_warning(&mut self, event_loop: &ActiveEventLoop)
fn memory_warning(&mut self, event_loop: &ActiveEventLoop)
Auto Trait Implementations§
impl<AppData, O, T> Freeze for App<AppData, O, T>
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>
impl<AppData, O, T> !UnwindSafe for App<AppData, O, T>
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
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> 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