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>
impl<L: Logic, B: Backend> Engine<L, B>
Sourcepub(super) fn windows_to_open(
&self,
reused: &[Option<ReusedWindow>],
) -> Vec<bool>
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.
Sourcepub(super) fn prepare_window(
&self,
index: usize,
reused: Option<ReusedWindow>,
) -> Result<PreparedWindow<L>, L::Error>
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.
Sourcepub(super) fn show_prepared(&self, prepared: PreparedWindow<L>)
pub(super) fn show_prepared(&self, prepared: PreparedWindow<L>)
Puts built content in its window and shows it.
Sourcepub(super) fn discard(&self, prepared: Vec<PreparedWindow<L>>)
pub(super) fn discard(&self, prepared: Vec<PreparedWindow<L>>)
Throws away content that was built but never shown, closing windows opened for it.
Sourcefn mount_window(
&self,
window: WindowId,
template: &WindowTemplate<L>,
) -> Result<MountedWindow<L>, L::Error>
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.
Sourcepub(super) fn apply_window_requests(
&self,
requests: &[WindowRequest],
) -> Result<(), L::Error>
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.
Sourcefn open_window(&self, index: usize) -> Result<(), L::Error>
fn open_window(&self, index: usize) -> Result<(), L::Error>
Opens the window at index, or brings it to the front if it is open.
Sourcefn close_window(&self, index: usize)
fn close_window(&self, index: usize)
Closes the window at index, if it is open.
Sourcepub(super) fn on_close(&self) -> WindowCloseHandler
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>
impl<L: Logic, B: Backend> Engine<L, B>
Sourcepub 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>
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.
Sourcepub fn reload(
&self,
app: AppTemplate<L>,
make_logic: impl FnOnce(&Ui<B>, Weak<Self>) -> L,
) -> Result<Rc<Self>, L::Error>
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.
pub fn logic(&self) -> &L
Sourcepub fn handle_event(&self, event: impl FnOnce(&L) -> Result<(), L::Error>)
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.
Sourcefn 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>
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.
Gives the app menu_bar’s menus, whose items run their actions as events.
Runs the numbered item’s action, with frame as its locals, as one event.
fn mount_list( &self, templates: &Templates<L>, frame: &Rc<L::Frame>, parent: Node, offset: &mut usize, ) -> Result<Vec<Mounted<L>>, L::Error>
Sourcefn mount(
&self,
template: TemplateRef<L>,
frame: &Rc<L::Frame>,
parent: Node,
offset: &mut usize,
) -> Result<Mounted<L>, L::Error>
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.
fn create_widget( &self, at: Position, widget: &Widget<L>, frame: &Rc<L::Frame>, ) -> Result<Node, L::Error>
Sourcefn mount_region(
&self,
region: &L::Region,
frame: &Rc<L::Frame>,
parent: Node,
offset: &mut usize,
) -> Result<Vec<Mounted<L>>, L::Error>
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.
Sourcefn refresh(&self) -> Result<(), L::Error>
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.
fn refresh_list( &self, items: &mut [Mounted<L>], parent: Node, changed: &StateSet, offset: &mut usize, ) -> Result<(), L::Error>
fn unmount(&self, mounted: Mounted<L>)
fn update_widget( &self, node: Node, widget: &Widget<L>, frame: &L::Frame, ) -> Result<(), L::Error>
fn badge( &self, badge: Option<&L::Value>, frame: &L::Frame, ) -> Result<String, L::Error>
fn is_selected( &self, value: &L::Value, selection: &L::Binding, frame: &L::Frame, ) -> Result<bool, L::Error>
fn on_click(&self, action: L::Action, frame: Rc<L::Frame>) -> ClickHandler
fn on_edit(&self, binding: L::Binding, frame: Rc<L::Frame>) -> TextHandler
Sourcefn on_select(
&self,
selection: L::Binding,
value: L::Value,
frame: Rc<L::Frame>,
) -> ClickHandler
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.
fn on_number(&self, binding: L::Binding, frame: Rc<L::Frame>) -> NumberHandler
Sourcefn on_drop(
&self,
dropped: L::Binding,
action: Option<L::Action>,
frame: Rc<L::Frame>,
) -> DropHandler
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.