Context

Struct Context 

Source
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, '_>

Source

pub fn arena(&self) -> &'a Arena

Get an arena for temporary allocations such as for arena_format.

Source

pub fn size(&self) -> Size

Returns the viewport size.

Source

pub fn indexed(&self, index: IndexedColor) -> u32

Returns an indexed color from the framebuffer.

Source

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().

Source

pub fn contrasted(&self, color: u32) -> u32

Returns a color in contrast with the given color. See Framebuffer::contrasted().

Source

pub fn clipboard_ref(&self) -> &Clipboard

Returns the clipboard.

Source

pub fn clipboard_mut(&mut self) -> &mut Clipboard

Returns the clipboard (mutable).

Source

pub fn needs_rerender(&mut self)

Tell the UI framework that your state changed and you need another layout pass.

Source

pub fn block_begin(&mut self, classname: &'static str)

Begins a generic UI block (container) with a unique ID derived from the given classname.

Source

pub fn block_end(&mut self)

Ends the current UI block, returning to its parent container.

Source

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.

Source

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.

Source

pub fn steal_focus(&mut self)

Steals the focus unconditionally.

Source

pub fn toss_focus_up(&mut self)

If the current node owns the focus, it’ll be given to the parent.

Source

pub fn inherit_focus(&mut self)

If the parent node owns the focus, it’ll be given to the current node.

Source

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.

Source

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.

Source

pub fn attr_float(&mut self, spec: FloatSpec)

Turns the current node into a floating node, like a popup, modal or a tooltip.

Source

pub fn attr_border(&mut self)

Gives the current node a border.

Source

pub fn attr_position(&mut self, align: Position)

Sets the current node’s position inside the parent.

Source

pub fn attr_padding(&mut self, padding: Rect)

Assigns padding to the current node.

Source

pub fn attr_background_rgba(&mut self, bg: u32)

Assigns a sRGB background color to the current node.

Source

pub fn attr_foreground_rgba(&mut self, fg: u32)

Assigns a sRGB foreground color to the current node.

Source

pub fn attr_reverse(&mut self)

Applies reverse-video to the current node: Background and foreground colors are swapped.

Source

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.

Source

pub fn keyboard_input(&self) -> Option<InputKey>

Returns current keyboard input, if any. Returns None if the input was already consumed.

Source

pub fn set_input_consumed(&mut self)

Source

pub fn was_mouse_down(&mut self) -> bool

Returns whether the mouse was pressed down on the current node.

Source

pub fn contains_mouse_down(&mut self) -> bool

Returns whether the mouse was pressed down on the current node’s subtree.

Source

pub fn is_focused(&mut self) -> bool

Returns whether the current node is focused.

Source

pub fn contains_focus(&mut self) -> bool

Returns whether the current node’s subtree is focused.

Source

pub fn modal_begin(&mut self, classname: &'static str, title: &str)

Begins a modal window. Call Context::modal_end().

Source

pub fn modal_end(&mut self) -> bool

Ends the current modal window block. Returns true if the user pressed Escape (a request to close).

Source

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).

Source

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.

Source

pub fn table_set_cell_gap(&mut self, cell_gap: Size)

Assigns the gap between cells in the current table.

Source

pub fn table_next_row(&mut self)

Starts the next row in the current table.

Source

pub fn table_end(&mut self)

Ends the current table block.

Source

pub fn label(&mut self, classname: &'static str, text: &str)

Creates a simple text label.

Source

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!");
}
Source

pub fn styled_label_set_foreground(&mut self, fg: u32)

Changes the active pencil color of the current label.

Source

pub fn styled_label_set_attributes(&mut self, attr: Attributes)

Changes the active pencil attributes of the current label.

Source

pub fn styled_label_add_text(&mut self, text: &str)

Adds text to the current label.

Source

pub fn styled_label_end(&mut self)

Ends the current label block.

Source

pub fn attr_overflow(&mut self, overflow: Overflow)

Sets the overflow behavior of the current label.

Source

pub fn button( &mut self, classname: &'static str, text: &str, style: ButtonStyle, ) -> bool

Creates a button with the given text. Returns true if the button was activated.

Source

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.

Source

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.

Source

pub fn textarea(&mut self, classname: &'static str, tb: RcTextBuffer)

Creates a text area.

Source

pub fn scrollarea_begin( &mut self, classname: &'static str, intrinsic_size: Size, )

Creates a scrollable area.

Source

pub fn scrollarea_scroll_to(&mut self, pos: Point)

Scrolls the current scrollable area to the given position.

Source

pub fn scrollarea_end(&mut self)

Ends the current scrollarea block.

Source

pub fn list_begin(&mut self, classname: &'static str)

Creates a list where exactly one item is selected.

Source

pub fn list_item(&mut self, select: bool, text: &str) -> ListSelection

Creates a list item with the given text.

Source

pub fn styled_list_item_begin(&mut self)

Creates a list item consisting of a styled label. See Context::styled_label_begin.

Source

pub fn styled_list_item_end(&mut self, select: bool) -> ListSelection

Ends the current styled list item.

Source

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.

Source

pub fn list_end(&mut self)

Ends the current list block.

Source

pub fn menubar_begin(&mut self)

Creates a menubar, to be shown at the top of the screen.

Source

pub fn menubar_menu_begin(&mut self, text: &str, accelerator: char) -> bool

Appends a menu to the current menubar.

Returns true if the menu is open. Continue appending items to it in that case.

Source

pub fn menubar_menu_button( &mut self, text: &str, accelerator: char, shortcut: InputKey, ) -> bool

Appends a button to the current menu.

Source

pub fn menubar_menu_checkbox( &mut self, text: &str, accelerator: char, shortcut: InputKey, checked: bool, ) -> bool

Appends a checkbox to the current menu. Returns true if the checkbox was activated.

Source

pub fn menubar_menu_end(&mut self)

Ends the current menu.

Source

pub fn menubar_end(&mut self)

Ends the current menubar.

Trait Implementations§

Source§

impl<'a> Drop for Context<'a, '_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, 'input> Freeze for Context<'a, 'input>

§

impl<'a, 'input> !RefUnwindSafe for Context<'a, 'input>

§

impl<'a, 'input> !Send for Context<'a, 'input>

§

impl<'a, 'input> !Sync for Context<'a, 'input>

§

impl<'a, 'input> Unpin for Context<'a, 'input>

§

impl<'a, 'input> !UnwindSafe for Context<'a, 'input>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.