Skip to main content

Engine

Struct Engine 

Source
pub struct Engine<L: Logic, B: Backend> {
    logic: L,
    ui: Ui<B>,
    templates: Vec<WindowTemplate<L>>,
    windows: RefCell<Vec<Option<MountedWindow<L>>>>,
    on_error: ErrorHandler<L::Error>,
    this: Weak<Self>,
}
Expand description

A running app: its logic, its windows, and what each widget shows.

Fields§

§logic: L§ui: Ui<B>§templates: Vec<WindowTemplate<L>>

The app’s windows, which code refers to by their position.

§windows: RefCell<Vec<Option<MountedWindow<L>>>>

What each window shows, by its template’s position; None while it is closed.

§on_error: ErrorHandler<L::Error>§this: Weak<Self>

Implementations§

Source§

impl<L: Logic, B: Backend> Engine<L, B>

Source

pub(super) fn windows_to_open( &self, reused: &[Option<ReusedWindow>], ) -> Vec<bool>

Which windows to open, by template: those the replaced app had open, reused, and new ones that start open. When none would be open, those that start open are, so the app keeps running.

Source

pub(super) fn prepare_window( &self, index: usize, reused: Option<ReusedWindow>, ) -> Result<PreparedWindow<L>, L::Error>

Builds the content of the window at index, in the window reused if given or a new one, without showing it yet.

Source

pub(super) fn show_prepared(&self, prepared: PreparedWindow<L>)

Puts built content in its window and shows it.

Source

pub(super) fn discard(&self, prepared: Vec<PreparedWindow<L>>)

Throws away content that was built but never shown, closing windows opened for it.

Source

fn mount_window( &self, window: WindowId, template: &WindowTemplate<L>, ) -> Result<MountedWindow<L>, L::Error>

Builds a window’s content without placing it in the window yet.

Source

pub(super) fn apply_window_requests( &self, requests: &[WindowRequest], ) -> Result<(), L::Error>

Opens and closes windows as requests ask, the last request for a window deciding what happens to it. Windows open before others close, so the app, which quits with its last window, keeps running when code swaps one window for another.

Source

fn open_window(&self, index: usize) -> Result<(), L::Error>

Opens the window at index, or brings it to the front if it is open.

Source

fn close_window(&self, index: usize)

Closes the window at index, if it is open.

Source

pub(super) fn on_close(&self) -> WindowCloseHandler

Closes a window the user asked to close, as code closing it would.

Source§

impl<L: Logic, B: Backend> Engine<L, B>

Source

pub fn start( ui: Ui<B>, app: AppTemplate<L>, on_error: ErrorHandler<L::Error>, make_logic: impl FnOnce(&Ui<B>, Weak<Self>) -> L, ) -> Result<Rc<Self>, L::Error>

Shows the windows of app that start open, with make_logic giving their dynamic parts values. It receives the UI and the engine-to-be, for logic that wakes the app later.

§Errors

When building the first UI fails.

Source

pub fn reload( &self, app: AppTemplate<L>, make_logic: impl FnOnce(&Ui<B>, Weak<Self>) -> L, ) -> Result<Rc<Self>, L::Error>

Shows app’s windows and menus in place of this app’s. A window open now stays open with its new content, one closed now stays closed, and windows this app didn’t have open if they start open; windows it has beyond app’s close.

§Errors

When building the new UI fails. Nothing has changed then, and this app keeps running.

Source

pub fn logic(&self) -> &L

Source

pub fn handle_event(&self, event: impl FnOnce(&L) -> Result<(), L::Error>)

Runs one event, then updates the UI; errors go to the app’s error handler.

Source

pub fn run(&self)

Runs the event loop until the app quits.

Source

fn open( ui: Ui<B>, _: AppTemplate<L>, on_error: ErrorHandler<L::Error>, make_logic: impl FnOnce(&Ui<B>, Weak<Self>) -> L, reused: &[Option<ReusedWindow>], ) -> Result<Rc<Self>, L::Error>

Builds the content of every window to open, reusing reused by position, and shows it all only once everything is built, so a failure leaves the windows as they were. The menus change with them.

Source

fn show_menus(&self, menu_bar: MenuBar<L>)

Gives the app menu_bar’s menus, whose items run their actions as events.

Source

fn on_menu(&self, actions: Vec<L::Action>, frame: Rc<L::Frame>) -> MenuHandler

Runs the numbered item’s action, with frame as its locals, as one event.

Source

fn mount_list( &self, templates: &Templates<L>, frame: &Rc<L::Frame>, parent: Node, offset: &mut usize, ) -> Result<Vec<Mounted<L>>, L::Error>

Source

fn mount( &self, template: TemplateRef<L>, frame: &Rc<L::Frame>, parent: Node, offset: &mut usize, ) -> Result<Mounted<L>, L::Error>

Creates the UI for template at position offset in parent, advancing offset past what it placed there.

Source

fn create_widget( &self, at: Position, widget: &Widget<L>, frame: &Rc<L::Frame>, ) -> Result<Node, L::Error>

Source

fn mount_region( &self, region: &L::Region, frame: &Rc<L::Frame>, parent: Node, offset: &mut usize, ) -> Result<Vec<Mounted<L>>, L::Error>

Creates what a region currently shows.

Source

fn refresh(&self) -> Result<(), L::Error>

Brings every window up to date with the state changed by the last event, then opens and closes the windows it asked for.

Source

fn refresh_list( &self, items: &mut [Mounted<L>], parent: Node, changed: &StateSet, offset: &mut usize, ) -> Result<(), L::Error>

Source

fn unmount(&self, mounted: Mounted<L>)

Source

fn update_widget( &self, node: Node, widget: &Widget<L>, frame: &L::Frame, ) -> Result<(), L::Error>

Source

fn badge( &self, badge: Option<&L::Value>, frame: &L::Frame, ) -> Result<String, L::Error>

Source

fn is_selected( &self, value: &L::Value, selection: &L::Binding, frame: &L::Frame, ) -> Result<bool, L::Error>

Source

fn on_click(&self, action: L::Action, frame: Rc<L::Frame>) -> ClickHandler

Source

fn on_edit(&self, binding: L::Binding, frame: Rc<L::Frame>) -> TextHandler

Source

fn on_select( &self, selection: L::Binding, value: L::Value, frame: Rc<L::Frame>, ) -> ClickHandler

Writes the item’s value as it is when picked, which may differ from when it was shown.

Source

fn on_number(&self, binding: L::Binding, frame: Rc<L::Frame>) -> NumberHandler

Source

fn on_drop( &self, dropped: L::Binding, action: Option<L::Action>, frame: Rc<L::Frame>, ) -> DropHandler

Writes what was dropped to dropped, then runs action, as one event.

Source

fn on_toggle(&self, binding: L::Binding, frame: Rc<L::Frame>) -> ToggleHandler

Trait Implementations§

Source§

impl<L: Logic, B: Backend> Debug for Engine<L, B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<L, B> !Freeze for Engine<L, B>

§

impl<L, B> !RefUnwindSafe for Engine<L, B>

§

impl<L, B> !Send for Engine<L, B>

§

impl<L, B> !Sync for Engine<L, B>

§

impl<L, B> !UnwindSafe for Engine<L, B>

§

impl<L, B> Unpin for Engine<L, B>
where L: Unpin,

§

impl<L, B> UnsafeUnpin for Engine<L, B>
where L: UnsafeUnpin,

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

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.