pub struct Ui { /* private fields */ }
Expand description
A reference for building the user interface for one frame
Implementations§
Source§impl Ui
§Clipboard
impl Ui
§Clipboard
Sourcepub fn clipboard_text(&self) -> Option<String>
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
Sourcepub fn set_clipboard_text(&self, text: impl AsRef<str>)
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
impl Ui
§Columns
pub fn columns(&self, count: i32, id: impl AsRef<str>, border: bool)
Sourcepub fn next_column(&self)
pub fn next_column(&self)
Switches to the next column.
If the current row is finished, switches to first column of the next row
Sourcepub fn current_column_index(&self) -> i32
pub fn current_column_index(&self) -> i32
Returns the index of the current column
Sourcepub fn current_column_width(&self) -> f32
pub fn current_column_width(&self) -> f32
Returns the width of the current column (in pixels)
Sourcepub fn column_width(&self, column_index: i32) -> f32
pub fn column_width(&self, column_index: i32) -> f32
Returns the width of the given column (in pixels)
Sourcepub fn set_current_column_width(&self, width: f32)
pub fn set_current_column_width(&self, width: f32)
Sets the width of the current column (in pixels)
Sourcepub fn set_column_width(&self, column_index: i32, width: f32)
pub fn set_column_width(&self, column_index: i32, width: f32)
Sets the width of the given column (in pixels)
Sourcepub fn current_column_offset(&self) -> f32
pub fn current_column_offset(&self) -> f32
Returns the offset of the current column (in pixels from the left side of the content region)
Sourcepub fn column_offset(&self, column_index: i32) -> f32
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)
Sourcepub fn set_current_column_offset(&self, offset_x: f32)
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)
Sourcepub fn set_column_offset(&self, column_index: i32, offset_x: f32)
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)
Sourcepub fn column_count(&self) -> i32
pub fn column_count(&self) -> i32
Returns the current amount of columns
Source§impl Ui
impl Ui
pub fn dockspace_over_main_viewport(&self)
Source§impl Ui
impl Ui
Sourcepub fn drag_drop_source_config<T: AsRef<str>>(
&self,
name: T,
) -> DragDropSource<'_, T>
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
impl Ui
Sourcepub fn drag_drop_target(&self) -> Option<DragDropTarget<'_>>
pub fn drag_drop_target(&self) -> Option<DragDropTarget<'_>>
Creates a new DragDropTarget, which gives methods for handling accepting payloads.
Source§impl Ui
§Fonts
impl Ui
§Fonts
Sourcepub fn current_font(&self) -> &Font
pub fn current_font(&self) -> &Font
Returns the current font
Sourcepub fn current_font_size(&self) -> f32
pub fn current_font_size(&self) -> f32
Returns the current font size (= height in pixels) with font scale applied
Sourcepub fn font_tex_uv_white_pixel(&self) -> [f32; 2]
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.
Sourcepub fn set_window_font_scale(&self, scale: f32)
pub fn set_window_font_scale(&self, scale: f32)
Sets the font scale of the current window
Source§impl Ui
§Input: Keyboard
impl Ui
§Input: Keyboard
Sourcepub fn is_key_down(&self, key: Key) -> bool
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]
Sourcepub fn is_key_index_down(&self, key_index: u32) -> bool
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.
Sourcepub fn is_key_pressed(&self, key: Key) -> bool
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
)
Sourcepub fn is_key_index_pressed(&self, key_index: u32) -> bool
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.
Sourcepub fn is_key_pressed_no_repeat(&self, key: Key) -> bool
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
)
Sourcepub fn is_key_index_pressed_no_repeat(&self, key_index: u32) -> bool
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.
Sourcepub fn is_key_released(&self, key: Key) -> bool
pub fn is_key_released(&self, key: Key) -> bool
Returns true if the key was released (went from down to !down)
Sourcepub fn is_key_index_released(&self, key_index: u32) -> bool
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.
Sourcepub fn key_pressed_amount(&self, key: Key, repeat_delay: f32, rate: f32) -> u32
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
.
Sourcepub fn key_index_pressed_amount(
&self,
key_index: u32,
repeat_delay: f32,
rate: f32,
) -> u32
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.
Sourcepub fn set_keyboard_focus_here(&self)
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
.
Sourcepub fn set_keyboard_focus_here_with_offset(&self, target_widget: FocusedWidget)
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
impl Ui
§Input: Mouse
Sourcepub fn is_mouse_down(&self, button: MouseButton) -> bool
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]
.
Sourcepub fn is_any_mouse_down(&self) -> bool
pub fn is_any_mouse_down(&self) -> bool
Returns true if any mouse button is held down
Sourcepub fn is_mouse_clicked(&self, button: MouseButton) -> bool
pub fn is_mouse_clicked(&self, button: MouseButton) -> bool
Returns true if the given mouse button was clicked (went from !down to down)
Sourcepub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool
pub fn is_mouse_double_clicked(&self, button: MouseButton) -> bool
Returns true if the given mouse button was double-clicked
Sourcepub fn is_mouse_released(&self, button: MouseButton) -> bool
pub fn is_mouse_released(&self, button: MouseButton) -> bool
Returns true if the given mouse button was released (went from down to !down)
Sourcepub fn is_mouse_dragging(&self, button: MouseButton) -> bool
pub fn is_mouse_dragging(&self, button: MouseButton) -> bool
Returns true if the mouse is currently dragging with the given mouse button held down
Sourcepub fn is_mouse_dragging_with_threshold(
&self,
button: MouseButton,
threshold: f32,
) -> bool
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
).
Sourcepub fn is_mouse_hovering_rect(
&self,
r_min: impl Into<Vector2<f32>>,
r_max: impl Into<Vector2<f32>>,
) -> bool
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.
Sourcepub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2]
pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2]
Returns the mouse position backed up at the time of opening a popup
Sourcepub fn mouse_drag_delta(&self) -> [f32; 2]
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
.
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
.
Sourcepub fn mouse_drag_delta_with_threshold(
&self,
button: MouseButton,
threshold: f32,
) -> [f32; 2]
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
).
Sourcepub fn reset_mouse_drag_delta(&self, button: MouseButton)
pub fn reset_mouse_drag_delta(&self, button: MouseButton)
Resets the current delta from initial clicking position.
Sourcepub fn mouse_cursor(&self) -> Option<MouseCursor>
pub fn mouse_cursor(&self) -> Option<MouseCursor>
Returns the currently desired mouse cursor type.
Returns None
if no cursor should be displayed
Sourcepub fn set_mouse_cursor(&self, cursor_type: Option<MouseCursor>)
pub fn set_mouse_cursor(&self, cursor_type: Option<MouseCursor>)
Sets the desired mouse cursor type.
Passing None
hides the mouse cursor.
pub fn is_current_mouse_pos_valid(&self) -> bool
pub fn is_mouse_pos_valid(&self, mouse_pos: impl Into<Vector2<f32>>) -> bool
Source§impl Ui
§Cursor / Layout
impl Ui
§Cursor / Layout
Sourcepub fn separator(&self)
pub fn separator(&self)
Renders a separator (generally horizontal).
This becomes a vertical separator inside a menu bar or in horizontal layout mode.
Sourcepub fn same_line(&self)
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
.
Sourcepub fn same_line_with_pos(&self, pos_x: f32)
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.
Sourcepub fn same_line_with_spacing(&self, pos_x: f32, spacing_w: f32)
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.
Sourcepub fn new_line(&self)
pub fn new_line(&self)
Undo a same_line
call or force a new line when in horizontal layout mode
Sourcepub fn dummy(&self, size: impl Into<Vector2<f32>>)
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.
Sourcepub fn indent(&self)
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
.
Sourcepub fn unindent(&self)
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
.
Sourcepub fn unindent_by(&self, width: f32)
pub fn unindent_by(&self, width: f32)
Moves content position to the left by width
Sourcepub fn begin_group(&self) -> GroupToken<'_>
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()
Sourcepub fn group<R, F: FnOnce() -> R>(&self, f: F) -> R
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.
Sourcepub fn cursor_pos(&self) -> [f32; 2]
pub fn cursor_pos(&self) -> [f32; 2]
Returns the cursor position (in window coordinates)
Sourcepub fn set_cursor_pos(&self, pos: impl Into<Vector2<f32>>)
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.
Sourcepub fn cursor_start_pos(&self) -> [f32; 2]
pub fn cursor_start_pos(&self) -> [f32; 2]
Returns the initial cursor position (in window coordinates)
Sourcepub fn cursor_screen_pos(&self) -> [f32; 2]
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.
Sourcepub fn set_cursor_screen_pos(&self, pos: impl Into<Vector2<f32>>)
pub fn set_cursor_screen_pos(&self, pos: impl Into<Vector2<f32>>)
Sets the cursor position (in absolute screen coordinates)
Sourcepub fn align_text_to_frame_padding(&self)
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.
pub fn text_line_height(&self) -> f32
pub fn text_line_height_with_spacing(&self) -> f32
pub fn frame_height(&self) -> f32
pub fn frame_height_with_spacing(&self) -> f32
Source§impl Ui
impl Ui
Sourcepub fn open_popup(&self, str_id: impl AsRef<str>)
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.
Sourcepub fn begin_popup(&self, str_id: impl AsRef<str>) -> Option<PopupToken<'_>>
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.
Sourcepub fn popup<F>(&self, str_id: impl AsRef<str>, f: F)where
F: FnOnce(),
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.
Sourcepub fn modal_popup<Label, Func, R>(&self, str_id: Label, f: Func) -> Option<R>
pub fn modal_popup<Label, Func, R>(&self, str_id: Label, f: Func) -> Option<R>
Creates a PopupModal, and runs a closure on it.
To customize the behavior of this PopupModal, use modal_popup_config
.
Sourcepub fn begin_modal_popup<Label: AsRef<str>>(
&self,
str_id: Label,
) -> Option<PopupToken<'_>>
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
.
Sourcepub fn modal_popup_config<Label: AsRef<str>>(
&self,
str_id: Label,
) -> PopupModal<'_, '_, Label>
pub fn modal_popup_config<Label: AsRef<str>>( &self, str_id: Label, ) -> PopupModal<'_, '_, Label>
Creates a PopupModal builder.
Sourcepub fn close_current_popup(&self)
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
.
Sourcepub fn begin_popup_context_item(&self) -> Option<PopupToken<'_>>
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.
Sourcepub fn begin_popup_context_with_label<Label: AsRef<str>>(
&self,
str_id: Label,
) -> Option<PopupToken<'_>>
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.
Sourcepub fn begin_popup_context_window(&self) -> Option<PopupToken<'_>>
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.
Sourcepub fn begin_popup_context_window_with_label<Label: AsRef<str>>(
&self,
str_id: Label,
) -> Option<PopupToken<'_>>
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.
Sourcepub fn begin_popup_context_void(&self) -> Option<PopupToken<'_>>
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.
Sourcepub fn begin_popup_context_void_with_label<Label: AsRef<str>>(
&self,
str_id: Label,
) -> Option<PopupToken<'_>>
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)
impl Ui
§Parameter stacks (shared)
Sourcepub fn push_font(&self, id: FontId) -> FontStackToken<'_>
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();
Sourcepub fn push_style_color(
&self,
style_color: StyleColor,
color: impl Into<Vector4<f32>>,
) -> ColorStackToken<'_>
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();
Sourcepub fn push_style_var(&self, style_var: StyleVar) -> StyleStackToken<'_>
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)
impl Ui
§Parameter stacks (current window)
Sourcepub fn push_item_width(&self, item_width: f32) -> ItemWidthStackToken<'_>
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 isitem_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)
Sourcepub fn set_next_item_width(&self, item_width: f32)
pub fn set_next_item_width(&self, item_width: f32)
Sets the width of the next item.
> 0.0
: width isitem_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)
Sourcepub fn calc_item_width(&self) -> f32
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.
Sourcepub fn push_text_wrap_pos(&self) -> TextWrapPosStackToken<'_>
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.
Sourcepub fn push_text_wrap_pos_with_pos(
&self,
wrap_pos_x: f32,
) -> TextWrapPosStackToken<'_>
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 atwrap_pos_x
position in window local space= 0.0
: wrap to end of window (or column)< 0.0
: no wrapping
Sourcepub fn push_allow_keyboard_focus(
&self,
allow: bool,
) -> PushAllowKeyboardFocusToken<'_>
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.
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.
Sourcepub fn push_item_flag(&self, item_flag: ItemFlag) -> ItemFlagsStackToken<'_>
👎Deprecated since 0.9.0: use push_allow_keyboard_focus
or push_button_repeat
instead
pub fn push_item_flag(&self, item_flag: ItemFlag) -> ItemFlagsStackToken<'_>
push_allow_keyboard_focus
or push_button_repeat
insteadChanges 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
impl Ui
§ID stack
Sourcepub fn push_id(&self, s: impl AsRef<str>) -> IdStackToken<'_>
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");
}
});
Sourcepub fn push_id_usize(&self, id: usize) -> IdStackToken<'_>
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.
Sourcepub fn push_id_int(&self, id: i32) -> IdStackToken<'_>
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.
Sourcepub fn push_id_ptr<T>(&self, value: &T) -> IdStackToken<'_>
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
impl Ui
Sourcepub fn begin_table(
&self,
str_id: impl AsRef<str>,
column_count: usize,
) -> Option<TableToken<'_>>
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.
Sourcepub fn begin_table_with_flags(
&self,
str_id: impl AsRef<str>,
column_count: usize,
flags: TableFlags,
) -> Option<TableToken<'_>>
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.
Sourcepub fn begin_table_with_sizing(
&self,
str_id: impl AsRef<str>,
column: usize,
flags: TableFlags,
outer_size: [f32; 2],
inner_width: f32,
) -> Option<TableToken<'_>>
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.
Sourcepub fn begin_table_header<Name: AsRef<str>, const N: usize>(
&self,
str_id: impl AsRef<str>,
column_data: [TableColumnSetup<Name>; N],
) -> Option<TableToken<'_>>
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.
Sourcepub 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<'_>>
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.
Sourcepub 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<'_>>
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.
Sourcepub fn table_next_row(&self)
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.
Sourcepub fn table_next_row_with_flags(&self, flags: TableRowFlags)
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.
Sourcepub fn table_next_row_with_height(
&self,
flags: TableRowFlags,
min_row_height: f32,
)
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.
Sourcepub fn table_next_column(&self) -> bool
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.
Sourcepub fn table_set_column_index(&self, column_index: usize) -> bool
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.
Sourcepub fn table_setup_column(&self, str_id: impl AsRef<str>)
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.
Sourcepub fn table_setup_column_with<N: AsRef<str>>(&self, data: TableColumnSetup<N>)
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.
Sourcepub fn table_setup_scroll_freeze(
&self,
locked_columns: usize,
locked_rows: usize,
)
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.
Sourcepub fn table_headers_row(&self)
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.
Sourcepub fn table_header(&self, label: impl AsRef<str>)
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.
Sourcepub fn table_column_count(&self) -> usize
pub fn table_column_count(&self) -> usize
Gets the numbers of columns in the current table.
Sourcepub fn table_column_index(&self) -> usize
pub fn table_column_index(&self) -> usize
Gets the current column index in the current table.
Sourcepub fn table_row_index(&self) -> usize
pub fn table_row_index(&self) -> usize
Gets the current row index in the current table.
Sourcepub fn table_column_name(&mut self) -> &str
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.
Sourcepub fn table_column_name_with_column(&mut self, column: usize) -> &str
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.
Sourcepub fn table_column_flags(&self) -> TableColumnFlags
pub fn table_column_flags(&self) -> TableColumnFlags
Gets the flags on the current column in the current table.
Sourcepub fn table_column_flags_with_column(
&self,
column_n: usize,
) -> TableColumnFlags
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.
Sourcepub fn table_set_bg_color(
&self,
target: TableBgTarget,
color: impl Into<ImColor32>,
)
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.
Sourcepub fn table_set_bg_color_with_column(
&self,
target: TableBgTarget,
color: impl Into<ImColor32>,
column_index: usize,
)
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.
Sourcepub fn table_set_enabled(&self, enabled: bool)
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.
Sourcepub fn table_set_enabled_with_column(&self, enabled: bool, column_idx: usize)
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.
Sourcepub fn table_sort_specs_mut(&self) -> Option<TableSortSpecsMut<'_>>
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
impl Ui
pub fn text_filter(label: String) -> TextFilter
pub fn text_filter_with_filter(label: String, filter: String) -> TextFilter
Source§impl Ui
§Item/widget utilities
impl Ui
§Item/widget utilities
Sourcepub fn is_item_hovered(&self) -> bool
pub fn is_item_hovered(&self) -> bool
Returns true
if the last item is hovered
Sourcepub fn is_item_hovered_with_flags(&self, flags: ItemHoveredFlags) -> bool
pub fn is_item_hovered_with_flags(&self, flags: ItemHoveredFlags) -> bool
Returns true
if the last item is hovered based on the given flags
Sourcepub fn is_item_active(&self) -> bool
pub fn is_item_active(&self) -> bool
Returns true
if the last item is active
Sourcepub fn is_item_focused(&self) -> bool
pub fn is_item_focused(&self) -> bool
Returns true
if the last item is focused for keyboard/gamepad navigation
Sourcepub fn is_item_clicked(&self) -> bool
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
.
Returns true
if the last item is being clicked
Sourcepub fn is_item_visible(&self) -> bool
pub fn is_item_visible(&self) -> bool
Returns true
if the last item is visible
Sourcepub fn is_item_edited(&self) -> bool
pub fn is_item_edited(&self) -> bool
Returns true
if the last item modified its underlying value this frame or was pressed
Sourcepub fn is_item_activated(&self) -> bool
pub fn is_item_activated(&self) -> bool
Returns true
if the last item was just made active
Sourcepub fn is_item_deactivated(&self) -> bool
pub fn is_item_deactivated(&self) -> bool
Returns true
if the last item was just made inactive
Sourcepub fn is_item_deactivated_after_edit(&self) -> bool
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
Sourcepub fn is_item_toggled_open(&self) -> bool
pub fn is_item_toggled_open(&self) -> bool
Returns true
if the last item open state was toggled
Sourcepub fn is_any_item_hovered(&self) -> bool
pub fn is_any_item_hovered(&self) -> bool
Returns true
if any item is hovered
Sourcepub fn is_any_item_active(&self) -> bool
pub fn is_any_item_active(&self) -> bool
Returns true
if any item is active
Sourcepub fn is_any_item_focused(&self) -> bool
pub fn is_any_item_focused(&self) -> bool
Returns true
if any item is focused
Sourcepub fn item_rect_min(&self) -> [f32; 2]
pub fn item_rect_min(&self) -> [f32; 2]
Returns the upper-left bounding rectangle of the last item (in screen coordinates)
Sourcepub fn item_rect_max(&self) -> [f32; 2]
pub fn item_rect_max(&self) -> [f32; 2]
Returns the lower-right bounding rectangle of the last item (in screen coordinates)
Sourcepub fn item_rect_size(&self) -> [f32; 2]
pub fn item_rect_size(&self) -> [f32; 2]
Returns the size of the last item
Sourcepub fn set_item_allow_overlap(&self)
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.
Sourcepub fn set_item_default_focus(&self)
pub fn set_item_default_focus(&self)
Makes the last item the default focused item of the window
Source§impl Ui
§Miscellaneous utilities
impl Ui
§Miscellaneous utilities
Sourcepub fn is_cursor_rect_visible(&self, size: impl Into<Vector2<f32>>) -> bool
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
Sourcepub fn is_rect_visible(
&self,
rect_min: impl Into<Vector2<f32>>,
rect_max: impl Into<Vector2<f32>>,
) -> bool
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
Sourcepub fn time(&self) -> f64
pub fn time(&self) -> f64
Returns the global imgui-rs time.
Incremented by Io::delta_time every frame.
Sourcepub fn frame_count(&self) -> i32
pub fn frame_count(&self) -> i32
Returns the global imgui-rs frame count.
Incremented by 1 every frame.
Sourcepub fn style_color(&self, style_color: StyleColor) -> [f32; 4]
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.
Sourcepub fn style_color_name(&self, style_color: StyleColor) -> &'static str
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.
Sourcepub unsafe fn style(&self) -> &Style
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
impl Ui
Sourcepub fn color_edit3<Label, C>(&self, label: Label, value: &mut C) -> bool
pub fn color_edit3<Label, C>(&self, label: Label, value: &mut C) -> bool
Edits a color of 3 channels. Use color_edit3_config for a builder to customize this widget.
Source§impl Ui
impl Ui
Sourcepub fn color_edit4<Label, C>(&self, label: Label, value: &mut C) -> bool
pub fn color_edit4<Label, C>(&self, label: Label, value: &mut C) -> bool
Edits a color of 4 channels. Use color_edit4_config for a builder to customize this widget.
Source§impl Ui
impl Ui
Sourcepub fn color_picker3<Label, C>(&self, label: Label, value: &mut C) -> bool
pub fn color_picker3<Label, C>(&self, label: Label, value: &mut C) -> bool
Edits a color of 3 channels. Use color_picker3 for a builder to customize this widget.
Source§impl Ui
impl Ui
Sourcepub fn color_picker4<Label, C>(&self, label: Label, value: &mut C) -> bool
pub fn color_picker4<Label, C>(&self, label: Label, value: &mut C) -> bool
Edits a color of 4 channels. Use color_picker4_config for a builder to customize this widget.
Source§impl Ui
impl Ui
Builds a ColorButton.
Returns true if this color button was clicked.
Returns a ColorButton builder.
Source§impl Ui
§Widgets: Color Editor/Picker
impl Ui
§Widgets: Color Editor/Picker
Sourcepub fn set_color_edit_options(&self, flags: ColorEditFlags)
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
impl Ui
§Convenience functions
Sourcepub fn begin_combo(
&self,
label: impl AsRef<str>,
preview_value: impl AsRef<str>,
) -> Option<ComboBoxToken<'_>>
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;
}
}
}
Sourcepub fn begin_combo_with_flags(
&self,
label: impl AsRef<str>,
preview_value: impl AsRef<str>,
flags: ComboBoxFlags,
) -> Option<ComboBoxToken<'_>>
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.
Sourcepub fn begin_combo_no_preview(
&self,
label: impl AsRef<str>,
) -> Option<ComboBoxToken<'_>>
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.
Sourcepub fn begin_combo_no_preview_with_flags(
&self,
label: impl AsRef<str>,
flags: ComboBoxFlags,
) -> Option<ComboBoxToken<'_>>
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.
Sourcepub fn combo<V, L>(
&self,
label: impl AsRef<str>,
current_item: &mut usize,
items: &[V],
label_fn: L,
) -> bool
pub fn combo<V, L>( &self, label: impl AsRef<str>, current_item: &mut usize, items: &[V], label_fn: L, ) -> bool
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
Sourcepub fn combo_simple_string(
&self,
label: impl AsRef<str>,
current_item: &mut usize,
items: &[impl AsRef<str>],
) -> bool
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
§Widgets: Menus
impl Ui
§Widgets: Menus
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.
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.
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.
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.
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
.
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.
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
.
Creates a menu and runs a closure to construct the contents.
Note: the closure is not called if the menu is not visible.
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.
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
impl Ui
§Widgets: Miscellaneous
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.
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.
Renders a small clickable button that is easy to embed in text.
Returns true if this button was clicked.
Renders a widget with button behaviour without the visual look.
Returns true if this button was clicked.
Renders a widget with button behaviour without the visual look.
Returns true if this button was clicked.
Renders a square button with an arrow shape.
Returns true if this button was clicked.
Sourcepub fn checkbox(&self, label: impl AsRef<str>, value: &mut bool) -> bool
pub fn checkbox(&self, label: impl AsRef<str>, value: &mut bool) -> bool
Renders a simple checkbox.
Returns true if this checkbox was clicked.
Sourcepub fn checkbox_flags<T>(
&self,
label: impl AsRef<str>,
flags: &mut T,
mask: T,
) -> bool
pub fn checkbox_flags<T>( &self, label: impl AsRef<str>, flags: &mut T, mask: T, ) -> bool
Renders a checkbox suitable for toggling bit flags using a mask.
Returns true if this checkbox was clicked.
Renders a simple radio button.
Returns true if this radio button was clicked.
Renders a radio button suitable for choosing an arbitrary value.
Returns true if this radio button was clicked.
Source§impl Ui
impl Ui
Sourcepub fn selectable<T: AsRef<str>>(&self, label: T) -> bool
pub fn selectable<T: AsRef<str>>(&self, label: T) -> bool
Constructs a new simple selectable.
Use selectable_config for a builder with additional options.
Sourcepub fn selectable_config<T: AsRef<str>>(&self, label: T) -> Selectable<'_, T>
pub fn selectable_config<T: AsRef<str>>(&self, label: T) -> Selectable<'_, T>
Constructs a new selectable builder.
Source§impl Ui
impl Ui
Sourcepub fn slider<T: AsRef<str>, K: DataTypeKind>(
&self,
label: T,
min: K,
max: K,
value: &mut K,
) -> bool
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.
Sourcepub fn slider_config<T: AsRef<str>, K: DataTypeKind>(
&self,
label: T,
min: K,
max: K,
) -> Slider<'_, T, K>
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
impl Ui
Sourcepub fn tab_bar(&self, id: impl AsRef<str>) -> Option<TabBarToken<'_>>
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.
Sourcepub fn tab_bar_with_flags(
&self,
id: impl AsRef<str>,
flags: TabBarFlags,
) -> Option<TabBarToken<'_>>
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.
Sourcepub fn tab_item(&self, label: impl AsRef<str>) -> Option<TabItemToken<'_>>
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.
Sourcepub fn tab_item_with_opened(
&self,
label: impl AsRef<str>,
opened: &mut bool,
) -> Option<TabItemToken<'_>>
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.
Sourcepub fn tab_item_with_flags(
&self,
label: impl AsRef<str>,
opened: Option<&mut bool>,
flags: TabItemFlags,
) -> Option<TabItemToken<'_>>
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
impl Ui
§Widgets: Text
Sourcepub fn text_colored<T: AsRef<str>>(
&self,
color: impl Into<Vector4<f32>>,
text: T,
)
pub fn text_colored<T: AsRef<str>>( &self, color: impl Into<Vector4<f32>>, text: T, )
Renders simple text using the given text color
Sourcepub fn text_disabled<T: AsRef<str>>(&self, text: T)
pub fn text_disabled<T: AsRef<str>>(&self, text: T)
Renders simple text using StyleColor::TextDisabled
color
Sourcepub fn text_wrapped(&self, text: impl AsRef<str>)
pub fn text_wrapped(&self, text: impl AsRef<str>)
Renders text wrapped to the end of window (or column)
Sourcepub fn label_text(&self, label: impl AsRef<str>, text: impl AsRef<str>)
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
Sourcepub fn bullet_text(&self, text: impl AsRef<str>)
pub fn bullet_text(&self, text: impl AsRef<str>)
Renders text with a little bullet aligned to the typical tree node
Source§impl Ui
impl Ui
Sourcepub fn tree_node<I, T>(&self, id: I) -> Option<TreeNodeToken<'_>>
pub fn tree_node<I, T>(&self, id: I) -> Option<TreeNodeToken<'_>>
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.
Sourcepub fn tree_node_config<I, T>(&self, id: I) -> TreeNode<'_, T>
pub fn tree_node_config<I, T>(&self, id: I) -> TreeNode<'_, T>
Constructs a new tree node builder.
Use tree_node to build a simple node with just a name.
Source§impl Ui
impl Ui
Sourcepub fn collapsing_header(
&self,
label: impl AsRef<str>,
flags: TreeNodeFlags,
) -> bool
pub fn collapsing_header( &self, label: impl AsRef<str>, flags: TreeNodeFlags, ) -> bool
Constructs a new collapsing header
Constructs a new collapsing header
Source§impl Ui
§Content region
impl Ui
§Content region
Sourcepub fn content_region_max(&self) -> [f32; 2]
pub fn content_region_max(&self) -> [f32; 2]
Returns the current content boundaries (in window coordinates)
Sourcepub fn content_region_avail(&self) -> [f32; 2]
pub fn content_region_avail(&self) -> [f32; 2]
Equal to ui.content_region_max()
- ui.cursor_pos()
Sourcepub fn window_content_region_min(&self) -> [f32; 2]
pub fn window_content_region_min(&self) -> [f32; 2]
Content boundaries min (in window coordinates).
Roughly equal to [0.0, 0.0] - scroll.
Sourcepub fn window_content_region_max(&self) -> [f32; 2]
pub fn window_content_region_max(&self) -> [f32; 2]
Content boundaries max (in window coordinates).
Roughly equal to [0.0, 0.0] + size - scroll.
pub fn window_content_region_width(&self) -> f32
Source§impl Ui
§Window scrolling
impl Ui
§Window scrolling
Sourcepub fn scroll_x(&self) -> f32
pub fn scroll_x(&self) -> f32
Returns the horizontal scrolling position.
Value is between 0.0 and self.scroll_max_x().
Sourcepub fn scroll_y(&self) -> f32
pub fn scroll_y(&self) -> f32
Returns the vertical scrolling position.
Value is between 0.0 and self.scroll_max_y().
Sourcepub fn scroll_max_x(&self) -> f32
pub fn scroll_max_x(&self) -> f32
Returns the maximum horizontal scrolling position.
Roughly equal to content size X - window size X.
Sourcepub fn scroll_max_y(&self) -> f32
pub fn scroll_max_y(&self) -> f32
Returns the maximum vertical scrolling position.
Roughly equal to content size Y - window size Y.
Sourcepub fn set_scroll_x(&self, scroll_x: f32)
pub fn set_scroll_x(&self, scroll_x: f32)
Sets the horizontal scrolling position
Sourcepub fn set_scroll_y(&self, scroll_y: f32)
pub fn set_scroll_y(&self, scroll_y: f32)
Sets the vertical scroll position
Sourcepub fn set_scroll_here_x(&self)
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.
Sourcepub fn set_scroll_here_x_with_ratio(&self, center_x_ratio: f32)
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
: left0.5
: center1.0
: right
Sourcepub fn set_scroll_here_y(&self)
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.
Sourcepub fn set_scroll_here_y_with_ratio(&self, center_y_ratio: f32)
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
: top0.5
: center1.0
: bottom
Sourcepub fn set_scroll_from_pos_x(&self, local_x: f32)
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.
Sourcepub fn set_scroll_from_pos_x_with_ratio(
&self,
local_x: f32,
center_x_ratio: f32,
)
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
: left0.5
: center1.0
: right
Sourcepub fn set_scroll_from_pos_y(&self, local_y: f32)
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.
Sourcepub fn set_scroll_from_pos_y_with_ratio(
&self,
local_y: f32,
center_y_ratio: f32,
)
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
: top0.5
: center1.0
: bottom
Source§impl Ui
§Window utilities
impl Ui
§Window utilities
Sourcepub fn is_window_appearing(&self) -> bool
pub fn is_window_appearing(&self) -> bool
Returns true if the current window appeared during this frame
Sourcepub fn is_window_collapsed(&self) -> bool
pub fn is_window_collapsed(&self) -> bool
Returns true if the current window is in collapsed state (= only the title bar is visible)
Sourcepub fn is_window_focused(&self) -> bool
pub fn is_window_focused(&self) -> bool
Returns true if the current window is focused
Sourcepub fn is_window_focused_with_flags(&self, flags: WindowFocusedFlags) -> bool
pub fn is_window_focused_with_flags(&self, flags: WindowFocusedFlags) -> bool
Returns true if the current window is focused based on the given flags
Sourcepub fn is_window_hovered(&self) -> bool
pub fn is_window_hovered(&self) -> bool
Returns true if the current window is hovered
Sourcepub fn is_window_hovered_with_flags(&self, flags: WindowHoveredFlags) -> bool
pub fn is_window_hovered_with_flags(&self, flags: WindowHoveredFlags) -> bool
Returns true if the current window is hovered based on the given flags
Sourcepub fn window_pos(&self) -> [f32; 2]
pub fn window_pos(&self) -> [f32; 2]
Returns the position of the current window (in screen space)
Sourcepub fn window_size(&self) -> [f32; 2]
pub fn window_size(&self) -> [f32; 2]
Returns the size of the current window
Source§impl Ui
impl Ui
Sourcepub unsafe fn scratch_buffer(&self) -> &UnsafeCell<UiBuffer>
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.
Sourcepub fn clone_style(&self) -> Style
pub fn clone_style(&self) -> Style
Returns a clone of the user interface style
Sourcepub fn render(&mut self)
👎Deprecated since 0.9.0: use Context::render
to render frames, or end_frame_early
to not render at all
pub fn render(&mut self)
Context::render
to render frames, or end_frame_early
to not render at allThis 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
.
Sourcepub fn end_frame_early(&mut self)
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
impl Ui
§Demo, debug, information
Sourcepub fn show_demo_window(&self, opened: &mut bool)
pub fn show_demo_window(&self, opened: &mut bool)
Renders a demo window (previously called a test window), which demonstrates most Dear Imgui features.
Sourcepub fn show_about_window(&self, opened: &mut bool)
pub fn show_about_window(&self, opened: &mut bool)
Renders an about window.
Displays the Dear ImGui version/credits, and build/system information.
Sourcepub fn show_metrics_window(&self, opened: &mut bool)
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.
Sourcepub fn show_style_editor(&self, style: &mut Style)
pub fn show_style_editor(&self, style: &mut Style)
Renders a style editor block (not a window) for the given Style
structure
Sourcepub fn show_default_style_editor(&self)
pub fn show_default_style_editor(&self)
Renders a style editor block (not a window) for the currently active style
Sourcepub fn show_user_guide(&self)
pub fn show_user_guide(&self)
Renders a basic help/info block (not a window)
Source§impl Ui
impl Ui
Sourcepub fn new_id_int(&self, input: i32) -> Id
pub fn new_id_int(&self, input: i32) -> Id
Create Id
from i32
Sourcepub fn new_id_ptr<T>(&self, input: &T) -> Id
pub fn new_id_ptr<T>(&self, input: &T) -> Id
Create Id
from a pointer
Source§impl Ui
impl Ui
Sourcepub fn window<Label: AsRef<str>>(&self, name: Label) -> Window<'_, '_, Label>
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();
};
Sourcepub fn child_window<Label: AsRef<str>>(&self, name: Label) -> ChildWindow<'_>
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.
Sourcepub fn child_window_id(&self, id: Id) -> ChildWindow<'_>
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
impl<'ui> Ui
Sourcepub fn input_text<'p, L: AsRef<str>>(
&'ui self,
label: L,
buf: &'p mut String,
) -> InputText<'ui, 'p, L>
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
Sourcepub fn input_text_multiline<'p, L: AsRef<str>>(
&'ui self,
label: L,
buf: &'p mut String,
size: [f32; 2],
) -> InputTextMultiline<'ui, 'p, L>
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
Sourcepub fn input_float<'p, L: AsRef<str>>(
&'ui self,
label: L,
value: &'p mut f32,
) -> InputScalar<'ui, 'p, f32, L>
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
Sourcepub fn input_float2<'p, L, T>(
&'ui self,
label: L,
value: &'p mut T,
) -> InputFloat2<'ui, 'p, L, T>
pub fn input_float2<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputFloat2<'ui, 'p, L, T>
Widget to edit two floats
Sourcepub fn input_float3<'p, L, T>(
&'ui self,
label: L,
value: &'p mut T,
) -> InputFloat3<'ui, 'p, L, T>
pub fn input_float3<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputFloat3<'ui, 'p, L, T>
Widget to edit 3 floats
Sourcepub fn input_float4<'p, L, T>(
&'ui self,
label: L,
value: &'p mut T,
) -> InputFloat4<'ui, 'p, L, T>
pub fn input_float4<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputFloat4<'ui, 'p, L, T>
Widget to edit 4 floats
Sourcepub fn input_int<'p, L: AsRef<str>>(
&'ui self,
label: L,
value: &'p mut i32,
) -> InputScalar<'ui, 'p, i32, L>
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
Sourcepub fn input_int2<'p, L, T>(
&'ui self,
label: L,
value: &'p mut T,
) -> InputInt2<'ui, 'p, L, T>
pub fn input_int2<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputInt2<'ui, 'p, L, T>
Shortcut for Ui::input_scalar
Sourcepub fn input_int3<'p, L, T>(
&'ui self,
label: L,
value: &'p mut T,
) -> InputInt3<'ui, 'p, L, T>
pub fn input_int3<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputInt3<'ui, 'p, L, T>
Shortcut for Ui::input_scalar
Sourcepub fn input_int4<'p, L, T>(
&'ui self,
label: L,
value: &'p mut T,
) -> InputInt4<'ui, 'p, L, T>
pub fn input_int4<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputInt4<'ui, 'p, L, T>
Shortcut for Ui::input_scalar
Sourcepub fn input_scalar<'p, L, T>(
&'ui self,
label: L,
value: &'p mut T,
) -> InputScalar<'ui, 'p, T, L>
pub fn input_scalar<'p, L, T>( &'ui self, label: L, value: &'p mut T, ) -> InputScalar<'ui, 'p, T, L>
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
.
Sourcepub fn input_scalar_n<'p, L, T>(
&'ui self,
label: L,
values: &'p mut [T],
) -> InputScalarN<'ui, 'p, T, L>
pub fn input_scalar_n<'p, L, T>( &'ui self, label: L, values: &'p mut [T], ) -> InputScalarN<'ui, 'p, T, L>
Shows a horizontal array of scalar value input fields. See input_scalar
.
Source§impl Ui
§Tooltips
impl Ui
§Tooltips
Sourcepub fn tooltip<F: FnOnce()>(&self, f: F)
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!");
});
}
}
Sourcepub fn begin_tooltip(&self) -> TooltipToken<'_>
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()
Sourcepub fn tooltip_text<T: AsRef<str>>(&self, text: T)
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
)
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
)
Sourcepub fn begin_disabled(&self, disabled: bool) -> DisabledToken<'_>
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");
}
Sourcepub fn begin_enabled(&self, enabled: bool) -> DisabledToken<'_>
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)
)
Sourcepub fn disabled<F: FnOnce()>(&self, disabled: bool, f: F)
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");
});
}
Sourcepub fn enabled<F: FnOnce()>(&self, enabled: bool, f: F)
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> Ui
impl<'ui> Ui
Sourcepub fn plot_lines<'p, Label: AsRef<str>>(
&'ui self,
label: Label,
values: &'p [f32],
) -> PlotLines<'ui, 'p, Label>
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
Sourcepub fn plot_histogram<'p, Label: AsRef<str>>(
&'ui self,
label: Label,
values: &'p [f32],
) -> PlotHistogram<'ui, 'p, Label>
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
Sourcepub fn calc_text_size<T: AsRef<str>>(&self, text: T) -> [f32; 2]
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
.
Sourcepub fn calc_text_size_with_opts<T: AsRef<str>>(
&self,
text: T,
hide_text_after_double_hash: bool,
wrap_width: f32,
) -> [f32; 2]
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
impl Ui
§Draw list for custom drawing
Sourcepub fn get_window_draw_list(&self) -> DrawListMut<'_>
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();
}
Sourcepub fn get_background_draw_list(&self) -> DrawListMut<'_>
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
Sourcepub fn get_foreground_draw_list(&self) -> DrawListMut<'_>
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