pub struct App<Delegate, State = ()> { /* private fields */ }
Expand description
This is the main entrypoint to the framework. You have to implement the
AppDelegate
to get notified of specific app lifecycle events.
§Example
let app = App::new(());
app.run();
§App Lifecycle
The app lifecycle is initiated by the App::run()
function, and after
that, the platform takes over. Finestra ensures the order of the delegate
invocations are consistent:
- Instantiate an
App
and call therun()
method. - The platform will make preparations for your app, and after loading whats
necessary, it will call
AppDelegate::did_launch()
- Finestra ensures the creation of a main window, and will call
AppDelegate::configure_main_window()
. You can override the default implementation to e.g. set a title by usingWindowConfiguration::with_title()
. - After configuring the window, the content of the window must be
determined. This is done by calling
AppDelegate::make_content_view()
. UseLabels
,Stacks
and other views to build your user interface. - Finestra will translate those views into the platform-dependent
primitives. Before the window is shown, you get a chance to do some
last-minute preparations by overriding
AppDelegate::will_show_window()
. You also get a reference to theWindow
. - After that, you’re done! Respond to events and such by using
the
State<T>
type, or specific-events likeButton::with_on_click()
.
Implementations§
source§impl<Delegate, State: 'static> App<Delegate, State>where
Delegate: AppDelegate<State> + 'static,
impl<Delegate, State: 'static> App<Delegate, State>where
Delegate: AppDelegate<State> + 'static,
sourcepub fn new(delegate: Delegate) -> App<Delegate, ()>
pub fn new(delegate: Delegate) -> App<Delegate, ()>
This is the main entrypoint to the framework.
let app = App::new(());
app.run();
sourcepub fn with_state<NewState>(
delegate: Delegate,
state: NewState
) -> App<Delegate, NewState>
pub fn with_state<NewState>( delegate: Delegate, state: NewState ) -> App<Delegate, NewState>
With this function, you can specify a State
parameter that gets passed
to invocation by the platform to your delegate.
#[derive(Default)]
struct AppState {
label: State<String>,
}
struct MyApp;
impl AppDelegate<AppState> for MyApp {}
let app = App::with_state(MyApp, AppState::default());
app.run();
sourcepub fn with_backend(self, backend: UIBackend) -> Self
pub fn with_backend(self, backend: UIBackend) -> Self
Override the UIBackend
for this application. Note that the default
is already the most appropriate for the platform, but you can still
override that behavior if you’d like.
source§impl<Delegate, State> App<Delegate, State>where
Delegate: AppDelegate<State> + 'static,
State: 'static,
impl<Delegate, State> App<Delegate, State>where
Delegate: AppDelegate<State> + 'static,
State: 'static,
sourcepub fn delegate(&self) -> &Delegate
pub fn delegate(&self) -> &Delegate
Get the delegate passed by Self::new()
or Self::with_state()
.
sourcepub fn run(self) -> !
pub fn run(self) -> !
Start the application. At this point, you can no longer make changes to
the application configuration. The next thing that gets called is the
AppDelegate::did_launch()
to signify the application was made aware
of to the platform.