Struct finestra::App

source ·
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:

  1. Instantiate an App and call the run() method.
  2. The platform will make preparations for your app, and after loading whats necessary, it will call AppDelegate::did_launch()
  3. 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 using WindowConfiguration::with_title().
  4. After configuring the window, the content of the window must be determined. This is done by calling AppDelegate::make_content_view(). Use Labels, Stacks and other views to build your user interface.
  5. 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 the Window.
  6. After that, you’re done! Respond to events and such by using the State<T> type, or specific-events like Button::with_on_click().

Implementations§

source§

impl<Delegate, State: 'static> App<Delegate, State>
where Delegate: AppDelegate<State> + 'static,

source

pub fn new(delegate: Delegate) -> App<Delegate, ()>

This is the main entrypoint to the framework.

let app = App::new(());
app.run();
source

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();
source

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,

source

pub fn delegate(&self) -> &Delegate

Get the delegate passed by Self::new() or Self::with_state().

source

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.

Auto Trait Implementations§

§

impl<Delegate, State> RefUnwindSafe for App<Delegate, State>
where Delegate: RefUnwindSafe, State: RefUnwindSafe,

§

impl<Delegate, State> Send for App<Delegate, State>
where Delegate: Send, State: Send,

§

impl<Delegate, State> Sync for App<Delegate, State>
where Delegate: Sync, State: Sync,

§

impl<Delegate, State> Unpin for App<Delegate, State>
where Delegate: Unpin, State: Unpin,

§

impl<Delegate, State> UnwindSafe for App<Delegate, State>
where Delegate: UnwindSafe, State: UnwindSafe,

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.