pub struct TUI { /* private fields */ }Expand description
Top-level TUI manager.
Owns the terminal, a list of mounted components, overlays, and a
Renderer that performs differential drawing. Only one component
receives focus at a time; it is the sole recipient of input events.
§Example
use photon_ui::{
TUI,
TestTerminal,
components::Text,
};
let mut tui = TUI::new(Box::new(TestTerminal::new(80, 24)));
tui.mount(Box::new(Text::new("Hello", 0, 0)));
tui.render_frame().unwrap();Implementations§
Source§impl TUI
impl TUI
Sourcepub fn mount(&mut self, component: Box<dyn Component>)
pub fn mount(&mut self, component: Box<dyn Component>)
Add a component to the TUI.
The component is appended to the children list. If no component currently has focus, the new component receives focus automatically.
Sourcepub fn set_focus(&mut self, index: usize)
pub fn set_focus(&mut self, index: usize)
Move focus to the component at index.
The previously focused component, if any, is unfocused first.
Sourcepub fn clear_children(&mut self)
pub fn clear_children(&mut self)
Remove all children and reset focus.
Sourcepub fn add_overlay(&mut self, overlay: Overlay)
pub fn add_overlay(&mut self, overlay: Overlay)
Add an overlay on top of the main UI.
Sourcepub fn clear_overlays(&mut self)
pub fn clear_overlays(&mut self)
Remove all overlays.
Sourcepub fn show_modal(&mut self, modal: Box<dyn Component>)
pub fn show_modal(&mut self, modal: Box<dyn Component>)
Show a modal dialog on top of the main UI.
The modal captures all input until it is dismissed. Focus is moved to the modal content automatically. When dismissed, focus returns to the previously focused component.
Sourcepub fn dismiss_modal(&mut self)
pub fn dismiss_modal(&mut self)
Dismiss the currently open modal, restoring previous focus.
Sourcepub fn modal_active(&self) -> bool
pub fn modal_active(&self) -> bool
Returns true if a modal is currently open.
Sourcepub fn set_layout(&mut self, layout: Layout)
pub fn set_layout(&mut self, layout: Layout)
Set a layout for splitting the terminal area among children.
Sourcepub fn clear_layout(&mut self)
pub fn clear_layout(&mut self)
Clear the layout, reverting to vertical stacking.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the TUI for a fresh page / screen.
Clears all children, overlays, and layout, and schedules a full screen redraw so no stale content or ANSI attributes bleed through.
Sourcepub fn stop(&mut self) -> Result<()>
pub fn stop(&mut self) -> Result<()>
Restore the terminal (leave alternate screen, disable raw mode, show cursor).
Sourcepub fn render_frame(&mut self) -> Result<()>
pub fn render_frame(&mut self) -> Result<()>
Render one frame to the terminal.
- Queries terminal size.
- Decides
RenderStrategy(first render, full redraw on resize, or diff). - Renders all children and overlays into a composite screen buffer.
- Deletes stale terminal images.
- Writes the result through the
Renderer. - Positions the hardware cursor.
Sourcepub fn handle_input(&mut self, event: &Event)
pub fn handle_input(&mut self, event: &Event)
Dispatch an event to the focused component, falling back to other
children if the focused one returns crate::InputResult::Ignored.
Also handles Tab to cycle focus between focusable children.