pub struct Context<'a, 'input> { /* private fields */ }Expand description
Context is a temporary object that is created for each frame. Its primary purpose is to build a UI tree.
Implementations§
Source§impl<'a> Context<'a, '_>
impl<'a> Context<'a, '_>
Sourcepub fn arena(&self) -> &'a Arena
pub fn arena(&self) -> &'a Arena
Get an arena for temporary allocations such as for arena_format.
Sourcepub fn indexed(&self, index: IndexedColor) -> u32
pub fn indexed(&self, index: IndexedColor) -> u32
Returns an indexed color from the framebuffer.
Sourcepub fn indexed_alpha(
&self,
index: IndexedColor,
numerator: u32,
denominator: u32,
) -> u32
pub fn indexed_alpha( &self, index: IndexedColor, numerator: u32, denominator: u32, ) -> u32
Returns an indexed color from the framebuffer with the given alpha.
See Framebuffer::indexed_alpha().
Sourcepub fn contrasted(&self, color: u32) -> u32
pub fn contrasted(&self, color: u32) -> u32
Returns a color in contrast with the given color.
See Framebuffer::contrasted().
Sourcepub fn clipboard_ref(&self) -> &Clipboard
pub fn clipboard_ref(&self) -> &Clipboard
Returns the clipboard.
Sourcepub fn clipboard_mut(&mut self) -> &mut Clipboard
pub fn clipboard_mut(&mut self) -> &mut Clipboard
Returns the clipboard (mutable).
Sourcepub fn needs_rerender(&mut self)
pub fn needs_rerender(&mut self)
Tell the UI framework that your state changed and you need another layout pass.
Sourcepub fn block_begin(&mut self, classname: &'static str)
pub fn block_begin(&mut self, classname: &'static str)
Begins a generic UI block (container) with a unique ID derived from the given classname.
Sourcepub fn next_block_id_mixin(&mut self, id: u64)
pub fn next_block_id_mixin(&mut self, id: u64)
Mixes in an extra value to the next UI block’s ID for uniqueness. Use this when you build a list of items with the same classname.
Sourcepub fn focus_on_first_present(&mut self)
pub fn focus_on_first_present(&mut self)
If this is the first time the current node is being drawn, it’ll steal the active focus.
Sourcepub fn steal_focus(&mut self)
pub fn steal_focus(&mut self)
Steals the focus unconditionally.
Sourcepub fn toss_focus_up(&mut self)
pub fn toss_focus_up(&mut self)
If the current node owns the focus, it’ll be given to the parent.
Sourcepub fn inherit_focus(&mut self)
pub fn inherit_focus(&mut self)
If the parent node owns the focus, it’ll be given to the current node.
Sourcepub fn attr_focus_well(&mut self)
pub fn attr_focus_well(&mut self)
Causes keyboard focus to be unable to escape this node and its children. It’s a “well” because if the focus is inside it, it can’t escape.
Sourcepub fn attr_intrinsic_size(&mut self, size: Size)
pub fn attr_intrinsic_size(&mut self, size: Size)
Explicitly sets the intrinsic size of the current node. The intrinsic size is the size the node ideally wants to be.
Sourcepub fn attr_float(&mut self, spec: FloatSpec)
pub fn attr_float(&mut self, spec: FloatSpec)
Turns the current node into a floating node, like a popup, modal or a tooltip.
Sourcepub fn attr_border(&mut self)
pub fn attr_border(&mut self)
Gives the current node a border.
Sourcepub fn attr_position(&mut self, align: Position)
pub fn attr_position(&mut self, align: Position)
Sets the current node’s position inside the parent.
Sourcepub fn attr_padding(&mut self, padding: Rect)
pub fn attr_padding(&mut self, padding: Rect)
Assigns padding to the current node.
Sourcepub fn attr_background_rgba(&mut self, bg: u32)
pub fn attr_background_rgba(&mut self, bg: u32)
Assigns a sRGB background color to the current node.
Sourcepub fn attr_foreground_rgba(&mut self, fg: u32)
pub fn attr_foreground_rgba(&mut self, fg: u32)
Assigns a sRGB foreground color to the current node.
Sourcepub fn attr_reverse(&mut self)
pub fn attr_reverse(&mut self)
Applies reverse-video to the current node: Background and foreground colors are swapped.
Sourcepub fn consume_shortcut(&mut self, shortcut: InputKey) -> bool
pub fn consume_shortcut(&mut self, shortcut: InputKey) -> bool
Checks if the current keyboard input matches the given shortcut, consumes it if it is and returns true in that case.
Sourcepub fn keyboard_input(&self) -> Option<InputKey>
pub fn keyboard_input(&self) -> Option<InputKey>
Returns current keyboard input, if any. Returns None if the input was already consumed.
pub fn set_input_consumed(&mut self)
Sourcepub fn was_mouse_down(&mut self) -> bool
pub fn was_mouse_down(&mut self) -> bool
Returns whether the mouse was pressed down on the current node.
Sourcepub fn contains_mouse_down(&mut self) -> bool
pub fn contains_mouse_down(&mut self) -> bool
Returns whether the mouse was pressed down on the current node’s subtree.
Sourcepub fn is_focused(&mut self) -> bool
pub fn is_focused(&mut self) -> bool
Returns whether the current node is focused.
Sourcepub fn contains_focus(&mut self) -> bool
pub fn contains_focus(&mut self) -> bool
Returns whether the current node’s subtree is focused.
Sourcepub fn modal_begin(&mut self, classname: &'static str, title: &str)
pub fn modal_begin(&mut self, classname: &'static str, title: &str)
Begins a modal window. Call Context::modal_end().
Sourcepub fn modal_end(&mut self) -> bool
pub fn modal_end(&mut self) -> bool
Ends the current modal window block. Returns true if the user pressed Escape (a request to close).
Sourcepub fn table_begin(&mut self, classname: &'static str)
pub fn table_begin(&mut self, classname: &'static str)
Begins a table block. Call Context::table_end().
Tables are the primary way to create a grid layout,
and to layout controls on a single row (= a table with 1 row).
Sourcepub fn table_set_columns(&mut self, columns: &[CoordType])
pub fn table_set_columns(&mut self, columns: &[CoordType])
Assigns widths to the columns of the current table. By default, the table will left-align all columns.
Sourcepub fn table_set_cell_gap(&mut self, cell_gap: Size)
pub fn table_set_cell_gap(&mut self, cell_gap: Size)
Assigns the gap between cells in the current table.
Sourcepub fn table_next_row(&mut self)
pub fn table_next_row(&mut self)
Starts the next row in the current table.
Sourcepub fn styled_label_begin(&mut self, classname: &'static str)
pub fn styled_label_begin(&mut self, classname: &'static str)
Creates a styled text label.
§Example
use edit::framebuffer::IndexedColor;
use edit::tui::Context;
fn draw(ctx: &mut Context) {
ctx.styled_label_begin("label");
// Shows "Hello" in the inherited foreground color.
ctx.styled_label_add_text("Hello");
// Shows ", World!" next to "Hello" in red.
ctx.styled_label_set_foreground(ctx.indexed(IndexedColor::Red));
ctx.styled_label_add_text(", World!");
}Sourcepub fn styled_label_set_foreground(&mut self, fg: u32)
pub fn styled_label_set_foreground(&mut self, fg: u32)
Changes the active pencil color of the current label.
Sourcepub fn styled_label_set_attributes(&mut self, attr: Attributes)
pub fn styled_label_set_attributes(&mut self, attr: Attributes)
Changes the active pencil attributes of the current label.
Sourcepub fn styled_label_add_text(&mut self, text: &str)
pub fn styled_label_add_text(&mut self, text: &str)
Adds text to the current label.
Sourcepub fn styled_label_end(&mut self)
pub fn styled_label_end(&mut self)
Ends the current label block.
Sourcepub fn attr_overflow(&mut self, overflow: Overflow)
pub fn attr_overflow(&mut self, overflow: Overflow)
Sets the overflow behavior of the current label.
Creates a button with the given text. Returns true if the button was activated.
Sourcepub fn checkbox(
&mut self,
classname: &'static str,
text: &str,
checked: &mut bool,
) -> bool
pub fn checkbox( &mut self, classname: &'static str, text: &str, checked: &mut bool, ) -> bool
Creates a checkbox with the given text. Returns true if the checkbox was activated.
Sourcepub fn editline(
&mut self,
classname: &'static str,
text: &mut dyn WriteableDocument,
) -> bool
pub fn editline( &mut self, classname: &'static str, text: &mut dyn WriteableDocument, ) -> bool
Creates a text input field. Returns true if the text contents changed.
Sourcepub fn textarea(&mut self, classname: &'static str, tb: RcTextBuffer)
pub fn textarea(&mut self, classname: &'static str, tb: RcTextBuffer)
Creates a text area.
Sourcepub fn scrollarea_begin(
&mut self,
classname: &'static str,
intrinsic_size: Size,
)
pub fn scrollarea_begin( &mut self, classname: &'static str, intrinsic_size: Size, )
Creates a scrollable area.
Sourcepub fn scrollarea_scroll_to(&mut self, pos: Point)
pub fn scrollarea_scroll_to(&mut self, pos: Point)
Scrolls the current scrollable area to the given position.
Sourcepub fn scrollarea_end(&mut self)
pub fn scrollarea_end(&mut self)
Ends the current scrollarea block.
Sourcepub fn list_begin(&mut self, classname: &'static str)
pub fn list_begin(&mut self, classname: &'static str)
Creates a list where exactly one item is selected.
Sourcepub fn list_item(&mut self, select: bool, text: &str) -> ListSelection
pub fn list_item(&mut self, select: bool, text: &str) -> ListSelection
Creates a list item with the given text.
Sourcepub fn styled_list_item_begin(&mut self)
pub fn styled_list_item_begin(&mut self)
Creates a list item consisting of a styled label.
See Context::styled_label_begin.
Sourcepub fn styled_list_item_end(&mut self, select: bool) -> ListSelection
pub fn styled_list_item_end(&mut self, select: bool) -> ListSelection
Ends the current styled list item.
Sourcepub fn list_item_steal_focus(&mut self)
pub fn list_item_steal_focus(&mut self)
Context::steal_focus, but for a list view.
This exists, because didn’t want to figure out how to get
Context::styled_list_item_end to recognize a regular,
programmatic focus steal.
Creates a menubar, to be shown at the top of the screen.
Appends a menu to the current menubar.
Returns true if the menu is open. Continue appending items to it in that case.
Appends a button to the current menu.
Appends a checkbox to the current menu. Returns true if the checkbox was activated.
Ends the current menu.
Ends the current menubar.