osui::Screen
The Screen struct is the central orchestrator of an OSUI application. It manages the UI tree (widgets), registers extensions, and runs the main rendering and event loop. It's the primary entry point for setting up and running your terminal user interface.
Struct Definition
pub struct Screen {
pub widgets: Mutex<Vec<Arc<Widget>>>,
extensions: Mutex<Vec<Arc<Mutex<Box<dyn Extension + Send + Sync>>>>>,
running: Mutex<bool>,
}
widgets: AMutexprotecting aVecofArc<Widget>. This holds the top-level widgets thatScreenis responsible for rendering.extensions: AMutexprotecting aVecof registeredExtensionimplementations. Extensions provide global behaviors and hooks into the rendering and event pipeline.running: AMutex<bool>flag controlling the main event loop's execution.
Associated Items
Methods
Screen::new() -> Arc<Self>
Creates a new Screen instance wrapped in an Arc.
It's recommended to always create the Screen this way, as its Arc can then be easily cloned and passed to extensions or other parts of your application without moving ownership.
Example:
use osui::prelude::*;
let screen = Screen::new();
Screen::draw<E: Element + 'static + Send + Sync>(self: &Arc<Self>, element: E) -> Arc<Widget>
Draws a static element to the screen and returns its Arc<Widget> handle.
This is a convenience method that wraps the provided Element into a StaticWidget.
Arguments:
element: An instance of a type that implements theElementtrait.
Returns:
An Arc<Widget> representing the newly drawn static widget.
Example:
use osui::prelude::*;
let screen = Screen::new();
let my_text_widget = screen.draw("Hello, Static World!");
Screen::draw_box(self: &Arc<Self>, element: BoxedElement) -> Arc<Widget>
Draws a boxed Element to the screen and returns its Arc<Widget> handle.
Similar to draw, but takes a BoxedElement directly.
Arguments:
element: ABox<dyn Element + Send + Sync>.
Returns:
An Arc<Widget> representing the newly drawn static widget.
Example:
use osui::prelude::*;
let screen = Screen::new();
let my_div_widget = screen.draw_box(Box::new(Div::new()));