Guide API
Skip to main content

Application

Struct Application 

Source
pub struct Application { /* private fields */ }
Expand description

A thin embed-and-delegate wrapper over Program.

Application adds the application-level window commands on top of Program: the tile and cascade commands lay the desktop’s windows out (into get_tile_rect’s rectangle), and the shell command suspends the terminal. Subsystem init and teardown are handled by the Backend + Renderer construction path. History needs no explicit setup: the store is a thread_local! Vec that auto-initializes and auto-drops (see history.rs). The type is thin: one get_tile_rect helper plus forwarding delegations to the embedded program.

Application provides Application::get_tile_rect (the rectangle tile and cascade lay windows into) and forwards all other behavior verbatim to the embedded Program.

Build with Application::new; drive with Application::run or step with Application::pump_once.

§Turbo Vision heritage

Ports TApplication (tapplica.cpp); its constructor is the factory mixin that wires up the status line, menu bar, and desktop. The TApplication : TProgram inheritance becomes embed-and-delegate composition (deviation D2): the type holds a Program and forwards to it. History needs no explicit setup — the store is a thread_local! Vec that auto-initializes and auto-drops (see history.rs).

Implementations§

Source§

impl Application

Source

pub fn new( backend: Box<dyn Backend>, clock: Box<dyn Clock>, theme: Theme, create_desktop: impl FnOnce(Rect) -> Option<Box<dyn View>>, create_status_line: impl FnOnce(Rect) -> Option<Box<dyn View>>, create_menu_bar: impl FnOnce(Rect) -> Option<Box<dyn View>>, ) -> Self

Construct the application and its three subviews.

create_desktop, create_status_line, and create_menu_bar are factory closures, each receiving the full terminal Rect; they own their own inset (shrink the rect by one row for a menu bar, one row for a status line, etc.) and return None to omit that subview entirely. Pass Desktop::new wrapped in Some(Box::new(...)) for a standard desktop; substitute custom types as needed.

Hardware/mouse/screen subsystem init is handled by the backend construction path (e.g. CrosstermBackend::new); history needs no explicit setup — the store is a thread_local! Vec that auto-initializes and auto-drops.

After construction, drive the loop with Application::run (production) or step with Application::pump_once (tests).

§Turbo Vision heritage

Ports TApplication::TApplication (tapplica.cpp). The subsystem-init sequence (TMemoryManager, TSystemError, TEventQueue, TScreen) is folded into the backend construction path; the virtual factory overrides (initDeskTop, initStatusLine, initMenuBar) become the three factory closures, with Application embedding and delegating to its Program.

Source

pub fn run(&mut self) -> Command

Run the event loop — delegates to Program::run.

Source

pub fn pump_once(&mut self)

One iteration of the event loop — delegates to Program::pump_once.

Source

pub fn exec_view(&mut self, view: Box<dyn View>) -> Command

Run view as a modal dialog — delegates to Program::exec_view.

Source

pub fn desktop(&self) -> Option<ViewId>

The desktop child’s id — delegates to Program::desktop.

Source

pub fn end_modal(&mut self, cmd: Command)

Request the modal loop end — delegates to Program::end_modal.

Source

pub fn end_state(&self) -> Option<Command>

The current modal end state — delegates to Program::end_state.

Source

pub fn enable_command(&mut self, cmd: Command)

Enable a command — delegates to Program::enable_command.

Source

pub fn disable_command(&mut self, cmd: Command)

Disable a command — delegates to Program::disable_command.

Source

pub fn command_enabled(&self, cmd: Command) -> bool

Whether a command is currently enabled — delegates to Program::command_enabled.

Source

pub fn program(&self) -> &Program

Shared borrow of the embedded Program.

Source

pub fn program_mut(&mut self) -> &mut Program

Exclusive borrow of the embedded Program.

Source

pub fn set_shell_msg_hook(&mut self, hook: Box<dyn Fn() -> String>)

Register a closure that produces the shell-suspend message printed before the terminal is yielded to the shell (Command::DOS_SHELL). See Program::set_shell_msg_hook for the full contract and an example.

Source

pub fn get_tile_rect(&mut self) -> Option<Rect>

The rectangle that the tile and cascade window commands lay windows into: the desktop child’s local-origin extent (0, 0, w, h), so it stays correct when the desktop is inset below a menu bar or above a status line. Returns None if no desktop was created.

The TILE and CASCADE command handlers call this internally. You can call it directly if you need the desktop layout rectangle for your own window-positioning logic (e.g. centering a newly opened window within the desktop area). To restrict tiling to a sub-region, size the desktop accordingly rather than adjusting this value.

Requires &mut self because the underlying Group::find_mut requires &mut.

§Turbo Vision heritage

Ports TApplication::getTileRect (tapplica.cpp); virtual in C++ so subclasses could exclude reserved rows. Here the desktop rect is the canonical answer; adjust by sizing the desktop in the factory closure.

Auto Trait Implementations§

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &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> 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.