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
impl Application
Sourcepub 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
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.
Sourcepub fn run(&mut self) -> Command
pub fn run(&mut self) -> Command
Run the event loop — delegates to Program::run.
Sourcepub fn pump_once(&mut self)
pub fn pump_once(&mut self)
One iteration of the event loop — delegates to Program::pump_once.
Sourcepub fn exec_view(&mut self, view: Box<dyn View>) -> Command
pub fn exec_view(&mut self, view: Box<dyn View>) -> Command
Run view as a modal dialog — delegates to Program::exec_view.
Sourcepub fn desktop(&self) -> Option<ViewId>
pub fn desktop(&self) -> Option<ViewId>
The desktop child’s id — delegates to Program::desktop.
Sourcepub fn end_modal(&mut self, cmd: Command)
pub fn end_modal(&mut self, cmd: Command)
Request the modal loop end — delegates to Program::end_modal.
Sourcepub fn end_state(&self) -> Option<Command>
pub fn end_state(&self) -> Option<Command>
The current modal end state — delegates to Program::end_state.
Sourcepub fn enable_command(&mut self, cmd: Command)
pub fn enable_command(&mut self, cmd: Command)
Enable a command — delegates to Program::enable_command.
Sourcepub fn disable_command(&mut self, cmd: Command)
pub fn disable_command(&mut self, cmd: Command)
Disable a command — delegates to Program::disable_command.
Sourcepub fn command_enabled(&self, cmd: Command) -> bool
pub fn command_enabled(&self, cmd: Command) -> bool
Whether a command is currently enabled — delegates to
Program::command_enabled.
Sourcepub fn program_mut(&mut self) -> &mut Program
pub fn program_mut(&mut self) -> &mut Program
Exclusive borrow of the embedded Program.
Sourcepub fn set_shell_msg_hook(&mut self, hook: Box<dyn Fn() -> String>)
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.
Sourcepub fn get_tile_rect(&mut self) -> Option<Rect>
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§
impl !RefUnwindSafe for Application
impl !Send for Application
impl !Sync for Application
impl !UnwindSafe for Application
impl Freeze for Application
impl Unpin for Application
impl UnsafeUnpin for Application
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.