Ui

Struct Ui 

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

Represents the Dear ImGui user interface for one frame

Implementations§

Source§

impl Ui

Docking-related functionality

Source

pub fn dockspace_over_main_viewport_with_flags( &self, dockspace_id: Id, flags: DockNodeFlags, ) -> Id

Creates a dockspace over the main viewport

This is a convenience function that creates a dockspace covering the entire main viewport. It’s equivalent to calling dock_space with the main viewport’s ID and size.

§Parameters
  • dockspace_id - The ID for the dockspace (use 0 to auto-generate)
  • flags - Dock node flags
§Returns

The ID of the created dockspace

§Example
let dockspace_id = ui.dockspace_over_main_viewport_with_flags(
    0,
    DockNodeFlags::PASSTHRU_CENTRAL_NODE
);
Source

pub fn dockspace_over_main_viewport(&self) -> Id

Creates a dockspace over the main viewport with default settings

This is a convenience function that creates a dockspace covering the entire main viewport with passthrough central node enabled.

§Returns

The ID of the created dockspace

§Example
let dockspace_id = ui.dockspace_over_main_viewport();
Source

pub fn dock_space_with_class( &self, id: Id, size: [f32; 2], flags: DockNodeFlags, window_class: Option<&WindowClass>, ) -> Id

Creates a dockspace with the specified ID, size, and flags

§Parameters
  • id - The ID for the dockspace (use 0 to auto-generate)
  • size - The size of the dockspace in pixels
  • flags - Dock node flags
  • window_class - Optional window class for docking configuration
§Returns

The ID of the created dockspace

§Example
let dockspace_id = ui.dock_space_with_class(
    0,
    [800.0, 600.0],
    DockNodeFlags::NO_DOCKING_SPLIT,
    Some(&WindowClass::new(1))
);
Source

pub fn dock_space(&self, id: Id, size: [f32; 2]) -> Id

Creates a dockspace with the specified ID and size

§Parameters
  • id - The ID for the dockspace (use 0 to auto-generate)
  • size - The size of the dockspace in pixels
§Returns

The ID of the created dockspace

§Example
let dockspace_id = ui.dock_space(0, [800.0, 600.0]);
Source

pub fn set_next_window_dock_id_with_cond(&self, dock_id: Id, cond: Condition)

Sets the dock ID for the next window with condition

This function must be called before creating a window to dock it to a specific dock node.

§Parameters
  • dock_id - The ID of the dock node to dock the next window to
  • cond - Condition for when to apply the docking
§Example
let dockspace_id = ui.dockspace_over_main_viewport();
ui.set_next_window_dock_id_with_cond(dockspace_id, Condition::FirstUseEver);
ui.window("Docked Window").build(|| {
    ui.text("This window will be docked!");
});
Source

pub fn set_next_window_dock_id(&self, dock_id: Id)

Sets the dock ID for the next window

This function must be called before creating a window to dock it to a specific dock node. Uses Condition::Always by default.

§Parameters
  • dock_id - The ID of the dock node to dock the next window to
§Example
let dockspace_id = ui.dockspace_over_main_viewport();
ui.set_next_window_dock_id(dockspace_id);
ui.window("Docked Window").build(|| {
    ui.text("This window will be docked!");
});
Source

pub fn set_next_window_class(&self, window_class: &WindowClass)

Sets the window class for the next window

This function must be called before creating a window to apply the window class configuration.

§Parameters
  • window_class - The window class configuration
§Example
let window_class = WindowClass::new(1).docking_always_tab_bar(true);
ui.set_next_window_class(&window_class);
ui.window("Classed Window").build(|| {
    ui.text("This window has a custom class!");
});
Source

pub fn get_window_dock_id(&self) -> Id

Gets the dock ID of the current window

§Returns

The dock ID of the current window, or 0 if the window is not docked

§Example
ui.window("My Window").build(|| {
    let dock_id = ui.get_window_dock_id();
    if dock_id != 0 {
        ui.text(format!("This window is docked with ID: {}", dock_id));
    } else {
        ui.text("This window is not docked");
    }
});
Source

pub fn is_window_docked(&self) -> bool

Checks if the current window is docked

§Returns

true if the current window is docked, false otherwise

§Example
ui.window("My Window").build(|| {
    if ui.is_window_docked() {
        ui.text("This window is docked!");
    } else {
        ui.text("This window is floating");
    }
});
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 push_font_with_size(&self, font: Option<&Font>, size: f32)

Push a font with dynamic size support (v1.92+ feature)

This allows changing font size at runtime without pre-loading different sizes. Pass None for font to use the current font with the new size.

Source

pub fn with_font_and_size<F, R>( &self, font: Option<&Font>, size: f32, f: F, ) -> R
where F: FnOnce() -> R,

Execute a closure with a specific font and size (v1.92+ dynamic fonts)

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

Note: This function is not available in our Dear ImGui version. Font scaling should be handled through font size instead.

Source§

impl Ui

Source

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

Check if a key is being held down

Source

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

Check if a key was pressed (went from !Down to Down)

Source

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

Check if a key was pressed (went from !Down to Down), with repeat

Source

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

Check if a key was released (went from Down to !Down)

Source

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

Check if a mouse button is being held down

Source

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

Check if a mouse button was clicked (went from !Down to Down)

Source

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

Check if a mouse button was clicked, with repeat

Source

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

Check if a mouse button was released (went from Down to !Down)

Source

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

Check if a mouse button was double-clicked

Source

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

Get mouse position in screen coordinates

Source

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

Get mouse position when a specific button was clicked

Source

pub fn is_mouse_hovering_rect(&self, r_min: [f32; 2], r_max: [f32; 2]) -> bool

Check if mouse is hovering given rectangle

Source

pub fn is_mouse_hovering_rect_with_clip( &self, r_min: [f32; 2], r_max: [f32; 2], clip: bool, ) -> bool

Check if mouse is hovering given rectangle (with clipping test)

Source

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

Check if mouse is dragging

Source

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

Check if mouse is dragging with threshold

Source

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

Get mouse drag delta

Source

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

Get mouse drag delta with threshold

Source

pub fn reset_mouse_drag_delta(&self, button: MouseButton)

Reset mouse drag delta for a specific button

Source§

impl Ui

Source

pub fn main_viewport(&self) -> &'static Viewport

Returns a reference to the main Dear ImGui viewport (safe wrapper)

Same viewport used by dockspace_over_main_viewport().

Source

pub fn io(&self) -> &Io

Returns an immutable reference to the inputs/outputs object

Source

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

Display text

Source

pub fn set_next_window_viewport(&self, viewport_id: Id)

Set the viewport for the next window.

This is a convenience wrapper over ImGui::SetNextWindowViewport. Useful when hosting a fullscreen DockSpace window inside the main viewport.

Source

pub fn get_id(&self, label: &str) -> Id

Returns an ID from a string label in the current ID scope.

This mirrors ImGui::GetID(label). Useful for building stable IDs for widgets or dockspaces inside the current window/scope.

Source

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

Access to the current window’s draw list

Source

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

Access to the background draw list

Source

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

Access to the foreground draw list

Source

pub fn window(&self, name: impl Into<String>) -> Window<'_>

Creates a window builder

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 image_with_bg( &self, texture: impl Into<TextureRef>, size: [f32; 2], bg_color: [f32; 4], tint_color: [f32; 4], )

Convenience: draw an image with background and tint (ImGui 1.92+)

Equivalent to using image_config(...).build_with_bg(bg, tint) but in one call.

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

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

Creates a drag float slider

Source

pub fn drag_float_config<L: AsRef<str>>(&self, label: L) -> Drag<f32, L>

Creates a drag float slider with configuration

Source

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

Creates a drag int slider

Source

pub fn drag_int_config<L: AsRef<str>>(&self, label: L) -> Drag<i32, L>

Creates a drag int slider with configuration

Source

pub fn drag_float_range2( &self, label: impl AsRef<str>, min: &mut f32, max: &mut f32, ) -> bool

Creates a drag float range slider

Source

pub fn drag_float_range2_config<L: AsRef<str>>( &self, label: L, ) -> DragRange<f32, L>

Creates a drag float range slider with configuration

Source

pub fn drag_int_range2( &self, label: impl AsRef<str>, min: &mut i32, max: &mut i32, ) -> bool

Creates a drag int range slider

Source

pub fn drag_int_range2_config<L: AsRef<str>>( &self, label: L, ) -> DragRange<i32, L>

Creates a drag int range slider with configuration

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 set_keyboard_focus_here(&self)

Focuses keyboard on the next widget.

This is the equivalent to set_keyboard_focus_here_with_offset with offset set to 0.

Source

pub fn set_keyboard_focus_here_with_offset(&self, offset: i32)

Focuses keyboard on a widget relative to current position.

Use positive offset to focus on next widgets, negative offset to focus on previous widgets.

Source

pub fn set_next_item_open(&self, is_open: bool)

Set next item to be open by default.

This is useful for tree nodes, collapsing headers, etc.

Source

pub fn set_next_item_open_with_cond(&self, is_open: bool, cond: Condition)

Set next item to be open by default with condition.

Source

pub fn set_next_item_width(&self, item_width: f32)

Set next item width.

Set to 0.0 for default width, >0.0 for explicit width, <0.0 for relative width.

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

pub fn clone_style(&self) -> Style

Returns a copy of the current style.

This is a safe alternative to style that avoids the lifetime issues.

Source

pub fn style_colors_dark(&self)

Apply the built-in Dark style to the current style.

Source

pub fn style_colors_light(&self)

Apply the built-in Light style to the current style.

Source

pub fn style_colors_classic(&self)

Apply the built-in Classic style to the current style.

Source

pub fn style_colors_dark_into(&self, dst: &mut Style)

Write the Dark style values into the provided [Style] object.

Source

pub fn style_colors_light_into(&self, dst: &mut Style)

Write the Light style values into the provided [Style] object.

Source

pub fn style_colors_classic_into(&self, dst: &mut Style)

Write the Classic style values into the provided [Style] object.

Source

pub fn window_dpi_scale(&self) -> f32

Returns DPI scale currently associated to the current window’s viewport.

Source

pub fn value_bool(&self, prefix: impl AsRef<str>, v: bool)

Display a text label with a boolean value (for quick debug UIs).

Source

pub fn window_width(&self) -> f32

Get current window width (shortcut for GetWindowSize().x).

Source

pub fn window_height(&self) -> f32

Get current window height (shortcut for GetWindowSize().y).

Source

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

Get current window position in screen space.

Source

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

Get current window size.

Source

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

Renders a debug log window.

Displays a simplified log of important dear imgui events.

Source

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

Renders an ID stack tool window.

Hover items with mouse to query information about the source of their unique ID.

Source

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

Renders a style selector combo box.

Returns true when a different style was selected.

Source

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

Renders a font selector combo box.

Source

pub fn get_version(&self) -> &str

Returns the Dear ImGui version string

Source§

impl Ui

Utility functions for Dear ImGui

Source

pub fn is_item_toggled_open(&self) -> bool

Returns true if the last item open state was toggled

Source

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

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

Source

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

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

Source

pub fn is_window_hovered(&self) -> bool

Returns true if the current window is hovered (and typically: not blocked by a popup/modal)

Source

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

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

Source

pub fn is_window_focused(&self) -> bool

Returns true if the current window is focused (and typically: not blocked by a popup/modal)

Source

pub fn is_window_appearing(&self) -> bool

Returns true if the current window is appearing this frame.

Source

pub fn is_window_collapsed(&self) -> bool

Returns true if the current window is collapsed.

Source

pub fn get_key_pressed_amount( &self, key: Key, repeat_delay: f32, rate: f32, ) -> i32

Returns the number of times the key was pressed in the current frame

Source

pub fn get_key_name(&self, key: Key) -> &str

Returns the name of a key

Source

pub fn get_mouse_clicked_count(&self, button: MouseButton) -> i32

Returns the number of times the mouse button was clicked in the current frame

Source

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

Returns the mouse position in screen coordinates

Source

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

Returns the mouse position when the button was clicked

Source

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

Returns the mouse drag delta

Source

pub fn get_mouse_wheel(&self) -> f32

Returns the mouse wheel delta

Source

pub fn get_mouse_wheel_h(&self) -> f32

Returns the horizontal mouse wheel delta

Source

pub fn is_any_mouse_down(&self) -> bool

Returns true if any mouse button is down

Source

pub fn time(&self) -> f64

Get global imgui time. Incremented by io.DeltaTime every frame.

Source

pub fn frame_count(&self) -> i32

Get global imgui 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

Returns the name of a style color.

This is just a wrapper around calling name on StyleColor.

Source

pub fn is_rect_visible(&self, size: [f32; 2]) -> bool

Test if rectangle (of given size, starting from cursor position) is visible / not clipped.

Source

pub fn is_rect_visible_ex(&self, rect_min: [f32; 2], rect_max: [f32; 2]) -> bool

Test if rectangle (in screen space) is visible / not clipped.

Source

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

Get cursor position in screen coordinates.

Source

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

Get available content region size.

Source

pub fn is_point_in_rect( &self, point: [f32; 2], rect_min: [f32; 2], rect_max: [f32; 2], ) -> bool

Check if a point is inside a rectangle.

Source

pub fn distance(&self, p1: [f32; 2], p2: [f32; 2]) -> f32

Calculate distance between two points.

Source

pub fn distance_squared(&self, p1: [f32; 2], p2: [f32; 2]) -> f32

Calculate squared distance between two points (faster than distance).

Source

pub fn line_segments_intersect( &self, p1: [f32; 2], p2: [f32; 2], p3: [f32; 2], p4: [f32; 2], ) -> bool

Check if two line segments intersect.

Source

pub fn normalize(&self, v: [f32; 2]) -> [f32; 2]

Normalize a 2D vector.

Source

pub fn dot_product(&self, v1: [f32; 2], v2: [f32; 2]) -> f32

Calculate dot product of two 2D vectors.

Source

pub fn angle_between_vectors(&self, v1: [f32; 2], v2: [f32; 2]) -> f32

Calculate the angle between two vectors in radians.

Source

pub fn is_point_in_circle( &self, point: [f32; 2], center: [f32; 2], radius: f32, ) -> bool

Check if a point is inside a circle.

Source

pub fn triangle_area(&self, p1: [f32; 2], p2: [f32; 2], p3: [f32; 2]) -> f32

Calculate the area of a triangle given three points.

Source

pub fn set_next_item_allow_overlap(&self)

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

Source§

impl Ui

Source

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

Creates a button with the given label

Source

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

Creates a button with the given label and size

Source

pub fn button_config(&self, label: impl AsRef<str>) -> Button<'_>

Creates a button builder

Source§

impl Ui

Source

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

Creates a checkbox

Source

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

Creates a radio button

Source

pub fn radio_button_int( &self, label: impl AsRef<str>, v: &mut i32, v_button: i32, ) -> bool

Creates a radio button with integer value

Source

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

Creates a radio button suitable for choosing an arbitrary value.

Returns true if this radio button 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§

impl Ui

§Color Edit Widgets

Source

pub fn color_edit3(&self, label: impl AsRef<str>, color: &mut [f32; 3]) -> bool

Creates a color edit widget for 3 components (RGB)

Source

pub fn color_edit4(&self, label: impl AsRef<str>, color: &mut [f32; 4]) -> bool

Creates a color edit widget for 4 components (RGBA)

Source

pub fn color_picker3( &self, label: impl AsRef<str>, color: &mut [f32; 3], ) -> bool

Creates a color picker widget for 3 components (RGB)

Source

pub fn color_picker4( &self, label: impl AsRef<str>, color: &mut [f32; 4], ) -> bool

Creates a color picker widget for 4 components (RGBA)

Source

pub fn color_button(&self, desc_id: impl AsRef<str>, color: [f32; 4]) -> bool

Creates a color button widget

Source

pub fn color_edit3_config<'p>( &self, label: impl AsRef<str>, color: &'p mut [f32; 3], ) -> ColorEdit3<'_, 'p>

Creates a color edit builder for 3 components

Source

pub fn color_edit4_config<'p>( &self, label: impl AsRef<str>, color: &'p mut [f32; 4], ) -> ColorEdit4<'_, 'p>

Creates a color edit builder for 4 components

Source

pub fn color_picker3_config<'p>( &self, label: impl AsRef<str>, color: &'p mut [f32; 3], ) -> ColorPicker3<'_, 'p>

Creates a color picker builder for 3 components

Source

pub fn color_picker4_config<'p>( &self, label: impl AsRef<str>, color: &'p mut [f32; 4], ) -> ColorPicker4<'_, 'p>

Creates a color picker builder for 4 components

Source

pub fn color_button_config( &self, desc_id: impl AsRef<str>, color: [f32; 4], ) -> ColorButton<'_>

Creates a color button builder

Source§

impl Ui

§Combo Box Widgets

Source

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

Creates a combo box and starts appending to it.

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_with_flags( &self, label: impl AsRef<str>, preview_value: impl AsRef<str>, flags: ComboBoxFlags, ) -> Option<ComboBoxToken<'_>>

Creates a combo box with flags and starts appending to it.

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 without preview value.

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 without preview value and 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 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.

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

Source

pub fn set_item_default_focus(&self)

Sets the default focus for the next item

Source§

impl Ui

Source

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

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

Source

pub fn drag_config<T: AsRef<str>, K: DataTypeKind>( &self, label: T, ) -> Drag<K, T>

Creates a new unbuilt Drag.

Source

pub fn drag_float2(&self, label: impl AsRef<str>, values: &mut [f32; 2]) -> bool

Creates a drag float2 slider (2 floats)

Source

pub fn drag_float3(&self, label: impl AsRef<str>, values: &mut [f32; 3]) -> bool

Creates a drag float3 slider (3 floats)

Source

pub fn drag_float4(&self, label: impl AsRef<str>, values: &mut [f32; 4]) -> bool

Creates a drag float4 slider (4 floats)

Source

pub fn drag_int2(&self, label: impl AsRef<str>, values: &mut [i32; 2]) -> bool

Creates a drag int2 slider (2 ints)

Source

pub fn drag_int3(&self, label: impl AsRef<str>, values: &mut [i32; 3]) -> bool

Creates a drag int3 slider (3 ints)

Source

pub fn drag_int4(&self, label: impl AsRef<str>, values: &mut [i32; 4]) -> bool

Creates a drag int4 slider (4 ints)

Source§

impl Ui

§Image Widgets

Examples

  • Using a plain texture id:
let tex_id = texture::TextureId::new(0xDEAD_BEEF);
ui.image(tex_id, [128.0, 128.0]);
  • Using an ImGui-managed texture:
let mut tex = texture::TextureData::new();
tex.create(texture::TextureFormat::RGBA32, 64, 64);
ui.image(&mut *tex, [64.0, 64.0]);
Source

pub fn image(&self, texture: impl Into<TextureRef>, size: [f32; 2])

Creates an image widget

Source

pub fn image_button( &self, str_id: impl AsRef<str>, texture: impl Into<TextureRef>, size: [f32; 2], ) -> bool

Creates an image button widget

Source

pub fn image_config( &self, texture: impl Into<TextureRef>, size: [f32; 2], ) -> Image<'_>

Creates an image builder

Source

pub fn image_button_config( &self, str_id: impl AsRef<str>, texture: impl Into<TextureRef>, size: [f32; 2], ) -> ImageButton<'_>

Creates an image button builder

Source§

impl Ui

§Input Widgets

Source

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

Creates a single-line text input widget builder.

§Examples
let mut text = String::new();
if ui.input_text("Label", &mut text).build() {
    println!("Text changed: {}", text);
}
Source

pub fn input_text_imstr<'p>( &self, label: impl AsRef<str>, buf: &'p mut ImString, ) -> InputTextImStr<'_, 'p, String, String, PassthroughCallback>

Creates a single-line text input backed by ImString (zero-copy)

Source

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

Creates a multi-line text input widget builder.

§Examples
let mut text = String::new();
if ui.input_text_multiline("Label", &mut text, [200.0, 100.0]).build() {
    println!("Text changed: {}", text);
}
Source

pub fn input_text_multiline_imstr<'p>( &self, label: impl AsRef<str>, buf: &'p mut ImString, size: impl Into<[f32; 2]>, ) -> InputTextMultilineImStr<'_, 'p>

Creates a multi-line text input backed by ImString (zero-copy)

Source

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

Creates an integer input widget.

Returns true if the value was edited.

Source

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

Creates a float input widget.

Returns true if the value was edited.

Source

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

Creates a double input widget.

Returns true if the value was edited.

Source

pub fn input_int_config(&self, label: impl AsRef<str>) -> InputInt<'_>

Creates an integer input builder

Source

pub fn input_float_config(&self, label: impl AsRef<str>) -> InputFloat<'_>

Creates a float input builder

Source

pub fn input_double_config(&self, label: impl AsRef<str>) -> InputDouble<'_>

Creates a double input builder

Source

pub fn input_scalar<'p, L, T>( &self, label: L, value: &'p mut T, ) -> InputScalar<'_, '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>( &self, label: L, values: &'p mut [T], ) -> InputScalarN<'_, 'p, T, L>
where L: AsRef<str>, T: DataTypeKind,

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

Source

pub fn input_float2<'p, L>( &self, label: L, value: &'p mut [f32; 2], ) -> InputFloat2<'_, 'p, L>
where L: AsRef<str>,

Widget to edit two floats

Source

pub fn input_float3<'p, L>( &self, label: L, value: &'p mut [f32; 3], ) -> InputFloat3<'_, 'p, L>
where L: AsRef<str>,

Widget to edit three floats

Source

pub fn input_float4<'p, L>( &self, label: L, value: &'p mut [f32; 4], ) -> InputFloat4<'_, 'p, L>
where L: AsRef<str>,

Widget to edit four floats

Source

pub fn input_int2<'p, L>( &self, label: L, value: &'p mut [i32; 2], ) -> InputInt2<'_, 'p, L>
where L: AsRef<str>,

Widget to edit two integers

Source

pub fn input_int3<'p, L>( &self, label: L, value: &'p mut [i32; 3], ) -> InputInt3<'_, 'p, L>
where L: AsRef<str>,

Widget to edit three integers

Source

pub fn input_int4<'p, L>( &self, label: L, value: &'p mut [i32; 4], ) -> InputInt4<'_, 'p, L>
where L: AsRef<str>,

Widget to edit four integers

Source§

impl Ui

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 begin_menu_bar(&self) -> Option<MenuBarToken<'_>>

Creates and starts appending to a menu bar for a 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 begin_menu(&self, label: impl AsRef<str>) -> Option<MenuToken<'_>>

Creates a menu and starts appending to it.

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

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

Source

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

Creates a menu with enabled state and starts appending to it.

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

Returns None if the menu is not open 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.

Returns true if the menu item is activated.

Source

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

Creates a menu item with a shortcut.

Returns true if the menu item is activated.

Source

pub fn menu_item_enabled_selected( &self, label: impl AsRef<str>, shortcut: Option<impl AsRef<str>>, selected: bool, enabled: bool, ) -> bool

Creates a menu item with explicit enabled/selected state. Returns true if the menu item is activated.

Source

pub fn menu_item_toggle( &self, label: impl AsRef<str>, shortcut: Option<impl AsRef<str>>, selected: &mut bool, enabled: bool, ) -> bool

Creates a toggleable menu item bound to selected (updated in place). Returns true if the menu item is activated.

Source§

impl Ui

Source

pub fn bullet(&self)

Creates a bullet point

Source

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

Creates a bullet point with text

Source§

impl Ui

Source

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

Creates a small button

Source

pub fn invisible_button( &self, str_id: impl AsRef<str>, size: impl Into<[f32; 2]>, ) -> bool

Creates an invisible button

Source

pub fn invisible_button_flags( &self, str_id: impl AsRef<str>, size: impl Into<[f32; 2]>, flags: ButtonFlags, ) -> bool

Creates an invisible button with flags

Source

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

Creates an arrow button

Source§

impl Ui

Source

pub fn begin_disabled(&self) -> DisabledToken<'_>

Begin a disabled scope for subsequent items.

All following widgets will be disabled (grayed out and non-interactive) until the returned token is dropped.

Source

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

Begin a conditionally disabled scope for subsequent items.

If disabled is false, this still needs to be paired with the returned token being dropped to correctly balance the internal stack.

Source§

impl Ui

Source

pub fn push_button_repeat(&self, repeat: bool)

Enable/disable repeating behavior for subsequent buttons.

Internally uses PushItemFlag(ImGuiItemFlags_ButtonRepeat, repeat).

Source

pub fn pop_button_repeat(&self)

Pop the button repeat item flag.

Source§

impl Ui

Source

pub fn set_item_key_owner(&self, key: Key)

Set the key owner for the last item, without flags.

Source

pub fn set_item_key_owner_with_flags(&self, key: Key, flags: ImGuiInputFlags)

Set the key owner for the last item with input flags. Pass a combination of ImGuiInputFlags_* from dear_imgui_sys.

Source§

impl Ui

§Plot Widgets

Source

pub fn plot_lines(&self, label: impl AsRef<str>, values: &[f32])

Creates a plot lines widget

Source

pub fn plot_histogram(&self, label: impl AsRef<str>, values: &[f32])

Creates a plot histogram widget

Source

pub fn plot_lines_config<'p>( &self, label: impl AsRef<str>, values: &'p [f32], ) -> PlotLines<'_, 'p>

Creates a plot lines builder

Source

pub fn plot_histogram_config<'p>( &self, label: impl AsRef<str>, values: &'p [f32], ) -> PlotHistogram<'_, 'p>

Creates a plot histogram builder

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 open_popup_with_flags(&self, str_id: impl AsRef<str>, flags: PopupFlags)

Instructs ImGui that a popup is open with flags.

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 begin_popup_with_flags( &self, str_id: impl AsRef<str>, flags: WindowFlags, ) -> Option<PopupToken<'_>>

Construct a popup with window flags.

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 begin_modal_popup( &self, name: impl AsRef<str>, ) -> Option<ModalPopupToken<'_>>

Creates a modal popup.

Modal popups block interaction with the rest of the application until closed.

Source

pub fn begin_modal_popup_config<'a>(&'a self, name: &'a str) -> ModalPopup<'a>

Creates a modal popup builder.

Source

pub fn modal_popup<F, R>(&self, name: impl AsRef<str>, f: F) -> Option<R>
where F: FnOnce() -> R,

Creates a modal popup and runs a closure to construct the contents.

Returns the result of the closure if the popup is open.

Source

pub fn close_current_popup(&self)

Closes the current popup.

Source

pub fn is_popup_open(&self, str_id: impl AsRef<str>) -> bool

Returns true if the popup is open.

Source

pub fn is_popup_open_with_flags( &self, str_id: impl AsRef<str>, flags: PopupFlags, ) -> bool

Returns true if the popup is open with flags.

Source

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

Begin a popup context menu for the last item. This is typically used with right-click context menus.

Source

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

Begin a popup context menu for the last item with a custom label.

Source

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

Begin a popup context menu for the current window.

Source

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

Begin a popup context menu for the current window with a custom label.

Source

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

Begin a popup context menu for empty space (void).

Source

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

Begin a popup context menu for empty space with a custom label.

Source§

impl Ui

§Progress Bar Widgets

Source

pub fn progress_bar(&self, fraction: f32) -> ProgressBar<'_>

Creates a progress bar widget.

The fraction should be between 0.0 (0%) and 1.0 (100%).

Source

pub fn progress_bar_with_overlay( &self, fraction: f32, overlay: impl AsRef<str>, ) -> ProgressBar<'_>

Creates a progress bar with overlay text.

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 a new unbuilt Slider.

Source

pub fn slider_f32( &self, label: impl AsRef<str>, value: &mut f32, min: f32, max: f32, ) -> bool

Creates a float slider

Source

pub fn slider_i32( &self, label: impl AsRef<str>, value: &mut i32, min: i32, max: i32, ) -> bool

Creates an integer slider

Source

pub fn v_slider_f32( &self, label: impl AsRef<str>, size: impl Into<[f32; 2]>, value: &mut f32, min: f32, max: f32, ) -> bool

Creates a vertical slider

Source

pub fn v_slider_i32( &self, label: impl AsRef<str>, size: impl Into<[f32; 2]>, value: &mut i32, min: i32, max: i32, ) -> bool

Creates a vertical integer slider

Source

pub fn slider_angle(&self, label: impl AsRef<str>, value_rad: &mut f32) -> bool

Creates an angle slider (value in radians)

Source§

impl Ui

§Tab Widgets

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

§Table Widgets

Source

pub fn table(&self, str_id: impl AsRef<str>) -> TableBuilder<'_>

Start a Table builder for ergonomic setup + headers + options.

Example

ui.table("perf")
    .flags(TableFlags::RESIZABLE | TableFlags::SORTABLE)
    .outer_size([600.0, 240.0])
    .freeze(1, 1)
    .column("Name").width(140.0).done()
    .column("Value").weight(1.0).done()
    .headers(true)
    .build(|ui| {
        ui.table_next_row();
        ui.table_next_column(); ui.text("CPU");
        ui.table_next_column(); ui.text("Intel");
    });
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 constraints.

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

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 with standard sizing constraints.

Source

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

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

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

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 with standard sizing constraints.

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

Source

pub fn table_setup_column( &self, label: impl AsRef<str>, flags: TableColumnFlags, init_width_or_weight: f32, user_id: u32, )

Setup a column for the current table

Source

pub fn table_headers_row(&self)

Submit all headers cells based on data provided to TableSetupColumn() + submit context menu

Source

pub fn table_next_column(&self) -> bool

Append into the next column (or first column of next row if currently in last column)

Source

pub fn table_set_column_index(&self, column_n: i32) -> bool

Append into the specified column

Source

pub fn table_next_row(&self)

Append into the next row

Source

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

Append into the next row with flags and minimum height

Source

pub fn table_setup_scroll_freeze(&self, frozen_cols: i32, frozen_rows: i32)

Freeze columns/rows so they stay visible when scrolling.

Source

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

Submit one header cell at current column position.

Source

pub fn table_get_column_count(&self) -> i32

Return columns count.

Source

pub fn table_get_column_index(&self) -> i32

Return current column index.

Source

pub fn table_get_row_index(&self) -> i32

Return current row index.

Source

pub fn table_get_column_name(&self, column_n: i32) -> &str

Return the name of a column by index.

Source

pub fn table_get_column_flags(&self, column_n: i32) -> TableColumnFlags

Return the flags of a column by index.

Source

pub fn table_set_column_enabled(&self, column_n: i32, enabled: bool)

Enable/disable a column by index.

Source

pub fn table_get_hovered_column(&self) -> i32

Return hovered column index, or -1 when none.

Source

pub fn table_set_column_width(&self, column_n: i32, width: f32)

Set column width (for fixed-width columns).

Source

pub fn table_set_bg_color_u32( &self, target: TableBgTarget, color: u32, column_n: i32, )

Set a table background color target.

Color must be an ImGui-packed ImU32 in ABGR order (IM_COL32). Use crate::colors::Color::to_imgui_u32() to convert RGBA floats.

Source

pub fn table_set_bg_color( &self, target: TableBgTarget, rgba: [f32; 4], column_n: i32, )

Set a table background color target using RGBA color (0..=1 floats).

Source

pub fn table_get_hovered_row(&self) -> i32

Return hovered row index, or -1 when none.

Source

pub fn table_get_header_row_height(&self) -> f32

Header row height in pixels.

Source

pub fn table_set_column_sort_direction( &self, column_n: i32, dir: SortDirection, append_to_sort_specs: bool, )

Set sort direction for a column. Optionally append to existing sort specs (multi-sort).

Source

pub fn table_get_sort_specs(&self) -> Option<TableSortSpecs<'_>>

Get current table sort specifications, if any. When non-None and is_dirty() is true, the application should sort its data and then call clear_dirty().

Source§

impl Ui

Source

pub fn table_get_header_angled_max_label_width(&self) -> f32

Maximum label width used for angled headers (when enabled in style/options).

Source

pub fn table_angled_headers_row(&self)

Submit angled headers row (requires style/flags enabling angled headers).

Source

pub fn table_angled_headers_row_ex_with_data( &self, row_id: u32, angle: f32, max_label_width: f32, headers: &[TableHeaderData], )

Submit angled headers row with explicit data (Ex variant).

  • row_id: ImGuiID for the row. Use 0 for automatic if not needed.
  • angle: Angle in radians for headers.
  • max_label_width: Maximum label width for angled headers.
  • headers: Per-column header data.
Source

pub fn table_push_background_channel(&self)

Push background draw channel for the current table and return a token to pop it.

Source

pub fn table_pop_background_channel(&self)

Pop background draw channel for the current table.

Source

pub fn table_push_column_channel(&self, column_n: i32)

Push column draw channel for the given column index and return a token to pop it.

Source

pub fn table_pop_column_channel(&self)

Pop column draw channel.

Source

pub fn with_table_background_channel<R>(&self, f: impl FnOnce() -> R) -> R

Run a closure after pushing table background channel (auto-pop on return).

Source

pub fn with_table_column_channel<R>( &self, column_n: i32, f: impl FnOnce() -> R, ) -> R

Run a closure after pushing a table column channel (auto-pop on return).

Source

pub fn table_open_context_menu(&self, column_n: Option<i32>)

Open the table context menu for a given column (use -1 for current/default).

Source§

impl Ui

Source

pub fn text_colored(&self, color: [f32; 4], text: impl AsRef<str>)

Display colored text

This implementation uses zero-copy optimization with igTextEx, avoiding string allocation and null-termination overhead.

§Example
ui.text_colored([1.0, 0.0, 0.0, 1.0], "Red text");
ui.text_colored([0.0, 1.0, 0.0, 1.0], "Green text");
Source

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

Display disabled (grayed out) text

This implementation uses zero-copy optimization with igTextEx, avoiding string allocation and null-termination overhead.

§Example
ui.text_disabled("This option is not available");
Source

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

Display text wrapped to fit the current item width

§Note

This function currently uses the scratch buffer implementation. Optimization for this function requires additional investigation.

Source

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

Display a label and text on the same line

Render a hyperlink-style text button. Returns true when clicked.

Render a hyperlink-style text button, and open the given URL when clicked. Returns true when clicked.

Source§

impl Ui

§Tooltip Widgets

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
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) -> Option<TooltipToken<'_>>

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

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

Source

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

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

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

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

Sets a tooltip with simple text content. This is more efficient than begin_tooltip/end_tooltip for simple text.

Source

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

Sets a tooltip with formatted text content.

Source

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

Sets a tooltip for the last item with simple text content. More efficient than building a tooltip window for simple cases.

Source§

impl Ui

§Item/Widget Utilities and Query Functions

Source

pub fn is_item_hovered(&self) -> bool

Returns true if the last item is being hovered by mouse (and usable). This is typically used to show tooltips.

Source

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

Returns true if the last item is being hovered by mouse with specific flags.

Source

pub fn is_item_active(&self) -> bool

Returns true if the last item is active (e.g. button being held, text field being edited).

Source

pub fn is_item_focused(&self) -> bool

Returns true if the last item is focused (e.g. text input field).

Source

pub fn is_item_clicked(&self) -> bool

Returns true if the last item was just clicked.

Source

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

Returns true if the last item was clicked with specific mouse button.

Source

pub fn is_item_visible(&self) -> bool

Returns true if the last item is visible (not clipped).

Source

pub fn is_item_activated(&self) -> bool

Returns true if the last item was just made active (e.g. button was pressed).

Source

pub fn is_item_deactivated(&self) -> bool

Returns true if the last item was just made inactive (e.g. button was released).

Source

pub fn is_item_deactivated_after_edit(&self) -> bool

Returns true if the last item was just made inactive and was edited.

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 is_any_item_hovered(&self) -> bool

Returns true if any item is hovered.

Source

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

Gets the bounding rectangle of the last item in screen space.

Source

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

Gets the size of the last item.

Source§

impl Ui

§Tree Node Widgets

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

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

Creates a collapsing header widget

Source§

impl Ui

Source

pub fn child_window(&self, name: impl Into<String>) -> ChildWindow<'_>

Creates a child window builder

Source§

impl Ui

Source

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

Returns the size of the content region available for widgets

This is the size of the window minus decorations (title bar, scrollbars, etc.)

Source

pub fn content_region_avail_width(&self) -> f32

Returns the width of the content region available for widgets

This is equivalent to content_region_avail()[0]

Source

pub fn content_region_avail_height(&self) -> f32

Returns the height of the content region available for widgets

This is equivalent to content_region_avail()[1]

Source§

impl Ui

Source

pub fn scroll_x(&self) -> f32

Returns the current scroll position of the window

Source

pub fn scroll_y(&self) -> f32

Returns the current vertical scroll position of the window

Source

pub fn scroll_max_x(&self) -> f32

Returns the maximum horizontal scroll position

Source

pub fn scroll_max_y(&self) -> f32

Returns the maximum vertical scroll position

Source

pub fn set_scroll_x(&self, scroll_x: f32)

Sets the horizontal scroll position

Source

pub fn set_scroll_y(&self, scroll_y: f32)

Sets the vertical scroll position

Source

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

Sets the horizontal scroll position to center on the given position

The center_x_ratio parameter should be between 0.0 (left) and 1.0 (right)

Source

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

Sets the vertical scroll position to center on the given position

The center_y_ratio parameter should be between 0.0 (top) and 1.0 (bottom)

Source

pub fn set_scroll_here_x(&self, center_x_ratio: f32)

Scrolls to make the current item visible

This is useful when you want to ensure a specific item is visible in a scrollable region

Source

pub fn set_scroll_here_y(&self, center_y_ratio: f32)

Scrolls to make the current item visible vertically

This is useful when you want to ensure a specific item is visible in a scrollable region

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<[f32; 4]>, ) -> 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 push_item_width_text( &self, text: impl AsRef<str>, ) -> ItemWidthStackToken<'_>

Sets the width of the next item(s) to be the same as the width of the given text.

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

Source

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

Sets the position where text will wrap around.

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

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

impl Ui

§ID stack

Source

pub fn push_id<'a, T: Into<Id<'a>>>(&self, id: T) -> 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 explanation, see this part of the Dear ImGui FAQ

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


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

But sometimes we want to create widgets in a loop, or we want to avoid having to manually give each widget a unique label. In these cases, we can push an ID to the ID stack:


for i in 0..10 {
    let _id = ui.push_id(i);
    ui.button("Click");
}
Source§

impl Ui

Source

pub fn push_focus_scope(&self, id: ImGuiID) -> FocusScopeToken<'_>

Push a focus scope (affects e.g. navigation focus allocation).

Returns a FocusScopeToken which will pop the focus scope when dropped.

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 separator_with_text(&self, text: impl AsRef<str>)

Renders a separator with text.

Source

pub fn separator_vertical(&self)

Creates a vertical separator

Source

pub fn separator_horizontal(&self)

Creates a horizontal separator

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<[f32; 2]>)

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::indent_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::indent_spacing.

Source

pub fn unindent_by(&self, width: f32)

Moves content position to the left by width

Source

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

Creates a layout group and starts appending to it.

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 cursor_screen_pos(&self) -> [f32; 2]

Returns the cursor position (in absolute screen coordinates)

Source

pub fn set_cursor_pos(&self, pos: impl Into<[f32; 2]>)

Sets the cursor position (in window coordinates)

Source

pub fn set_cursor_screen_pos(&self, pos: impl Into<[f32; 2]>)

Sets the cursor position (in absolute screen coordinates)

Source

pub fn cursor_pos_x(&self) -> f32

Returns the X cursor position (in window coordinates)

Source

pub fn cursor_pos_y(&self) -> f32

Returns the Y cursor position (in window coordinates)

Source

pub fn set_cursor_pos_x(&self, x: f32)

Sets the X cursor position (in window coordinates)

Source

pub fn set_cursor_pos_y(&self, y: f32)

Sets the Y cursor position (in window coordinates)

Source

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

Returns the initial cursor position (in window coordinates)

Source§

impl Ui

Source

pub fn text_line_height(&self) -> f32

Return ~ FontSize.

Source

pub fn text_line_height_with_spacing(&self) -> f32

Return ~ FontSize + style.ItemSpacing.y.

Source

pub fn frame_height(&self) -> f32

Return ~ FontSize + style.FramePadding.y * 2.

Source

pub fn frame_height_with_spacing(&self) -> f32

Return ~ FontSize + style.FramePadding.y * 2 + style.ItemSpacing.y.

Source

pub fn push_clip_rect( &self, min: impl Into<[f32; 2]>, max: impl Into<[f32; 2]>, intersect_with_current: bool, )

Push a clipping rectangle in screen space.

Source

pub fn pop_clip_rect(&self)

Pop a clipping rectangle from the stack.

Source

pub fn with_clip_rect<R>( &self, min: impl Into<[f32; 2]>, max: impl Into<[f32; 2]>, intersect_with_current: bool, f: impl FnOnce() -> R, ) -> R

Run a closure with a clip rect pushed and automatically popped.

Source

pub fn is_rect_visible_min_max( &self, rect_min: impl Into<[f32; 2]>, rect_max: impl Into<[f32; 2]>, ) -> bool

Returns true if the specified rectangle (min,max) is visible (not clipped).

Source

pub fn is_rect_visible_with_size(&self, size: impl Into<[f32; 2]>) -> bool

Returns true if a rectangle of given size at the current cursor pos is visible.

Source

pub fn align_text_to_frame_padding(&self)

Vertically align upcoming text baseline to FramePadding.y (align text to framed items).

Source§

impl Ui

Source

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

Creates a new drag drop source configuration

§Arguments
  • name - Identifier for this drag source (must match target name)
§Example
ui.button("Drag me!");
if let Some(source) = ui.drag_drop_source_config("MY_DATA")
    .flags(DragDropFlags::SOURCE_NO_PREVIEW_TOOLTIP)
    .begin() {
    ui.text("Custom drag tooltip");
    source.end();
}
Source

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

Creates a drag drop target for the last item

Returns Some(DragDropTarget) if the last item can accept drops, None otherwise.

§Example
ui.button("Drop target");
if let Some(target) = ui.drag_drop_target() {
    if target.accept_payload_empty("MY_DATA", DragDropFlags::NONE).is_some() {
        println!("Received drop!");
    }
    target.pop();
}
Source§

impl Ui

Source

pub fn text_filter(&self, label: String) -> TextFilter

Creates a new TextFilter with an empty pattern.

This is a convenience method equivalent to TextFilter::new.

§Arguments
  • label - The label to display for the filter input
§Examples
let filter = ui.text_filter("Search".to_string());
Source

pub fn text_filter_with_filter( &self, label: String, filter: String, ) -> TextFilter

Creates a new TextFilter with a custom filter pattern.

This is a convenience method equivalent to TextFilter::new_with_filter.

§Arguments
  • label - The label to display for the filter input
  • filter - The initial filter pattern
§Examples
let filter = ui.text_filter_with_filter(
    "Search".to_string(),
    "include,-exclude".to_string()
);
Source§

impl Ui

§Columns

Source

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

Creates columns layout.

§Arguments
  • count - Number of columns (must be >= 1)
  • id - Optional ID for the columns (can be empty string)
  • border - Whether to draw borders between columns
Source

pub fn begin_columns( &self, id: impl AsRef<str>, count: i32, flags: OldColumnFlags, )

Begin columns layout with advanced flags.

§Arguments
  • id - ID for the columns
  • count - Number of columns (must be >= 1)
  • flags - Column flags
Source

pub fn end_columns(&self)

End columns layout.

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

pub fn push_column_clip_rect(&self, column_index: i32)

Push column clip rect for the given column index. This is useful for custom drawing within columns.

Source

pub fn push_columns_background(&self)

Push columns background for drawing.

Source

pub fn pop_columns_background(&self)

Pop columns background.

Source

pub fn get_columns_id(&self, str_id: impl AsRef<str>, count: i32) -> u32

Get columns ID for the given string ID and count.

Source

pub fn is_any_column_resizing(&self) -> bool

Check if any column is being resized. Note: This is a placeholder implementation as the underlying C++ function is not available

Source

pub fn get_columns_total_width(&self) -> f32

Get the total width of all columns.

Source

pub fn set_columns_equal_width(&self)

Set all columns to equal width.

Source

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

Get column width as a percentage of total width.

Source

pub fn set_column_width_percentage(&self, column_index: i32, percentage: f32)

Set column width as a percentage of total width.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more