Struct Ui

Source
pub struct Ui { /* private fields */ }
Expand description

A reference for building the user interface for one frame

Implementations§

Source§

impl Ui

§Clipboard

Source

pub fn clipboard_text(&self) -> Option<String>

Returns the current clipboard contents as text, or None if the clipboard is empty or cannot be accessed

Source

pub fn set_clipboard_text(&self, text: impl AsRef<str>)

Sets the clipboard contents.

Does nothing if the clipboard cannot be accessed.

Source§

impl Ui

§Columns

Source

pub fn columns(&self, count: i32, id: impl AsRef<str>, border: bool)

Source

pub fn next_column(&self)

Switches to the next column.

If the current row is finished, switches to first column of the next row

Source

pub fn current_column_index(&self) -> i32

Returns the index of the current column

Source

pub fn current_column_width(&self) -> f32

Returns the width of the current column (in pixels)

Source

pub fn column_width(&self, column_index: i32) -> f32

Returns the width of the given column (in pixels)

Source

pub fn set_current_column_width(&self, width: f32)

Sets the width of the current column (in pixels)

Source

pub fn set_column_width(&self, column_index: i32, width: f32)

Sets the width of the given column (in pixels)

Source

pub fn current_column_offset(&self) -> f32

Returns the offset of the current column (in pixels from the left side of the content region)

Source

pub fn column_offset(&self, column_index: i32) -> f32

Returns the offset of the given column (in pixels from the left side of the content region)

Source

pub fn set_current_column_offset(&self, offset_x: f32)

Sets the offset of the current column (in pixels from the left side of the content region)

Source

pub fn set_column_offset(&self, column_index: i32, offset_x: f32)

Sets the offset of the given column (in pixels from the left side of the content region)

Source

pub fn column_count(&self) -> i32

Returns the current amount of columns

Source§

impl Ui

Source§

impl Ui

Source

pub fn drag_drop_source_config<T: AsRef<str>>( &self, name: T, ) -> DragDropSource<'_, T>

Creates a new DragDropSource with the given name.

Source§

impl Ui

Source

pub fn drag_drop_target(&self) -> Option<DragDropTarget<'_>>

Creates a new DragDropTarget, which gives methods for handling accepting payloads.

Source§

impl Ui

§Fonts

Source

pub fn current_font(&self) -> &Font

Returns the current font

Source

pub fn current_font_size(&self) -> f32

Returns the current font size (= height in pixels) with font scale applied

Source

pub fn font_tex_uv_white_pixel(&self) -> [f32; 2]

Returns the UV coordinate for a white pixel.

Useful for drawing custom shapes with the draw list API.

Source

pub fn set_window_font_scale(&self, scale: f32)

Sets the font scale of the current window

Source§

impl Ui

§Input: Keyboard

Source

pub fn is_key_down(&self, key: Key) -> bool

Returns true if the key is being held.

Equivalent to indexing the Io struct keys_down field: ui.io().keys_down[key_index]

Source

pub fn is_key_index_down(&self, key_index: u32) -> bool

Same as is_key_down but takes a key index. The meaning of index is defined by your backend implementation.

Source

pub fn is_key_pressed(&self, key: Key) -> bool

Returns true if the key was pressed (went from !down to down).

Affected by key repeat settings (io.key_repeat_delay, io.key_repeat_rate)

Source

pub fn is_key_index_pressed(&self, key_index: u32) -> bool

Same as is_key_pressed but takes a key index.

The meaning of index is defined by your backend implementation.

Source

pub fn is_key_pressed_no_repeat(&self, key: Key) -> bool

Returns true if the key was pressed (went from !down to down).

Is not affected by key repeat settings (io.key_repeat_delay, io.key_repeat_rate)

Source

pub fn is_key_index_pressed_no_repeat(&self, key_index: u32) -> bool

Same as is_key_pressed_no_repeat but takes a key index.

The meaning of index is defined by your backend implementation.

Source

pub fn is_key_released(&self, key: Key) -> bool

Returns true if the key was released (went from down to !down)

Source

pub fn is_key_index_released(&self, key_index: u32) -> bool

Same as is_key_released but takes a key index.

The meaning of index is defined by your backend implementation.

Source

pub fn key_pressed_amount(&self, key: Key, repeat_delay: f32, rate: f32) -> u32

Returns a count of key presses using the given repeat rate/delay settings.

Usually returns 0 or 1, but might be >1 if rate is small enough that io.delta_time > rate.

Source

pub fn key_index_pressed_amount( &self, key_index: u32, repeat_delay: f32, rate: f32, ) -> u32

Same as crate::Ui::key_pressed_amount but takes a key index.

Source

pub fn set_keyboard_focus_here(&self)

Focuses keyboard on the next widget.

This is the equivalent to set_keyboard_focus_here_with_offset with target_widget set to FocusedWidget::Next.

Source

pub fn set_keyboard_focus_here_with_offset(&self, target_widget: FocusedWidget)

Focuses keyboard on a widget relative to current position.

Source§

impl Ui

§Input: Mouse

Source

pub fn is_mouse_down(&self, button: MouseButton) -> bool

Returns true if the given mouse button is held down.

Equivalent to indexing the Io struct with the button, e.g. ui.io()[button].

Source

pub fn is_any_mouse_down(&self) -> bool

Returns true if any mouse button is held down

Source

pub fn is_mouse_clicked(&self, button: MouseButton) -> bool

Returns true if the given mouse button was clicked (went from !down to down)

Source

pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool

Returns true if the given mouse button was double-clicked

Source

pub fn is_mouse_released(&self, button: MouseButton) -> bool

Returns true if the given mouse button was released (went from down to !down)

Source

pub fn is_mouse_dragging(&self, button: MouseButton) -> bool

Returns true if the mouse is currently dragging with the given mouse button held down

Source

pub fn is_mouse_dragging_with_threshold( &self, button: MouseButton, threshold: f32, ) -> bool

Returns true if the mouse is currently dragging with the given mouse button held down.

If the given threshold is invalid or negative, the global distance threshold is used (io.mouse_drag_threshold).

Source

pub fn is_mouse_hovering_rect( &self, r_min: impl Into<Vector2<f32>>, r_max: impl Into<Vector2<f32>>, ) -> bool

Returns true if the mouse is hovering over the given bounding rect.

Clipped by current clipping settings, but disregards other factors like focus, window ordering, modal popup blocking.

Source

pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2]

Returns the mouse position backed up at the time of opening a popup

Source

pub fn mouse_drag_delta(&self) -> [f32; 2]

Returns the delta from the initial position when the left mouse button clicked.

This is locked and returns [0.0, 0.0] until the mouse has moved past the global distance threshold (io.mouse_drag_threshold).

This is the same as mouse_drag_delta_with_button with button set to MouseButton::Left.

Source

pub fn mouse_drag_delta_with_button(&self, button: MouseButton) -> [f32; 2]

Returns the delta from the initial position when the given button was clicked.

This is locked and returns [0.0, 0.0] until the mouse has moved past the global distance threshold (io.mouse_drag_threshold).

This is the same as mouse_drag_delta_with_threshold with threshold set to -1.0, which uses the global threshold io.mouse_drag_threshold.

Source

pub fn mouse_drag_delta_with_threshold( &self, button: MouseButton, threshold: f32, ) -> [f32; 2]

Returns the delta from the initial clicking position.

This is locked and returns [0.0, 0.0] until the mouse has moved past the given threshold. If the given threshold is invalid or negative, the global distance threshold is used (io.mouse_drag_threshold).

Source

pub fn reset_mouse_drag_delta(&self, button: MouseButton)

Resets the current delta from initial clicking position.

Source

pub fn mouse_cursor(&self) -> Option<MouseCursor>

Returns the currently desired mouse cursor type.

Returns None if no cursor should be displayed

Source

pub fn set_mouse_cursor(&self, cursor_type: Option<MouseCursor>)

Sets the desired mouse cursor type.

Passing None hides the mouse cursor.

Source

pub fn is_current_mouse_pos_valid(&self) -> bool

Source

pub fn is_mouse_pos_valid(&self, mouse_pos: impl Into<Vector2<f32>>) -> bool

Source§

impl Ui

§Cursor / Layout

Source

pub fn separator(&self)

Renders a separator (generally horizontal).

This becomes a vertical separator inside a menu bar or in horizontal layout mode.

Source

pub fn same_line(&self)

Call between widgets or groups to layout them horizontally.

X position is given in window coordinates.

This is equivalent to calling same_line_with_pos with the pos set to 0.0, which uses Style::item_spacing.

Source

pub fn same_line_with_pos(&self, pos_x: f32)

Call between widgets or groups to layout them horizontally.

X position is given in window coordinates.

This is equivalent to calling same_line_with_spacing with the spacing set to -1.0, which means no extra spacing.

Source

pub fn same_line_with_spacing(&self, pos_x: f32, spacing_w: f32)

Call between widgets or groups to layout them horizontally.

X position is given in window coordinates.

Source

pub fn new_line(&self)

Undo a same_line call or force a new line when in horizontal layout mode

Source

pub fn spacing(&self)

Adds vertical spacing

Source

pub fn dummy(&self, size: impl Into<Vector2<f32>>)

Fills a space of size in pixels with nothing on the current window.

Can be used to move the cursor on the window.

Source

pub fn indent(&self)

Moves content position to the right by Style::indent_spacing

This is equivalent to indent_by with width set to Style::ident_spacing.

Source

pub fn indent_by(&self, width: f32)

Moves content position to the right by width

Source

pub fn unindent(&self)

Moves content position to the left by Style::indent_spacing

This is equivalent to unindent_by with width set to Style::ident_spacing.

Source

pub fn unindent_by(&self, width: f32)

Moves content position to the left by width

Source

pub fn begin_group(&self) -> GroupToken<'_>

Groups items together as a single item.

May be useful to handle the same mouse event on a group of items, for example.

Returns a GroupToken that must be ended by calling .end()

Source

pub fn group<R, F: FnOnce() -> R>(&self, f: F) -> R

Creates a layout group and runs a closure to construct the contents.

May be useful to handle the same mouse event on a group of items, for example.

Source

pub fn cursor_pos(&self) -> [f32; 2]

Returns the cursor position (in window coordinates)

Source

pub fn set_cursor_pos(&self, pos: impl Into<Vector2<f32>>)

Sets the cursor position (in window coordinates).

This sets the point on which the next widget will be drawn.

Source

pub fn cursor_start_pos(&self) -> [f32; 2]

Returns the initial cursor position (in window coordinates)

Source

pub fn cursor_screen_pos(&self) -> [f32; 2]

Returns the cursor position (in absolute screen coordinates).

This is especially useful for drawing, as the drawing API uses screen coordinates.

Source

pub fn set_cursor_screen_pos(&self, pos: impl Into<Vector2<f32>>)

Sets the cursor position (in absolute screen coordinates)

Source

pub fn align_text_to_frame_padding(&self)

Vertically aligns text baseline so that it will align properly to regularly frame items.

Call this if you have text on a line before a framed item.

Source

pub fn text_line_height(&self) -> f32

Source

pub fn text_line_height_with_spacing(&self) -> f32

Source

pub fn frame_height(&self) -> f32

Source

pub fn frame_height_with_spacing(&self) -> f32

Source§

impl Ui

Source

pub fn open_popup(&self, str_id: impl AsRef<str>)

Instructs ImGui that a popup is open.

You should call this function once while calling any of the following per-frame:

The confusing aspect to popups is that ImGui holds control over the popup itself.

Source

pub fn begin_popup(&self, str_id: impl AsRef<str>) -> Option<PopupToken<'_>>

Construct a popup that can have any kind of content.

This should be called per frame, whereas open_popup should be called once to signal that this popup is active.

Source

pub fn popup<F>(&self, str_id: impl AsRef<str>, f: F)
where F: FnOnce(),

Construct a popup that can have any kind of content.

This should be called per frame, whereas open_popup should be called once to signal that this popup is active.

Source

pub fn modal_popup<Label, Func, R>(&self, str_id: Label, f: Func) -> Option<R>
where Label: AsRef<str>, Func: FnOnce() -> R,

Creates a PopupModal, and runs a closure on it.

To customize the behavior of this PopupModal, use modal_popup_config.

Source

pub fn begin_modal_popup<Label: AsRef<str>>( &self, str_id: Label, ) -> Option<PopupToken<'_>>

Creates a PopupModal, returning a drop token.

To customize the behavior of this PopupModal, use modal_popup_config.

Source

pub fn modal_popup_config<Label: AsRef<str>>( &self, str_id: Label, ) -> PopupModal<'_, '_, Label>

Creates a PopupModal builder.

Source

pub fn close_current_popup(&self)

Close a popup. Should be called within the closure given as argument to Ui::popup or Ui::modal_popup.

Source

pub fn begin_popup_context_item(&self) -> Option<PopupToken<'_>>

Open and begin popup when clicked with the right mouse button on last item.

This does not take a label, which means that multiple calls in a row will use the same label, which is based on the last node which had a label. Text and other non-interactive elements generally don’t have ids, so you’ll need to use begin_popup_context_with_label for them.

Source

pub fn begin_popup_context_with_label<Label: AsRef<str>>( &self, str_id: Label, ) -> Option<PopupToken<'_>>

Open and begin popup when clicked with the right mouse button on the given item with a dedicated label.

If you want to use the label of the previous popup (outside of Text and other non-interactive cases, that is the more normal case), use begin_popup_context_item.

Source

pub fn begin_popup_context_window(&self) -> Option<PopupToken<'_>>

Open and begin popup when clicked on current window.

This does not take a label, which means that multiple calls will use the same provided label. If you want an explicit label, such as having two different kinds of windows popups in your program, use begin_popup_context_window_with_label.

Source

pub fn begin_popup_context_window_with_label<Label: AsRef<str>>( &self, str_id: Label, ) -> Option<PopupToken<'_>>

Open and begin popup when clicked on current window.

This takes a label explicitly. This is useful when multiple code locations may want to manipulate/open the same popup, given an explicit id.

Source

pub fn begin_popup_context_void(&self) -> Option<PopupToken<'_>>

Open and begin popup when right clicked in void (where there are no windows).

This does not take a label, which means that multiple calls will use the same provided label. If you want an explicit label, such as having two different kinds of void popups in your program, use begin_popup_context_void_with_label.

Source

pub fn begin_popup_context_void_with_label<Label: AsRef<str>>( &self, str_id: Label, ) -> Option<PopupToken<'_>>

Open and begin popup when right clicked in void (where there are no windows).

This takes a label explicitly. This is useful when multiple code locations may want to manipulate/open the same popup, given an explicit id.

Source§

impl Ui

§Parameter stacks (shared)

Source

pub fn push_font(&self, id: FontId) -> FontStackToken<'_>

Switches to the given font by pushing it to the font stack.

Returns a FontStackToken that must be popped by calling .pop()

§Panics

Panics if the font atlas does not contain the given font

§Examples
// At initialization time
let my_custom_font = ctx.fonts().add_font(&font_data_sources);
// During UI construction
let font = ui.push_font(my_custom_font);
ui.text("I use the custom font!");
font.pop();
Source

pub fn push_style_color( &self, style_color: StyleColor, color: impl Into<Vector4<f32>>, ) -> ColorStackToken<'_>

Changes a style color by pushing a change to the color stack.

Returns a ColorStackToken that must be popped by calling .pop()

§Examples
const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
let color = ui.push_style_color(StyleColor::Text, RED);
ui.text("I'm red!");
color.pop();
Source

pub fn push_style_var(&self, style_var: StyleVar) -> StyleStackToken<'_>

Changes a style variable by pushing a change to the style stack.

Returns a StyleStackToken that can be popped by calling .end() or by allowing to drop.

§Examples
let style = ui.push_style_var(StyleVar::Alpha(0.2));
ui.text("I'm transparent!");
style.pop();
Source§

impl Ui

§Parameter stacks (current window)

Source

pub fn push_item_width(&self, item_width: f32) -> ItemWidthStackToken<'_>

Changes the item width by pushing a change to the item width stack.

Returns an ItemWidthStackToken. The pushed width item is popped when either ItemWidthStackToken goes out of scope, or .end() is called.

  • > 0.0: width is item_width pixels
  • = 0.0: default to ~2/3 of window width
  • < 0.0: item_width pixels relative to the right of window (-1.0 always aligns width to the right side)
Source

pub fn set_next_item_width(&self, item_width: f32)

Sets the width of the next item.

  • > 0.0: width is item_width pixels
  • = 0.0: default to ~2/3 of window width
  • < 0.0: item_width pixels relative to the right of window (-1.0 always aligns width to the right side)
Source

pub fn calc_item_width(&self) -> f32

Returns the width of the item given the pushed settings and the current cursor position.

This is NOT necessarily the width of last item.

Source

pub fn push_text_wrap_pos(&self) -> TextWrapPosStackToken<'_>

Makes the text wrap at the end of window/column (which is generally the default), by pushing a change to the text wrapping position stack.

This is the same as calling push_text_wrap_pos_with_pos with wrap_pos_x set to 0.0.

Returns a TextWrapPosStackToken. The pushed position item is popped when either TextWrapPosStackToken goes out of scope, or .end() is called.

Source

pub fn push_text_wrap_pos_with_pos( &self, wrap_pos_x: f32, ) -> TextWrapPosStackToken<'_>

Changes the text wrapping position by pushing a change to the text wrapping position stack.

Returns a TextWrapPosStackToken. The pushed position item is popped when either TextWrapPosStackToken goes out of scope, or .end() is called.

  • > 0.0: wrap at wrap_pos_x position in window local space
  • = 0.0: wrap to end of window (or column)
  • < 0.0: no wrapping
Source

pub fn push_allow_keyboard_focus( &self, allow: bool, ) -> PushAllowKeyboardFocusToken<'_>

Tab stop enable. Allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets

Returns a PushAllowKeyboardFocusToken that should be dropped.

Source

pub fn push_button_repeat(&self, allow: bool) -> PushButtonRepeatToken<'_>

In ‘repeat’ mode, button_x functions return repeated true in a typematic manner (using io.KeyRepeatDelay/io.KeyRepeatRate setting). Note that you can call IsItemActive() after any Button() to tell if the button is held in the current frame.

Returns a PushButtonRepeatToken that should be dropped.

Source

pub fn push_item_flag(&self, item_flag: ItemFlag) -> ItemFlagsStackToken<'_>

👎Deprecated since 0.9.0: use push_allow_keyboard_focus or push_button_repeat instead

Changes an item flag by pushing a change to the item flag stack.

Returns a ItemFlagsStackToken that may be popped by calling .pop()

§Deprecated

This was deprecated in 0.9.0 because it isn’t part of the dear imgui design, and supporting it required a manual implementation of its drop token.

Instead, just use push_allow_keyboard_focus and push_button_repeat.

Source§

impl Ui

§ID stack

Source

pub fn push_id(&self, s: impl AsRef<str>) -> IdStackToken<'_>

Pushes an identifier to the ID stack.

Returns an IdStackToken that can be popped by calling .end() or by dropping manually.

§Examples

Dear ImGui uses labels to uniquely identify widgets. For a good explaination, see this part of the Dear ImGui FAQ

In imgui-rs the same applies, we can manually specify labels with the ## syntax:


ui.button("Click##button1");
ui.button("Click##button2");

Here Click is the label used for both buttons, and everything after ## is used as the identifier.

However when you either have many items (say, created in a loop), we can use our loop number as an item in the “ID stack”:


ui.window("Example").build(|| {
    // The window adds "Example" to the token stack.
    for num in 0..10 {
        // And now we add the loop number to the stack too,
        // to make our buttons unique within this window.
        let _id = ui.push_id_usize(num);
        if ui.button("Click!") {
            println!("Button {} clicked", num);
        }
    }
});

We don’t have to use numbers - strings also work:


fn callback1(ui: &imgui::Ui) {
    if ui.button("Click") {
        println!("First button clicked")
    }
}

fn callback2(ui: &imgui::Ui) {
    if ui.button("Click") {
        println!("Second button clicked")
    }
}

ui.window("Example")
.build(||{
    {
        // Since we don't know what callback1 might do, we create
        // a unique ID stack by pushing (a hash of) "first" to the ID stack:
        let _id1 = ui.push_id("first");
        callback1(&ui);
    }
    {
        // Same for second callback. If we didn't do this, clicking the "Click" button
        // would trigger both println statements!
        let id2 = ui.push_id("second");
        callback2(&ui);
        // Here we manually end the scope. Typically letting it drop is neater
        // but sometimes it's useful to end the scope earlier
        id2.end();
        ui.text("We can do other things, outside of the id2 scope");
    }
});
Source

pub fn push_id_usize(&self, id: usize) -> IdStackToken<'_>

Pushes a usize to the ID stack.

Returns an IdStackToken that can be popped by calling .end() or by dropping manually.

See push_id for more information.

Source

pub fn push_id_int(&self, id: i32) -> IdStackToken<'_>

Pushes an i32 to the ID stack.

Returns an IdStackToken that can be popped by calling .end() or by dropping manually.

See push_id for more information.

Source

pub fn push_id_ptr<T>(&self, value: &T) -> IdStackToken<'_>

Pushes a ptr to the ID stack.

Returns an IdStackToken that can be popped by calling .end() or by dropping manually.

See push_id for more information.

Source§

impl Ui

Source

pub fn begin_table( &self, str_id: impl AsRef<str>, column_count: usize, ) -> Option<TableToken<'_>>

Begins a table with no flags and with standard sizing contraints.

This does no work on styling the headers (the top row) – see either begin_table_header or the more complex table_setup_column.

Nb: we take column as a usize, but it will be converted with as i32 to an i32. If this makes a difference to you, you are probably trying to make too many columns.

Source

pub fn begin_table_with_flags( &self, str_id: impl AsRef<str>, column_count: usize, flags: TableFlags, ) -> Option<TableToken<'_>>

Begins a table with flags and standard sizing contraints.

This does no work on styling the headers (the top row) – see either begin_table_header or the more complex table_setup_column.

Nb: we take column as a usize, but it will be converted with as i32 to an i32. If this makes a difference to you, you are probably trying to make too many columns.

Source

pub fn begin_table_with_sizing( &self, str_id: impl AsRef<str>, column: usize, flags: TableFlags, outer_size: [f32; 2], inner_width: f32, ) -> Option<TableToken<'_>>

Begins a table with all flags and sizing contraints. This is the base method, and gives users the most flexibility.

This does no work on styling the headers (the top row) – see either begin_table_header or the more complex table_setup_column.

Nb: we take column as a usize, but it will be converted with as i32 to an i32. If this makes a difference to you, you are probably trying to make too many columns.

Source

pub fn begin_table_header<Name: AsRef<str>, const N: usize>( &self, str_id: impl AsRef<str>, column_data: [TableColumnSetup<Name>; N], ) -> Option<TableToken<'_>>

Begins a table with no flags and with standard sizing contraints.

Takes an array of table header information, the length of which determines how many columns will be created.

Source

pub fn begin_table_header_with_flags<Name: AsRef<str>, const N: usize>( &self, str_id: impl AsRef<str>, column_data: [TableColumnSetup<Name>; N], flags: TableFlags, ) -> Option<TableToken<'_>>

Begins a table with flags and standard sizing contraints.

Takes an array of table header information, the length of which determines how many columns will be created.

Source

pub fn begin_table_header_with_sizing<Name: AsRef<str>, const N: usize>( &self, str_id: impl AsRef<str>, column_data: [TableColumnSetup<Name>; N], flags: TableFlags, outer_size: [f32; 2], inner_width: f32, ) -> Option<TableToken<'_>>

Begins a table with all flags and sizing contraints. This is the base method, and gives users the most flexibility. Takes an array of table header information, the length of which determines how many columns will be created.

Source

pub fn table_next_row(&self)

Moves a table to the next row (ie, down) with no flags, and with the next row having a standard computed height.

If your table was made with begin_table, this must be called before rendering any cells (along with table_next_column). If your table was made with begin_table_header, this does not need to be called, though table_next_column still should be.

Source

pub fn table_next_row_with_flags(&self, flags: TableRowFlags)

Moves a table to the next row (ie, down), with the given flags, and with the next row having a standard computed height.

Setting a flag here will make the next row a “header” now, which may require setup of column data.

See table_next_row for information on how moving rows work. To set the row with a given height, see table_next_row_with_height.

Source

pub fn table_next_row_with_height( &self, flags: TableRowFlags, min_row_height: f32, )

Moves a table to the next row (ie, down), with the given flags, and with the given minimum height.

See table_next_row for information on how moving rows work.

Source

pub fn table_next_column(&self) -> bool

Moves onto the next column. If at column_count, this will move to the next row. In this way, you can use this function as an iterator over each cell in the table.

§Example
if let Some(_t) = ui.begin_table("Basic-Table", 2) {
    // we have to call next_row because we didn't make headers..
    ui.table_next_row();

    // you always have to call this to start...
    // take advantage of this in loops!
    ui.table_next_column();
    ui.text("x: 0, y: 0");

    ui.table_next_column();
    ui.text("x: 1, y: 0");
     
    // notice that we go down a row here too.
    ui.table_next_column();
    ui.text("x: 0, y: 1");

    ui.table_next_column();
    ui.text("x: 1, y: 1");
}

This functions returns true if the given column is visible. It is not marked as must use, as you can still render commands into the not-visible column, though you can choose to not as an optimization.

Source

pub fn table_set_column_index(&self, column_index: usize) -> bool

Moves onto the given column.

§Example
if let Some(_t) = ui.begin_table("Basic-Table", 2) {
    // we have to call next_row because we didn't make headers..
    ui.table_next_row();

    for i in 0..2 {
        ui.table_set_column_index(i);
        ui.text(format!("x: {}", i));
    }
     
    // oops I just remembered, i need to add something on idx 0!
    ui.table_set_column_index(0);
    // if i uncomment this line, we'll write on top of our previous "x: 0"
    // line:
    // ui.text("hello from the future on top of the past");
    // so we do a .newline();
    ui.new_line();
    ui.text("hello from the future");

    // imgui will understand this and row spacing will be adjusted automatically.
}

This functions returns true if the given column is visible. It is not marked as must use, as you can still render commands into the not-visible column, though you can choose to not as an optimization.

§Panics

If column_index >= ui.table_columm_count, this function will panic. In debug releases, we will panic on the Rust side, for a nicer error message, though in release, we will panic in C++, which will result in an ugly stack overflow.

Source

pub fn table_setup_column(&self, str_id: impl AsRef<str>)

Specify label per column, with no flags and default sizing. You can avoid calling this method entirely by using begin_table_header.

§Example
if let Some(_t) = ui.begin_table("My Table", 2) {
    ui.table_setup_column("One");
    ui.table_setup_column("Two");
    ui.table_setup_column("Three");
    ui.table_headers_row();

    // call next_column/set_column_index and proceed like normal.
    // the above code is the equivalent of just using `begin_table_header`
    // but does allow for some columns to have headers and others to not
}

Along with table_headers_row, this method is used to create a header row and automatically submit a table header for each column. Headers are required to perform: reordering, sorting, and opening the context menu (though, the context menu can also be made available in columns body using TableFlags::CONTEXT_MENU_IN_BODY.

Source

pub fn table_setup_column_with<N: AsRef<str>>(&self, data: TableColumnSetup<N>)

Specify label per column, with data given in TableColumnSetup. You can avoid calling this method entirely by using begin_table_header.

See table_setup_column for an example of how to setup columns yourself.

Along with table_headers_row, this method is used to create a header row and automatically submit a table header for each column. Headers are required to perform: reordering, sorting, and opening the context menu (though, the context menu can also be made available in columns body using TableFlags::CONTEXT_MENU_IN_BODY.

Source

pub fn table_setup_scroll_freeze( &self, locked_columns: usize, locked_rows: usize, )

Locks columns/rows so they stay visible when scrolled. Generally, you will be calling this so that the header column is always visible (though go wild if you want). You can avoid calling this entirely by passing true to begin_table_header.

§Example
const COLUMN_COUNT: usize = 3;
if let Some(_t) = ui.begin_table("scroll-freeze-example", COLUMN_COUNT) {
    // locks the header row. Notice how we need to call it BEFORE `table_headers_row`.
    ui.table_setup_scroll_freeze(1, COLUMN_COUNT);
    ui.table_setup_column("One");
    ui.table_setup_column("Two");
    ui.table_setup_column("Three");
    ui.table_headers_row();
}

Nb: we take locked_columns and locked_rows as a usize, but it will be converted with as i32 to an i32. If this makes a difference to you, you are probably trying to make too many columns.

Source

pub fn table_headers_row(&self)

Along with table_setup_column, this method is used to create a header row and automatically submit a table header for each column.

For an example of using this method, see table_setup_column.

Headers are required to perform: reordering, sorting, and opening the context menu (though, the context menu can also be made available in columns body using TableFlags::CONTEXT_MENU_IN_BODY.

You may manually submit headers using table_next_column + table_header calls, but this is only useful in some advanced use cases (e.g. adding custom widgets in header row). See table_header for more information.

Source

pub fn table_header(&self, label: impl AsRef<str>)

Use this function to manually declare a column cell to be a header.

You generally should avoid using this outside of specific cases, such as custom widgets. Instead, use table_headers_row and table_setup_column.

Source

pub fn table_column_count(&self) -> usize

Gets the numbers of columns in the current table.

Source

pub fn table_column_index(&self) -> usize

Gets the current column index in the current table.

Source

pub fn table_row_index(&self) -> usize

Gets the current row index in the current table.

Source

pub fn table_column_name(&mut self) -> &str

Gets the name of the current column. If there is no currently bound name for this column, we will return an empty string.

Use table_column_name_with_column for arbitrary indices.

Source

pub fn table_column_name_with_column(&mut self, column: usize) -> &str

Gets the name of a given column. If there is no currently bound name for this column, we will return an empty string.

Use table_column_name for the current column.

Source

pub fn table_column_flags(&self) -> TableColumnFlags

Gets the flags on the current column in the current table.

Source

pub fn table_column_flags_with_column( &self, column_n: usize, ) -> TableColumnFlags

Gets the flags on the given column in the current table. To get the current column’s flags without having to call table_column_index, use table_column_flags.

Source

pub fn table_set_bg_color( &self, target: TableBgTarget, color: impl Into<ImColor32>, )

Sets the given background color for this column. See TableBgTarget for more information on how colors work for tables.

Use table_set_bg_color_with_column to set for arbitrary indices.

Source

pub fn table_set_bg_color_with_column( &self, target: TableBgTarget, color: impl Into<ImColor32>, column_index: usize, )

Sets the given background color for any column. See TableBgTarget for more information on how colors work for tables.

Use table_set_bg_color for the current column.

Source

pub fn table_set_enabled(&self, enabled: bool)

Change user accessible enabled/disabled state of the current column.

Set to false to hide the column. Users can use the context menu to change this themselves by right-clicking in headers, or right-clicking in columns body if TableFlags::CONTEXT_MENU_IN_BODY.

Use table_set_enabled_with_column to set for arbitrary indices.

Source

pub fn table_set_enabled_with_column(&self, enabled: bool, column_idx: usize)

Change user accessible enabled/disabled state of the current column.

Set to false to hide the column. Users can use the context menu to change this themselves by right-clicking in headers, or right-clicking in columns body if TableFlags::CONTEXT_MENU_IN_BODY.

Source

pub fn table_sort_specs_mut(&self) -> Option<TableSortSpecsMut<'_>>

Gets the sorting data for a table. This will be None when not sorting.

See the examples folder for how to use the sorting API.

Source§

impl Ui

Source§

impl Ui

§Item/widget utilities

Source

pub fn is_item_hovered(&self) -> bool

Returns true if the last item is hovered

Source

pub fn is_item_hovered_with_flags(&self, flags: ItemHoveredFlags) -> bool

Returns true if the last item is hovered based on the given flags

Source

pub fn is_item_active(&self) -> bool

Returns true if the last item is active

Source

pub fn is_item_focused(&self) -> bool

Returns true if the last item is focused for keyboard/gamepad navigation

Source

pub fn is_item_clicked(&self) -> bool

Returns true if the last item is being clicked by MouseButton::Left.

This is the same as is_item_clicked_with_button with button set to MouseButton::Left.

Source

pub fn is_item_clicked_with_button(&self, button: MouseButton) -> bool

Returns true if the last item is being clicked

Source

pub fn is_item_visible(&self) -> bool

Returns true if the last item is visible

Source

pub fn is_item_edited(&self) -> bool

Returns true if the last item modified its underlying value this frame or was pressed

Source

pub fn is_item_activated(&self) -> bool

Returns true if the last item was just made active

Source

pub fn is_item_deactivated(&self) -> bool

Returns true if the last item was just made inactive

Source

pub fn is_item_deactivated_after_edit(&self) -> bool

Returns true if the last item was just made inactive and made a value change when it was active

Source

pub fn is_item_toggled_open(&self) -> bool

Returns true if the last item open state was toggled

Source

pub fn is_any_item_hovered(&self) -> bool

Returns true if any item is hovered

Source

pub fn is_any_item_active(&self) -> bool

Returns true if any item is active

Source

pub fn is_any_item_focused(&self) -> bool

Returns true if any item is focused

Source

pub fn item_rect_min(&self) -> [f32; 2]

Returns the upper-left bounding rectangle of the last item (in screen coordinates)

Source

pub fn item_rect_max(&self) -> [f32; 2]

Returns the lower-right bounding rectangle of the last item (in screen coordinates)

Source

pub fn item_rect_size(&self) -> [f32; 2]

Returns the size of the last item

Source

pub fn set_item_allow_overlap(&self)

Allows the last item to be overlapped by a subsequent item.

Both may be activated during the same frame before the later one takes priority.

Source

pub fn set_item_default_focus(&self)

Makes the last item the default focused item of the window

Source§

impl Ui

§Miscellaneous utilities

Source

pub fn is_cursor_rect_visible(&self, size: impl Into<Vector2<f32>>) -> bool

Returns true if the rectangle (of given size, starting from cursor position) is visible

Source

pub fn is_rect_visible( &self, rect_min: impl Into<Vector2<f32>>, rect_max: impl Into<Vector2<f32>>, ) -> bool

Returns true if the rectangle (in screen coordinates) is visible

Source

pub fn time(&self) -> f64

Returns the global imgui-rs time.

Incremented by Io::delta_time every frame.

Source

pub fn frame_count(&self) -> i32

Returns the global imgui-rs frame count.

Incremented by 1 every frame.

Source

pub fn style_color(&self, style_color: StyleColor) -> [f32; 4]

Returns a single style color from the user interface style.

Use this function if you need to access the colors, but don’t want to clone the entire style object.

Source

pub fn style_color_name(&self, style_color: StyleColor) -> &'static str

Gets the name of some style color.

This is just a wrapper around calling name on StyleColor.

Source

pub unsafe fn style(&self) -> &Style

Returns a shared reference to the current Style.

§Safety

This function is tagged as unsafe because pushing via push_style_color or push_style_var or popping via ColorStackToken::pop or StyleStackToken::pop will modify the values in the returned shared reference. Therefore, you should not retain this reference across calls to push and pop. The clone_style version may instead be used to avoid unsafe.

Source§

impl Ui

Source

pub fn color_edit3<Label, C>(&self, label: Label, value: &mut C) -> bool
where Label: AsRef<str>, C: Copy + Into<Vector3<f32>>, Vector3<f32>: Into<C> + Into<[f32; 3]>,

Edits a color of 3 channels. Use color_edit3_config for a builder to customize this widget.

Source

pub fn color_edit3_config<'a, Label, C>( &self, label: Label, value: &'a mut C, ) -> ColorEdit3<'_, 'a, Label, C>
where Label: AsRef<str>, C: Copy + Into<Vector3<f32>>, Vector3<f32>: Into<C> + Into<[f32; 3]>,

Constructs a new color editor builder.

Source§

impl Ui

Source

pub fn color_edit4<Label, C>(&self, label: Label, value: &mut C) -> bool
where Label: AsRef<str>, C: Copy + Into<Vector4<f32>>, Vector4<f32>: Into<C> + Into<[f32; 4]>,

Edits a color of 4 channels. Use color_edit4_config for a builder to customize this widget.

Source

pub fn color_edit4_config<'a, Label, C>( &self, label: Label, value: &'a mut C, ) -> ColorEdit4<'_, 'a, Label, C>
where Label: AsRef<str>, C: Copy + Into<Vector4<f32>>, Vector4<f32>: Into<C> + Into<[f32; 4]>,

Constructs a new color editor builder.

Source§

impl Ui

Source

pub fn color_picker3<Label, C>(&self, label: Label, value: &mut C) -> bool
where Label: AsRef<str>, C: Copy + Into<Vector3<f32>>, Vector3<f32>: Into<C> + Into<[f32; 3]>,

Edits a color of 3 channels. Use color_picker3 for a builder to customize this widget.

Source

pub fn color_picker3_config<'a, Label, C>( &self, label: Label, value: &'a mut C, ) -> ColorPicker3<'_, 'a, Label, C>
where Label: AsRef<str>, C: Copy + Into<Vector3<f32>>, Vector3<f32>: Into<C> + Into<[f32; 3]>,

Constructs a new color picker editor builder.

Source§

impl Ui

Source

pub fn color_picker4<Label, C>(&self, label: Label, value: &mut C) -> bool
where Label: AsRef<str>, C: Copy + Into<Vector4<f32>>, Vector4<f32>: Into<C> + Into<[f32; 4]>,

Edits a color of 4 channels. Use color_picker4_config for a builder to customize this widget.

Source

pub fn color_picker4_config<'a, Label, C>( &self, label: Label, value: &'a mut C, ) -> ColorPicker4<'_, 'a, Label, C>
where Label: AsRef<str>, C: Copy + Into<Vector4<f32>>, Vector4<f32>: Into<C> + Into<[f32; 4]>,

Constructs a new color picker editor builder.

Source§

impl Ui

Source

pub fn color_button<Label: AsRef<str>>( &self, desc_id: Label, color: impl Into<Vector4<f32>>, ) -> bool

Builds a ColorButton.

Returns true if this color button was clicked.

Source

pub fn color_button_config<Label: AsRef<str>>( &self, desc_id: Label, color: impl Into<Vector4<f32>>, ) -> ColorButton<'_, Label>

Returns a ColorButton builder.

Source§

impl Ui

§Widgets: Color Editor/Picker

Source

pub fn set_color_edit_options(&self, flags: ColorEditFlags)

Initializes current color editor/picker options (generally on application startup) if you want to select a default format, picker type, etc. Users will be able to change many settings, unless you use .options(false) in your widget builders.

Source§

impl Ui

§Convenience functions

Source

pub fn begin_combo( &self, label: impl AsRef<str>, preview_value: impl AsRef<str>, ) -> Option<ComboBoxToken<'_>>

Begins flexibly creating a combo box.

You provide a preview string, which is displayed on the widget before it is opened. If the function returns Some(_token) you can then begin creating the widgets inside the combo popup area.

A standard looking combo is made by using selectable items, however you can create almost anything inside if desired (for example using Ui::separator and Ui::text to create sections with headings).

See the simpler Ui::combo_simple_string if you have a list of strings plus a “currently selected item index”, or Ui::combo

If you do not want to provide a preview, use begin_combo_no_preview. If you want to pass flags, use begin_combo_with_flags.

Returns None if the combo box is not open and no content should be rendered.

§Example

let items = vec!["Example 1", "Example 2"];
let mut selected = &items[0];
if let Some(cb) = ui.begin_combo("example_combo", format!("Selected item: {}", selected)) {
    for cur in &items {
        if selected == cur {
            // Auto-scroll to selected item
            ui.set_item_default_focus();
        }
        // Create a "selectable"
        let clicked = ui.selectable_config(cur)
            .selected(selected == cur)
            .build();
        // When item is clicked, store it
        if clicked {
            selected = cur;
        }
    }
}
Source

pub fn begin_combo_with_flags( &self, label: impl AsRef<str>, preview_value: impl AsRef<str>, flags: ComboBoxFlags, ) -> Option<ComboBoxToken<'_>>

Creates a combo box which can be appended to with Selectable::new.

If you do not want to provide a preview, use begin_combo_no_preview. Returns Some(ComboBoxToken) if the combo box is open. After content has been rendered, the token must be ended by calling .end().

Returns None if the combo box is not open and no content should be rendered.

Source

pub fn begin_combo_no_preview( &self, label: impl AsRef<str>, ) -> Option<ComboBoxToken<'_>>

Creates a combo box which can be appended to with Selectable::new.

If you want to provide a preview, use begin_combo. If you want to pass flags, use begin_combo_no_preview_with_flags.

Returns Some(ComboBoxToken) if the combo box is open. After content has been rendered, the token must be ended by calling .end().

Returns None if the combo box is not open and no content should be rendered.

Source

pub fn begin_combo_no_preview_with_flags( &self, label: impl AsRef<str>, flags: ComboBoxFlags, ) -> Option<ComboBoxToken<'_>>

Creates a combo box which can be appended to with Selectable::new.

If you do not want to provide a preview, use begin_combo_no_preview. Returns Some(ComboBoxToken) if the combo box is open. After content has been rendered, the token must be ended by calling .end().

Returns None if the combo box is not open and no content should be rendered.

Source

pub fn combo<V, L>( &self, label: impl AsRef<str>, current_item: &mut usize, items: &[V], label_fn: L, ) -> bool
where for<'b> L: Fn(&'b V) -> Cow<'b, str>,

Builds a simple combo box for choosing from a slice of values.

See Ui::begin_combo for a more “immediate mode” style API for creating dynamic combo boxes

Source

pub fn combo_simple_string( &self, label: impl AsRef<str>, current_item: &mut usize, items: &[impl AsRef<str>], ) -> bool

Builds a simple combo box for choosing from a slice of strings

This is useful if you already have a list of strings to choose from, along with a currently selected idnex value. In cases where you have a list of non-string objects, instead of allocating a Vec<String> to use this method try using Ui::begin_combo instead

Source§

impl Ui

Source

pub fn image_button( &self, str_id: impl AsRef<str>, texture_id: TextureId, size: impl Into<Vector2<f32>>, ) -> bool

Source

pub fn image_button_config<IdStr: AsRef<str>>( &self, str_id: IdStr, texture_id: TextureId, size: impl Into<Vector2<f32>>, ) -> ImageButton<'_, IdStr>

Source§

impl Ui

§Widgets: Menus

Source

pub fn begin_main_menu_bar(&self) -> Option<MainMenuBarToken<'_>>

Creates and starts appending to a full-screen menu bar.

Returns Some(MainMenuBarToken) if the menu bar is visible. After content has been rendered, the token must be ended by calling .end().

Returns None if the menu bar is not visible and no content should be rendered.

Source

pub fn main_menu_bar<F: FnOnce()>(&self, f: F)

Creates a full-screen main menu bar and runs a closure to construct the contents.

Note: the closure is not called if the menu bar is not visible.

Source

pub fn begin_menu_bar(&self) -> Option<MenuBarToken<'_>>

Creates and starts appending to the menu bar of the current window.

Returns Some(MenuBarToken) if the menu bar is visible. After content has been rendered, the token must be ended by calling .end().

Returns None if the menu bar is not visible and no content should be rendered.

Source

pub fn menu_bar<F: FnOnce()>(&self, f: F)

Creates a menu bar in the current window and runs a closure to construct the contents.

Note: the closure is not called if the menu bar is not visible.

Source

pub fn begin_menu(&self, label: impl AsRef<str>) -> Option<MenuToken<'_>>

Creates and starts appending to a sub-menu entry.

Returns Some(MenuToken) if the menu is visible. After content has been rendered, the token must be ended by calling .end().

Returns None if the menu is not visible and no content should be rendered.

This is the equivalent of begin_menu_with_enabled with enabled set to true.

Source

pub fn begin_menu_with_enabled( &self, label: impl AsRef<str>, enabled: bool, ) -> Option<MenuToken<'_>>

Creates and starts appending to a sub-menu entry.

Returns Some(MenuToken) if the menu is visible. After content has been rendered, the token must be ended by calling .end().

Returns None if the menu is not visible and no content should be rendered.

Source

pub fn menu<F: FnOnce()>(&self, label: impl AsRef<str>, f: F)

Creates a menu and runs a closure to construct the contents.

Note: the closure is not called if the menu is not visible.

This is the equivalent of menu_with_enabled with enabled set to true.

Source

pub fn menu_with_enabled<F: FnOnce()>( &self, label: impl AsRef<str>, enabled: bool, f: F, )

Creates a menu and runs a closure to construct the contents.

Note: the closure is not called if the menu is not visible.

Source

pub fn menu_item(&self, label: impl AsRef<str>) -> bool

Creates a menu item with the given label, returning true if it was pressed.

If you want to configure this menu_item by setting selection, or enablement, use menu_item_config.

Note: a menu_item is the actual button/selectable within a Menu.

Source

pub fn menu_item_config<L: AsRef<str>>(&self, label: L) -> MenuItem<'_, L>

Creates a menu item builder, with further methods on it as needed. Use menu_item for simple Menu Items with no features on them.

Note: a menu_item is the actual button/selectable within a Menu.

Source§

impl Ui

§Widgets: Miscellaneous

Source

pub fn button(&self, label: impl AsRef<str>) -> bool

Renders a clickable button.

Returns true if this button was clicked.

This is the equivalent of button_with_size with size set to [0.0, 0.0], which will size the button to the label’s width in the current style.

Source

pub fn button_with_size( &self, label: impl AsRef<str>, size: impl Into<Vector2<f32>>, ) -> bool

Renders a clickable button.

Returns true if this button was clicked.

Setting size as [0.0, 0.0] will size the button to the label’s width in the current style.

Source

pub fn small_button(&self, label: impl AsRef<str>) -> bool

Renders a small clickable button that is easy to embed in text.

Returns true if this button was clicked.

Source

pub fn invisible_button( &self, id: impl AsRef<str>, size: impl Into<Vector2<f32>>, ) -> bool

Renders a widget with button behaviour without the visual look.

Returns true if this button was clicked.

Source

pub fn invisible_button_flags( &self, id: impl AsRef<str>, size: impl Into<Vector2<f32>>, flags: ButtonFlags, ) -> bool

Renders a widget with button behaviour without the visual look.

Returns true if this button was clicked.

Source

pub fn arrow_button(&self, id: impl AsRef<str>, direction: Direction) -> bool

Renders a square button with an arrow shape.

Returns true if this button was clicked.

Source

pub fn checkbox(&self, label: impl AsRef<str>, value: &mut bool) -> bool

Renders a simple checkbox.

Returns true if this checkbox was clicked.

Source

pub fn checkbox_flags<T>( &self, label: impl AsRef<str>, flags: &mut T, mask: T, ) -> bool
where T: Copy + PartialEq + BitOrAssign + BitAndAssign + BitAnd<Output = T> + Not<Output = T>,

Renders a checkbox suitable for toggling bit flags using a mask.

Returns true if this checkbox was clicked.

Source

pub fn radio_button_bool(&self, label: impl AsRef<str>, active: bool) -> bool

Renders a simple radio button.

Returns true if this radio button was clicked.

Source

pub fn radio_button<T>( &self, label: impl AsRef<str>, value: &mut T, button_value: T, ) -> bool
where T: Copy + PartialEq,

Renders a radio button suitable for choosing an arbitrary value.

Returns true if this radio button was clicked.

Source

pub fn bullet(&self)

Renders a small circle and keeps the cursor on the same line

Source§

impl Ui

Source

pub fn selectable<T: AsRef<str>>(&self, label: T) -> bool

Constructs a new simple selectable.

Use selectable_config for a builder with additional options.

Source

pub fn selectable_config<T: AsRef<str>>(&self, label: T) -> Selectable<'_, T>

Constructs a new selectable builder.

Source§

impl Ui

Source

pub fn slider<T: AsRef<str>, K: DataTypeKind>( &self, label: T, min: K, max: K, value: &mut K, ) -> bool

Creates a new slider widget. Returns true if the value has been edited.

Source

pub fn slider_config<T: AsRef<str>, K: DataTypeKind>( &self, label: T, min: K, max: K, ) -> Slider<'_, T, K>

Creates an new ubuilt Slider.

Source§

impl Ui

Source

pub fn tab_bar(&self, id: impl AsRef<str>) -> Option<TabBarToken<'_>>

Creates a tab bar and returns a tab bar token, allowing you to append Tab items afterwards. This passes no flags. To pass flags explicitly, use tab_bar_with_flags.

Source

pub fn tab_bar_with_flags( &self, id: impl AsRef<str>, flags: TabBarFlags, ) -> Option<TabBarToken<'_>>

Creates a tab bar and returns a tab bar token, allowing you to append Tab items afterwards.

Source

pub fn tab_item(&self, label: impl AsRef<str>) -> Option<TabItemToken<'_>>

Creates a new tab item and returns a token if its contents are visible.

By default, this doesn’t pass an opened bool nor any flags. See tab_item_with_opened and tab_item_with_flags for more.

Source

pub fn tab_item_with_opened( &self, label: impl AsRef<str>, opened: &mut bool, ) -> Option<TabItemToken<'_>>

Creates a new tab item and returns a token if its contents are visible.

By default, this doesn’t pass any flags. See [tab_item_with_flags] for more.

Source

pub fn tab_item_with_flags( &self, label: impl AsRef<str>, opened: Option<&mut bool>, flags: TabItemFlags, ) -> Option<TabItemToken<'_>>

Creates a new tab item and returns a token if its contents are visible.

Source§

impl Ui

§Widgets: Text

Source

pub fn text<T: AsRef<str>>(&self, text: T)

Renders simple text

Source

pub fn text_colored<T: AsRef<str>>( &self, color: impl Into<Vector4<f32>>, text: T, )

Renders simple text using the given text color

Source

pub fn text_disabled<T: AsRef<str>>(&self, text: T)

Renders simple text using StyleColor::TextDisabled color

Source

pub fn text_wrapped(&self, text: impl AsRef<str>)

Renders text wrapped to the end of window (or column)

Source

pub fn label_text(&self, label: impl AsRef<str>, text: impl AsRef<str>)

Render a text + label combination aligned the same way as value+label widgets

Source

pub fn bullet_text(&self, text: impl AsRef<str>)

Renders text with a little bullet aligned to the typical tree node

Source§

impl Ui

Source

pub fn tree_node<I, T>(&self, id: I) -> Option<TreeNodeToken<'_>>
where I: Into<TreeNodeId<T>>, T: AsRef<str>,

Constructs a new tree node with just a name, and pushes it.

Use tree_node_config to access a builder to put additional configurations on the tree node.

Source

pub fn tree_node_config<I, T>(&self, id: I) -> TreeNode<'_, T>
where I: Into<TreeNodeId<T>>, T: AsRef<str>,

Constructs a new tree node builder.

Use tree_node to build a simple node with just a name.

Source§

impl Ui

Source

pub fn collapsing_header( &self, label: impl AsRef<str>, flags: TreeNodeFlags, ) -> bool

Constructs a new collapsing header

Source

pub fn collapsing_header_with_close_button( &self, label: impl AsRef<str>, flags: TreeNodeFlags, opened: &mut bool, ) -> bool

Constructs a new collapsing header

Source§

impl Ui

§Content region

Source

pub fn content_region_max(&self) -> [f32; 2]

Returns the current content boundaries (in window coordinates)

Source

pub fn content_region_avail(&self) -> [f32; 2]

Equal to ui.content_region_max() - ui.cursor_pos()

Source

pub fn window_content_region_min(&self) -> [f32; 2]

Content boundaries min (in window coordinates).

Roughly equal to [0.0, 0.0] - scroll.

Source

pub fn window_content_region_max(&self) -> [f32; 2]

Content boundaries max (in window coordinates).

Roughly equal to [0.0, 0.0] + size - scroll.

Source

pub fn window_content_region_width(&self) -> f32

👎Deprecated since 0.9.0: Removed in Dear ImGui 1.85, ‘not very useful in practice’ and can be done with window_content_region_min/_max
Source§

impl Ui

§Window scrolling

Source

pub fn scroll_x(&self) -> f32

Returns the horizontal scrolling position.

Value is between 0.0 and self.scroll_max_x().

Source

pub fn scroll_y(&self) -> f32

Returns the vertical scrolling position.

Value is between 0.0 and self.scroll_max_y().

Source

pub fn scroll_max_x(&self) -> f32

Returns the maximum horizontal scrolling position.

Roughly equal to content size X - window size X.

Source

pub fn scroll_max_y(&self) -> f32

Returns the maximum vertical scrolling position.

Roughly equal to content size Y - window size Y.

Source

pub fn set_scroll_x(&self, scroll_x: f32)

Sets the horizontal scrolling position

Source

pub fn set_scroll_y(&self, scroll_y: f32)

Sets the vertical scroll position

Source

pub fn set_scroll_here_x(&self)

Adjusts the horizontal scroll position to make the current cursor position visible.

This is the same as set_scroll_here_x_with_ratio but with ratio at 0.5.

Source

pub fn set_scroll_here_x_with_ratio(&self, center_x_ratio: f32)

Adjusts the horizontal scroll position to make the current cursor position visible.

center_x_ratio:

  • 0.0: left
  • 0.5: center
  • 1.0: right
Source

pub fn set_scroll_here_y(&self)

Adjusts the vertical scroll position to make the current cursor position visible

This is the same as set_scroll_here_y_with_ratio but with ratio at 0.5.

Source

pub fn set_scroll_here_y_with_ratio(&self, center_y_ratio: f32)

Adjusts the vertical scroll position to make the current cursor position visible.

center_y_ratio:

  • 0.0: top
  • 0.5: center
  • 1.0: bottom
Source

pub fn set_scroll_from_pos_x(&self, local_x: f32)

Adjusts the horizontal scroll position to make the given position visible

This is the same as set_scroll_from_pos_x_with_ratio but with ratio at 0.5.

Source

pub fn set_scroll_from_pos_x_with_ratio( &self, local_x: f32, center_x_ratio: f32, )

Adjusts the horizontal scroll position to make the given position visible.

center_x_ratio:

  • 0.0: left
  • 0.5: center
  • 1.0: right
Source

pub fn set_scroll_from_pos_y(&self, local_y: f32)

Adjusts the vertical scroll position to make the given position visible

This is the same as set_scroll_from_pos_y_with_ratio but with ratio at 0.5.

Source

pub fn set_scroll_from_pos_y_with_ratio( &self, local_y: f32, center_y_ratio: f32, )

Adjusts the vertical scroll position to make the given position visible.

center_y_ratio:

  • 0.0: top
  • 0.5: center
  • 1.0: bottom
Source§

impl Ui

§Window utilities

Source

pub fn is_window_appearing(&self) -> bool

Returns true if the current window appeared during this frame

Source

pub fn is_window_collapsed(&self) -> bool

Returns true if the current window is in collapsed state (= only the title bar is visible)

Source

pub fn is_window_focused(&self) -> bool

Returns true if the current window is focused

Source

pub fn is_window_focused_with_flags(&self, flags: WindowFocusedFlags) -> bool

Returns true if the current window is focused based on the given flags

Source

pub fn is_window_hovered(&self) -> bool

Returns true if the current window is hovered

Source

pub fn is_window_hovered_with_flags(&self, flags: WindowHoveredFlags) -> bool

Returns true if the current window is hovered based on the given flags

Source

pub fn window_pos(&self) -> [f32; 2]

Returns the position of the current window (in screen space)

Source

pub fn window_size(&self) -> [f32; 2]

Returns the size of the current window

Source§

impl Ui

Source

pub unsafe fn scratch_buffer(&self) -> &UnsafeCell<UiBuffer>

This provides access to the backing scratch buffer that we use to write strings, along with null-terminators, before we pass normal Rust strs to Dear ImGui.

This is given as a get-out-of-jail free card if you need to handle the buffer, or, for example, resize it for some reason. Generally, you should never need this.

§Safety

This uses a static mut and we assume it will never be passed between threads. Do not pass the raw pointer you get between threads at all – Dear ImGui is single-threaded. We otherwise make no assumptions about the size or keep state in this buffer between calls, so editing the UiBuffer is fine.

Source

pub fn io(&self) -> &Io

Returns an immutable reference to the inputs/outputs object

Source

pub fn fonts(&self) -> &FontAtlas

Returns an immutable reference to the font atlas.

Source

pub fn clone_style(&self) -> Style

Returns a clone of the user interface style

Source

pub fn render(&mut self)

👎Deprecated since 0.9.0: use Context::render to render frames, or end_frame_early to not render at all

This function, and the library’s api, has been changed as of 0.9! Do not use this function! Instead, use Context::render, which does what this function in 0.8 used to do.

This function right now simply ends the current frame, but does not return draw data. If you want to end the frame without generated draw data, and thus save some CPU time, use end_frame_early.

Source

pub fn end_frame_early(&mut self)

Use this function to end the frame early. After this call, you should stop using the Ui object till new_frame has been called.

You probably don’t want this function. If you want to render your data, use Context::render now.

Source§

impl Ui

§Demo, debug, information

Source

pub fn show_demo_window(&self, opened: &mut bool)

Renders a demo window (previously called a test window), which demonstrates most Dear Imgui features.

Source

pub fn show_about_window(&self, opened: &mut bool)

Renders an about window.

Displays the Dear ImGui version/credits, and build/system information.

Source

pub fn show_metrics_window(&self, opened: &mut bool)

Renders a metrics/debug window.

Displays Dear ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc.

Source

pub fn show_style_editor(&self, style: &mut Style)

Renders a style editor block (not a window) for the given Style structure

Source

pub fn show_default_style_editor(&self)

Renders a style editor block (not a window) for the currently active style

Source

pub fn show_user_guide(&self)

Renders a basic help/info block (not a window)

Source§

impl Ui

Source

pub fn new_id(&self, input: usize) -> Id

Create new Id from a usize. See Id for details.

Source

pub fn new_id_int(&self, input: i32) -> Id

Create Id from i32

Source

pub fn new_id_ptr<T>(&self, input: &T) -> Id

Create Id from a pointer

Source

pub fn new_id_str(&self, s: impl AsRef<str>) -> Id

Create Id from string

Source§

impl Ui

Source

pub fn window<Label: AsRef<str>>(&self, name: Label) -> Window<'_, '_, Label>

§Windows

Start constructing a window.

This, like many objects in the library, uses the builder pattern to set optional arguments (like window size, flags, etc). Once all desired options are set, you must call either Window::build or Window::begin to actually create the window.

§Examples

Create a window using the closure based Window::build:

ui.window("Example Window")
    .size([100.0, 50.0], imgui::Condition::FirstUseEver)
    .build(|| {
        ui.text("An example");
    });

Same as Ui::window but using the “token based” .begin() approach.

if let Some(wt) = ui
    .window("Example Window")
    .size([100.0, 50.0], imgui::Condition::FirstUseEver)
    .begin()
{
    ui.text("Window is visible");
    // Window ends where where wt is dropped,
    // or you could call
    // if you want to let it drop on its own, name it `_wt`.
    // never name it `_`, as this will drop it *immediately*.
    wt.end();
};
Source

pub fn child_window<Label: AsRef<str>>(&self, name: Label) -> ChildWindow<'_>

Begins constructing a child window with the given name.

Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window. Child windows can embed their own child.

Source

pub fn child_window_id(&self, id: Id) -> ChildWindow<'_>

Begins constructing a child window with the given name.

Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window. Child windows can embed their own child.

Source§

impl<'ui> Ui

Source

pub fn input_text<'p, L: AsRef<str>>( &'ui self, label: L, buf: &'p mut String, ) -> InputText<'ui, 'p, L>

§Widgets: Input

Edits text in a single line input widget

Source

pub fn input_text_multiline<'p, L: AsRef<str>>( &'ui self, label: L, buf: &'p mut String, size: [f32; 2], ) -> InputTextMultiline<'ui, 'p, L>

Edits text in a multi line widget. Similar to Self::input_text but requires specifying a size. Self::content_region_avail can be useful to make this take up all avaialble space

Source

pub fn input_float<'p, L: AsRef<str>>( &'ui self, label: L, value: &'p mut f32, ) -> InputScalar<'ui, 'p, f32, L>

Simple floating point number widget

Source

pub fn input_float2<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputFloat2<'ui, 'p, L, T>
where L: AsRef<str>, T: Copy + Into<Vector2<f32>>, Vector2<f32>: Into<T> + Into<[f32; 2]>,

Widget to edit two floats

Source

pub fn input_float3<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputFloat3<'ui, 'p, L, T>
where L: AsRef<str>, T: Copy + Into<Vector3<f32>>, Vector3<f32>: Into<T> + Into<[f32; 3]>,

Widget to edit 3 floats

Source

pub fn input_float4<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputFloat4<'ui, 'p, L, T>
where L: AsRef<str>, T: Copy + Into<Vector4<f32>>, Vector4<f32>: Into<T> + Into<[f32; 4]>,

Widget to edit 4 floats

Source

pub fn input_int<'p, L: AsRef<str>>( &'ui self, label: L, value: &'p mut i32, ) -> InputScalar<'ui, 'p, i32, L>

Shortcut for Ui::input_scalar

Source

pub fn input_int2<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputInt2<'ui, 'p, L, T>
where L: AsRef<str>, T: Copy + Into<Vector2<i32>>, Vector2<i32>: Into<T> + Into<[i32; 2]>,

Shortcut for Ui::input_scalar

Source

pub fn input_int3<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputInt3<'ui, 'p, L, T>
where L: AsRef<str>, T: Copy + Into<Vector3<i32>>, Vector3<i32>: Into<T> + Into<[i32; 3]>,

Shortcut for Ui::input_scalar

Source

pub fn input_int4<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputInt4<'ui, 'p, L, T>
where L: AsRef<str>, T: Copy + Into<Vector4<i32>>, Vector4<i32>: Into<T> + Into<[i32; 4]>,

Shortcut for Ui::input_scalar

Source

pub fn input_scalar<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputScalar<'ui, 'p, T, L>
where L: AsRef<str>, T: DataTypeKind,

Shows an input field for a scalar value. This is not limited to f32 and i32 and can be used with any primitive scalar type e.g. u8 and f64.

Source

pub fn input_scalar_n<'p, L, T>( &'ui self, label: L, values: &'p mut [T], ) -> InputScalarN<'ui, 'p, T, L>
where L: AsRef<str>, T: DataTypeKind,

Shows a horizontal array of scalar value input fields. See input_scalar.

Source§

impl Ui

§Tooltips

Source

pub fn tooltip<F: FnOnce()>(&self, f: F)

Construct a tooltip window that can have any kind of content.

Typically used with Ui::is_item_hovered() or some other conditional check.

§Examples
fn user_interface(ui: &Ui) {
    ui.text("Hover over me");
    if ui.is_item_hovered() {
        ui.tooltip(|| {
            ui.text_colored([1.0, 0.0, 0.0, 1.0], "I'm red!");
        });
    }
}
Source

pub fn begin_tooltip(&self) -> TooltipToken<'_>

Construct a tooltip window that can have any kind of content.

Returns a TooltipToken that must be ended by calling .end()

Source

pub fn tooltip_text<T: AsRef<str>>(&self, text: T)

Shortcut to call Self::tooltip with simple text content.

§Examples
fn user_interface(ui: &Ui) {
    ui.text("Hover over me");
    if ui.is_item_hovered() {
        ui.tooltip_text("I'm a tooltip!");
    }
}
Source§

impl Ui

§Disabling widgets

imgui can disable widgets so they don’t react to mouse/keyboard inputs, and are displayed differently (currently dimmed by an amount set in Style::disabled_alpha)

Source

pub fn begin_disabled(&self, disabled: bool) -> DisabledToken<'_>

Creates a scope where interactions are disabled.

Scope ends when returned token is dropped, or .end() is explicitly called

§Examples
fn user_interface(ui: &Ui) {
    let disable_buttons = true;
    let _d = ui.begin_disabled(disable_buttons);
    ui.button("Dangerous button");
}
Source

pub fn begin_enabled(&self, enabled: bool) -> DisabledToken<'_>

Identical to Ui::begin_disabled but exists to allow avoiding a double-negative, for example begin_enabled(enable_buttons) instead of begin_disabled(!enable_buttons))

Source

pub fn disabled<F: FnOnce()>(&self, disabled: bool, f: F)

Helper to create a disabled section of widgets

§Examples
fn user_interface(ui: &Ui) {
    let safe_mode = true;
    ui.disabled(safe_mode, || {
        ui.button("Dangerous button");
    });
}
Source

pub fn enabled<F: FnOnce()>(&self, enabled: bool, f: F)

Same as Ui::disabled but with logic reversed. See Ui::begin_enabled.

Source§

impl Ui

Source

pub fn list_box<'p, StringType: AsRef<str> + ?Sized>( &self, label: impl AsRef<str>, current_item: &mut i32, items: &'p [&'p StringType], height_in_items: i32, ) -> bool

Source§

impl<'ui> Ui

Source

pub fn plot_lines<'p, Label: AsRef<str>>( &'ui self, label: Label, values: &'p [f32], ) -> PlotLines<'ui, 'p, Label>

Plot a list of floats as a “sparkline” style plot

Source

pub fn plot_histogram<'p, Label: AsRef<str>>( &'ui self, label: Label, values: &'p [f32], ) -> PlotHistogram<'ui, 'p, Label>

Plot a list of floats as a histogram

Source

pub fn calc_text_size<T: AsRef<str>>(&self, text: T) -> [f32; 2]

Calculate the size required for a given text string.

This is the same as calc_text_size_with_opts with hide_text_after_double_hash set to false and wrap_width set to -1.0.

Source

pub fn calc_text_size_with_opts<T: AsRef<str>>( &self, text: T, hide_text_after_double_hash: bool, wrap_width: f32, ) -> [f32; 2]

Calculate the size required for a given text string.

hide_text_after_double_hash allows the user to insert comments into their text, using a double hash-tag prefix. This is a feature of imgui.

wrap_width allows you to request a width at which to wrap the text to a newline for the calculation.

Source§

impl Ui

§Draw list for custom drawing

Source

pub fn get_window_draw_list(&self) -> DrawListMut<'_>

Get access to drawing API.

The window draw list draws within the current window. Coordinates are within the current window coordinates, so [0.0, 0.0] would be at beginning of window

§Examples
fn custom_draw(ui: &Ui) {
    let draw_list = ui.get_window_draw_list();
    // Draw a line
    const WHITE: [f32; 3] = [1.0, 1.0, 1.0];
    draw_list.add_line([100.0, 100.0], [200.0, 200.0], WHITE).build();
    // Continue drawing ...
}

This function will panic if several instances of DrawListMut coexist. Before a new instance is got, a previous instance should be dropped.

fn custom_draw(ui: &Ui) {
    let draw_list = ui.get_window_draw_list();
    // Draw something...

    // This second call will panic!
    let draw_list = ui.get_window_draw_list();
}
Source

pub fn get_background_draw_list(&self) -> DrawListMut<'_>

Get draw list to draw behind all windows

Coordinates are in window coordinates, so [0.0, 0.0] is at top left of the Dear ImGui window

See Self::get_window_draw_list for more details

Source

pub fn get_foreground_draw_list(&self) -> DrawListMut<'_>

Get draw list instance to draw above all window content

Coordinates are in window coordinates, so [0.0, 0.0] is at top left of the Dear ImGui window

See Self::get_window_draw_list for more details

Trait Implementations§

Source§

impl Debug for Ui

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Ui

§

impl !RefUnwindSafe for Ui

§

impl Send for Ui

§

impl !Sync for Ui

§

impl Unpin for Ui

§

impl UnwindSafe for Ui

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.