dear_imgui_rs/widget/mod.rs
1//! Standard widgets
2//!
3//! Collection of common Dear ImGui widgets exposed with an idiomatic Rust
4//! API. Most widgets follow a small builder pattern for configuration, and
5//! also provide convenience methods on [`Ui`].
6//!
7//! Examples:
8//! ```no_run
9//! # use dear_imgui_rs::*;
10//! # let mut ctx = Context::create();
11//! # let ui = ctx.frame();
12//! // Buttons
13//! if ui.button("Click me") { /* ... */ }
14//!
15//! // Sliders
16//! let mut value = 0.5f32;
17//! ui.slider_f32("Value", &mut value, 0.0, 1.0);
18//!
19//! // Inputs
20//! let mut text = String::new();
21//! ui.input_text("Name", &mut text).build();
22//! ```
23//!
24//! Submodules group related widgets: `button`, `color`, `combo`, `drag`,
25//! `image`, `input`, `list_box`, `menu`, `misc`, `plot`, `popup`, `progress`,
26//! `selectable`, `slider`, `tab`, `table`, `text`, `tooltip`, `tree`.
27//!
28use crate::sys;
29
30pub mod button;
31pub mod color;
32pub mod combo;
33pub mod drag;
34pub mod image;
35pub mod input;
36pub mod list_box;
37pub mod menu;
38pub mod misc;
39pub mod plot;
40pub mod popup;
41pub mod progress;
42pub mod selectable;
43pub mod slider;
44pub mod tab;
45pub mod table;
46pub mod text;
47pub mod tooltip;
48pub mod tree;
49
50// Re-export important types
51pub use popup::PopupFlags;
52pub use table::{TableBgTarget, TableBuilder, TableColumnSetup};
53
54// Widget implementations
55pub use self::button::*;
56pub use self::color::*;
57pub use self::combo::*;
58pub use self::drag::*;
59pub use self::image::*;
60pub use self::input::*;
61pub use self::list_box::*;
62pub use self::menu::*;
63pub use self::misc::*;
64pub use self::plot::*;
65pub use self::popup::*;
66pub use self::progress::*;
67pub use self::selectable::*;
68pub use self::slider::*;
69pub use self::tab::*;
70pub use self::table::*;
71pub use self::tooltip::*;
72pub use self::tree::*;
73
74// ButtonFlags is defined in misc.rs and re-exported
75
76bitflags::bitflags! {
77 /// Flags for tree node widgets
78 #[repr(transparent)]
79 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
80 pub struct TreeNodeFlags: i32 {
81 /// No flags
82 const NONE = 0;
83 /// Draw as selected
84 const SELECTED = sys::ImGuiTreeNodeFlags_Selected as i32;
85 /// Draw frame with background (e.g. for CollapsingHeader)
86 const FRAMED = sys::ImGuiTreeNodeFlags_Framed as i32;
87 /// Hit testing to allow subsequent widgets to overlap this one
88 const ALLOW_ITEM_OVERLAP = sys::ImGuiTreeNodeFlags_AllowOverlap as i32;
89 /// Don't do a TreePush() when open (e.g. for CollapsingHeader) = no extra indent nor pushing on ID stack
90 const NO_TREE_PUSH_ON_OPEN = sys::ImGuiTreeNodeFlags_NoTreePushOnOpen as i32;
91 /// Don't automatically and temporarily open node when Logging is active (by default logging will automatically open tree nodes)
92 const NO_AUTO_OPEN_ON_LOG = sys::ImGuiTreeNodeFlags_NoAutoOpenOnLog as i32;
93 /// Default node to be open
94 const DEFAULT_OPEN = sys::ImGuiTreeNodeFlags_DefaultOpen as i32;
95 /// Need double-click to open node
96 const OPEN_ON_DOUBLE_CLICK = sys::ImGuiTreeNodeFlags_OpenOnDoubleClick as i32;
97 /// Only open when clicking on the arrow part. If ImGuiTreeNodeFlags_OpenOnDoubleClick is also set, single-click arrow or double-click all box to open.
98 const OPEN_ON_ARROW = sys::ImGuiTreeNodeFlags_OpenOnArrow as i32;
99 /// No collapsing, no arrow (use as a convenience for leaf nodes)
100 const LEAF = sys::ImGuiTreeNodeFlags_Leaf as i32;
101 /// Display a bullet instead of arrow
102 const BULLET = sys::ImGuiTreeNodeFlags_Bullet as i32;
103 /// Use FramePadding (even for an unframed text node) to vertically align text baseline to regular widget height. Equivalent to calling AlignTextToFramePadding().
104 const FRAME_PADDING = sys::ImGuiTreeNodeFlags_FramePadding as i32;
105 /// Extend hit box to the right-most edge, even if not framed. This is not the default in order to allow adding other items on the same line. In the future we may refactor the hit system to be front-to-back, allowing natural overlaps and then this can become the default.
106 const SPAN_AVAIL_WIDTH = sys::ImGuiTreeNodeFlags_SpanAvailWidth as i32;
107 /// Extend hit box to the left-most and right-most edges (bypass the indented area).
108 const SPAN_FULL_WIDTH = sys::ImGuiTreeNodeFlags_SpanFullWidth as i32;
109 /// (WIP) Nav: left direction goes to parent. Only for the tree node, not the tree push.
110 const NAV_LEFT_JUMPS_BACK_HERE = sys::ImGuiTreeNodeFlags_NavLeftJumpsToParent as i32;
111 /// Combination of Leaf and NoTreePushOnOpen
112 const COLLAPSING_HEADER = Self::FRAMED.bits() | Self::NO_TREE_PUSH_ON_OPEN.bits();
113 }
114}
115
116bitflags::bitflags! {
117 /// Flags for combo box widgets
118 #[repr(transparent)]
119 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
120 pub struct ComboBoxFlags: i32 {
121 /// No flags
122 const NONE = 0;
123 /// Align the popup toward the left by default
124 const POPUP_ALIGN_LEFT = sys::ImGuiComboFlags_PopupAlignLeft as i32;
125 /// Max ~4 items visible. Tip: If you want your combo popup to be a specific size you can use SetNextWindowSizeConstraints() prior to calling BeginCombo()
126 const HEIGHT_SMALL = sys::ImGuiComboFlags_HeightSmall as i32;
127 /// Max ~8 items visible (default)
128 const HEIGHT_REGULAR = sys::ImGuiComboFlags_HeightRegular as i32;
129 /// Max ~20 items visible
130 const HEIGHT_LARGE = sys::ImGuiComboFlags_HeightLarge as i32;
131 /// As many fitting items as possible
132 const HEIGHT_LARGEST = sys::ImGuiComboFlags_HeightLargest as i32;
133 /// Display on the preview box without the square arrow button
134 const NO_ARROW_BUTTON = sys::ImGuiComboFlags_NoArrowButton as i32;
135 /// Display only a square arrow button
136 const NO_PREVIEW = sys::ImGuiComboFlags_NoPreview as i32;
137 /// Width dynamically calculated from preview contents
138 const WIDTH_FIT_PREVIEW = sys::ImGuiComboFlags_WidthFitPreview as i32;
139 }
140}
141
142bitflags::bitflags! {
143 /// Flags for table widgets
144 #[repr(transparent)]
145 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
146 pub struct TableFlags: i32 {
147 /// No flags
148 const NONE = 0;
149 /// Enable resizing columns
150 const RESIZABLE = sys::ImGuiTableFlags_Resizable as i32;
151 /// Enable reordering columns in header row (need calling TableSetupColumn() + TableHeadersRow() to display headers)
152 const REORDERABLE = sys::ImGuiTableFlags_Reorderable as i32;
153 /// Enable hiding/disabling columns in context menu
154 const HIDEABLE = sys::ImGuiTableFlags_Hideable as i32;
155 /// Enable sorting. Call TableGetSortSpecs() to obtain sort specs. Also see ImGuiTableFlags_SortMulti and ImGuiTableFlags_SortTristate.
156 const SORTABLE = sys::ImGuiTableFlags_Sortable as i32;
157 /// Disable persisting columns order, width and sort settings in the .ini file
158 const NO_SAVED_SETTINGS = sys::ImGuiTableFlags_NoSavedSettings as i32;
159 /// Right-click on columns body/contents will display table context menu. By default it is available in TableHeadersRow().
160 const CONTEXT_MENU_IN_BODY = sys::ImGuiTableFlags_ContextMenuInBody as i32;
161 /// Set each RowBg color with ImGuiCol_TableRowBg or ImGuiCol_TableRowBgAlt (equivalent of calling TableSetBgColor with ImGuiTableBgFlags_RowBg0 on each row manually)
162 const ROW_BG = sys::ImGuiTableFlags_RowBg as i32;
163 /// Draw horizontal borders between rows
164 const BORDERS_INNER_H = sys::ImGuiTableFlags_BordersInnerH as i32;
165 /// Draw horizontal borders at the top and bottom
166 const BORDERS_OUTER_H = sys::ImGuiTableFlags_BordersOuterH as i32;
167 /// Draw vertical borders between columns
168 const BORDERS_INNER_V = sys::ImGuiTableFlags_BordersInnerV as i32;
169 /// Draw vertical borders on the left and right sides
170 const BORDERS_OUTER_V = sys::ImGuiTableFlags_BordersOuterV as i32;
171 /// Draw horizontal borders
172 const BORDERS_H = Self::BORDERS_INNER_H.bits() | Self::BORDERS_OUTER_H.bits();
173 /// Draw vertical borders
174 const BORDERS_V = Self::BORDERS_INNER_V.bits() | Self::BORDERS_OUTER_V.bits();
175 /// Draw inner borders
176 const BORDERS_INNER = Self::BORDERS_INNER_V.bits() | Self::BORDERS_INNER_H.bits();
177 /// Draw outer borders
178 const BORDERS_OUTER = Self::BORDERS_OUTER_V.bits() | Self::BORDERS_OUTER_H.bits();
179 /// Draw all borders
180 const BORDERS = Self::BORDERS_INNER.bits() | Self::BORDERS_OUTER.bits();
181 /// [ALPHA] Disable vertical borders in columns Body (borders will always appears in Headers). -> May move to style
182 const NO_BORDERS_IN_BODY = sys::ImGuiTableFlags_NoBordersInBody as i32;
183 /// [ALPHA] Disable vertical borders in columns Body until hovered for resize (borders will always appears in Headers). -> May move to style
184 const NO_BORDERS_IN_BODY_UNTIL_RESIZE = sys::ImGuiTableFlags_NoBordersInBodyUntilResize as i32;
185 /// Columns default to _WidthFixed or _WidthAuto (if resizable or not resizable), matching contents width
186 const SIZING_FIXED_FIT = sys::ImGuiTableFlags_SizingFixedFit as i32;
187 /// Columns default to _WidthFixed or _WidthAuto (if resizable or not resizable), matching the maximum contents width of all columns. Implicitly enable ImGuiTableFlags_NoKeepColumnsVisible.
188 const SIZING_FIXED_SAME = sys::ImGuiTableFlags_SizingFixedSame as i32;
189 /// Columns default to _WidthStretch with default weights proportional to each columns contents widths.
190 const SIZING_STRETCH_PROP = sys::ImGuiTableFlags_SizingStretchProp as i32;
191 /// Columns default to _WidthStretch with default weights all equal, unless overridden by TableSetupColumn().
192 const SIZING_STRETCH_SAME = sys::ImGuiTableFlags_SizingStretchSame as i32;
193 /// Make outer width auto-fit to columns, overriding outer_size.x value. Only available when ScrollX/ScrollY are disabled and Stretch columns are not used.
194 const NO_HOST_EXTEND_X = sys::ImGuiTableFlags_NoHostExtendX as i32;
195 /// Make outer height stop exactly at outer_size.y (prevent auto-extending table past the limit). Only available when ScrollX/ScrollY are disabled. Data below the limit will be clipped and not visible.
196 const NO_HOST_EXTEND_Y = sys::ImGuiTableFlags_NoHostExtendY as i32;
197 /// Disable keeping column always minimally visible when ScrollX is on and table gets too small. Not recommended if columns are resizable.
198 const NO_KEEP_COLUMNS_VISIBLE = sys::ImGuiTableFlags_NoKeepColumnsVisible as i32;
199 /// Disable distributing remainder width to stretched columns (width allocation on a 100-wide table with 3 columns: Without this flag: 33,33,34. With this flag: 33,33,33). With larger number of columns, resizing will appear to be less smooth.
200 const PRECISE_WIDTHS = sys::ImGuiTableFlags_PreciseWidths as i32;
201 /// Disable clipping rectangle for every individual columns (reduce draw command count, items will be able to overflow into other columns). Generally incompatible with TableSetupScrollFreeze().
202 const NO_CLIP = sys::ImGuiTableFlags_NoClip as i32;
203 /// Default if BordersOuterV is on. Enable outer-most padding. Generally desirable if you have headers.
204 const PAD_OUTER_X = sys::ImGuiTableFlags_PadOuterX as i32;
205 /// Default if BordersOuterV is off. Disable outer-most padding.
206 const NO_PAD_OUTER_X = sys::ImGuiTableFlags_NoPadOuterX as i32;
207 /// Disable inner padding between columns (double inner padding if BordersOuterV is on, single inner padding if BordersOuterV is off).
208 const NO_PAD_INNER_X = sys::ImGuiTableFlags_NoPadInnerX as i32;
209 /// Enable horizontal scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size. Changes default sizing policy. Because this creates a child window, ScrollY is currently generally recommended when using ScrollX.
210 const SCROLL_X = sys::ImGuiTableFlags_ScrollX as i32;
211 /// Enable vertical scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size.
212 const SCROLL_Y = sys::ImGuiTableFlags_ScrollY as i32;
213 /// Hold shift when clicking headers to sort on multiple column. TableGetSortSpecs() may return specs where (SpecsCount > 1).
214 const SORT_MULTI = sys::ImGuiTableFlags_SortMulti as i32;
215 /// Allow no sorting, disable default sorting. TableGetSortSpecs() may return specs where (SpecsCount == 0).
216 const SORT_TRISTATE = sys::ImGuiTableFlags_SortTristate as i32;
217 /// Highlight column headers when hovered (may not be visible if table header is declaring a background color)
218 const HIGHLIGHT_HOVERED_COLUMN = sys::ImGuiTableFlags_HighlightHoveredColumn as i32;
219 }
220}
221
222bitflags::bitflags! {
223 /// Flags for table columns
224 #[repr(transparent)]
225 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
226 pub struct TableColumnFlags: i32 {
227 /// No flags
228 const NONE = 0;
229 /// Overriding width becomes fixed width
230 const WIDTH_FIXED = sys::ImGuiTableColumnFlags_WidthFixed as i32;
231 /// Overriding width becomes weight
232 const WIDTH_STRETCH = sys::ImGuiTableColumnFlags_WidthStretch as i32;
233 /// Disable manual resizing
234 const NO_RESIZE = sys::ImGuiTableColumnFlags_NoResize as i32;
235 /// Disable manual reordering this column
236 const NO_REORDER = sys::ImGuiTableColumnFlags_NoReorder as i32;
237 /// Disable ability to hide/disable this column
238 const NO_HIDE = sys::ImGuiTableColumnFlags_NoHide as i32;
239 /// Disable clipping for this column
240 const NO_CLIP = sys::ImGuiTableColumnFlags_NoClip as i32;
241 /// Disable ability to sort on this field
242 const NO_SORT = sys::ImGuiTableColumnFlags_NoSort as i32;
243 /// Disable ability to sort in the ascending direction
244 const NO_SORT_ASCENDING = sys::ImGuiTableColumnFlags_NoSortAscending as i32;
245 /// Disable ability to sort in the descending direction
246 const NO_SORT_DESCENDING = sys::ImGuiTableColumnFlags_NoSortDescending as i32;
247 /// TableHeadersRow() will not submit label for this column
248 const NO_HEADER_LABEL = sys::ImGuiTableColumnFlags_NoHeaderLabel as i32;
249 /// Disable header text width contribution to automatic column width
250 const NO_HEADER_WIDTH = sys::ImGuiTableColumnFlags_NoHeaderWidth as i32;
251 /// Make the initial sort direction Ascending when first sorting on this column
252 const PREFER_SORT_ASCENDING = sys::ImGuiTableColumnFlags_PreferSortAscending as i32;
253 /// Make the initial sort direction Descending when first sorting on this column
254 const PREFER_SORT_DESCENDING = sys::ImGuiTableColumnFlags_PreferSortDescending as i32;
255 /// Use current Indent value when entering cell
256 const INDENT_ENABLE = sys::ImGuiTableColumnFlags_IndentEnable as i32;
257 /// Disable indenting for this column
258 const INDENT_DISABLE = sys::ImGuiTableColumnFlags_IndentDisable as i32;
259 /// Display an angled header for this column (when angled headers feature is enabled)
260 const ANGLED_HEADER = sys::ImGuiTableColumnFlags_AngledHeader as i32;
261 /// Status: is enabled == not hidden
262 const IS_ENABLED = sys::ImGuiTableColumnFlags_IsEnabled as i32;
263 /// Status: is visible == is enabled AND not clipped by scrolling
264 const IS_VISIBLE = sys::ImGuiTableColumnFlags_IsVisible as i32;
265 /// Status: is currently part of the sort specs
266 const IS_SORTED = sys::ImGuiTableColumnFlags_IsSorted as i32;
267 /// Status: is hovered by mouse
268 const IS_HOVERED = sys::ImGuiTableColumnFlags_IsHovered as i32;
269 }
270}