pub struct Ui<M> { /* private fields */ }Expand description
The element tree, the stylesheets that style it, and the focus.
M is the application’s message type. Handlers produce messages, and
handle returns them for the application to act on,
which keeps every decision in explicit application code rather than in
callbacks scattered through the tree.
A frame goes: feed events to handle, act on the
messages, layout, paint.
Implementations§
Source§impl<M: 'static> Ui<M>
impl<M: 'static> Ui<M>
Sourcepub fn paint(&self, renderer: &mut dyn Renderer)
pub fn paint(&self, renderer: &mut dyn Renderer)
Draws the whole tree, as last laid out, through renderer.
For each element, in tree order: the background, the border, the widget’s own content, then its children. Nothing is clipped unless a widget asks for it, so an element that overflows its parent shows.
Source§impl<M: 'static> Ui<M>
impl<M: 'static> Ui<M>
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty tree styled by the default theme.
Sourcepub fn set_theme(&mut self, theme: Stylesheet)
pub fn set_theme(&mut self, theme: Stylesheet)
Replaces every stylesheet with this one.
Sourcepub fn add_stylesheet(&mut self, sheet: Stylesheet)
pub fn add_stylesheet(&mut self, sheet: Stylesheet)
Adds a stylesheet after the existing ones, so it wins ties.
pub fn styler(&self) -> &Styler
Sourcepub fn styler_mut(&mut self) -> &mut Styler
pub fn styler_mut(&mut self) -> &mut Styler
The style engine, for changing the root font size and the like.
Sourcepub fn set_root(&mut self, element: Element<M>) -> NodeId
pub fn set_root(&mut self, element: Element<M>) -> NodeId
Replaces the whole tree with element.
Sourcepub fn mount(&mut self, parent: NodeId, element: Element<M>) -> NodeId
pub fn mount(&mut self, parent: NodeId, element: Element<M>) -> NodeId
Appends element as the last child of parent.
pub fn root(&self) -> Option<NodeId>
pub fn contains(&self, id: NodeId) -> bool
pub fn parent(&self, id: NodeId) -> Option<NodeId>
pub fn children(&self, id: NodeId) -> &[NodeId]
pub fn tag(&self, id: NodeId) -> &'static str
Sourcepub fn content_rect(&self, id: NodeId) -> Rect
pub fn content_rect(&self, id: NodeId) -> Rect
The element’s content box, as of the last layout.
Sourcepub fn style(&self, id: NodeId) -> &ComputedStyle
pub fn style(&self, id: NodeId) -> &ComputedStyle
The element’s style, as of the last layout.
Sourcepub fn state(&self, id: NodeId) -> ElementState
pub fn state(&self, id: NodeId) -> ElementState
The element’s full state: what the framework tracks, what the widget
owns, and DISABLED if it is disabled.
Sourcepub fn widget<W: Widget<M>>(&self, id: NodeId) -> Option<&W>
pub fn widget<W: Widget<M>>(&self, id: NodeId) -> Option<&W>
The widget behind an element, if it is a W.
Sourcepub fn widget_mut<W: Widget<M>>(&mut self, id: NodeId) -> Option<&mut W>
pub fn widget_mut<W: Widget<M>>(&mut self, id: NodeId) -> Option<&mut W>
The widget behind an element, for changing it. Styles and layout are recomputed afterwards.
Sourcepub fn hit_test(&self, point: Point) -> Option<NodeId>
pub fn hit_test(&self, point: Point) -> Option<NodeId>
The deepest element under point, as of the last layout.
Sourcepub fn preorder(&self) -> Vec<NodeId>
pub fn preorder(&self) -> Vec<NodeId>
Every element, parents before children, siblings in order.
Sourcepub fn needs_layout(&self) -> bool
pub fn needs_layout(&self) -> bool
Whether something changed since the last layout.
pub fn viewport(&self) -> Size
pub fn has_class(&self, id: NodeId, class: &str) -> bool
pub fn is_disabled(&self, id: NodeId) -> bool
Sourcepub fn set_disabled(&mut self, id: NodeId, disabled: bool)
pub fn set_disabled(&mut self, id: NodeId, disabled: bool)
A disabled element matches :disabled, gets no events and cannot
take focus.
Sourcepub fn set_state(&mut self, id: NodeId, name: &str, on: bool)
pub fn set_state(&mut self, id: NodeId, name: &str, on: bool)
Sets or clears a custom state, matched by :state(name).
Sourcepub fn set_attr(&mut self, id: NodeId, name: &str, value: &str) -> bool
pub fn set_attr(&mut self, id: NodeId, name: &str, value: &str) -> bool
Sets an attribute at run time, the same ones Element::attr takes.
Returns false for an attribute the element does not accept or a
value it cannot parse, rather than panicking, since the value may
come from anywhere.
Sourcepub fn set_inline_style(&mut self, id: NodeId, css: &str) -> Result<(), Error>
pub fn set_inline_style(&mut self, id: NodeId, css: &str) -> Result<(), Error>
Replaces the inline style.
pub fn focused(&self) -> Option<NodeId>
pub fn hovered(&self) -> Option<NodeId>
Sourcepub fn focus(&mut self, id: NodeId) -> bool
pub fn focus(&mut self, id: NodeId) -> bool
Moves keyboard focus to id, if it can take it. Focus moved this
way shows as :focus-visible, like focus moved with the keyboard.
pub fn blur(&mut self)
Sourcepub fn move_focus(&mut self, forward: bool)
pub fn move_focus(&mut self, forward: bool)
Moves focus to the next (or previous) focusable element in tree order, wrapping around. What Tab and Shift+Tab do.
Sourcepub fn bind(&mut self, shortcut: Shortcut, handler: impl FnMut() -> M + 'static)
pub fn bind(&mut self, shortcut: Shortcut, handler: impl FnMut() -> M + 'static)
Binds a shortcut for the whole window. Global shortcuts are checked before element shortcuts and before the focused element sees the key.
pub fn unbind(&mut self, shortcut: Shortcut)
Sourcepub fn shortcuts(&self) -> Vec<(Shortcut, Option<NodeId>)>
pub fn shortcuts(&self) -> Vec<(Shortcut, Option<NodeId>)>
Every shortcut in effect: the global ones and those of elements that are not disabled, with the element’s id when it has one. For help screens and menus.
Sourcepub fn handle(&mut self, event: &Event, fonts: &dyn Fonts) -> Vec<M>
pub fn handle(&mut self, event: &Event, fonts: &dyn Fonts) -> Vec<M>
Feeds one event through the tree and returns the messages it produced.
Pointer events go to the deepest element under the pointer and bubble up until a widget handles them; while a button is held, they go to the element it was pressed on. Key events go first to global shortcuts, then to element shortcuts, then to the focused element, and finally Tab and Shift+Tab move focus. Text goes to the focused element.
Hit-testing uses the last layout, so call layout
after changes before feeding more pointer events.