arcdps_imgui/
layout.rs

1use crate::sys;
2use crate::Ui;
3
4create_token!(
5    /// Tracks a layout group that can be ended with `end` or by dropping.
6    pub struct GroupToken<'ui>;
7
8    /// Drops the layout group manually. You can also just allow this token
9    /// to drop on its own.
10    drop { sys::igEndGroup() }
11);
12
13/// # Cursor / Layout
14impl<'ui> Ui<'ui> {
15    /// Renders a separator (generally horizontal).
16    ///
17    /// This becomes a vertical separator inside a menu bar or in horizontal layout mode.
18    #[doc(alias = "Separator")]
19    pub fn separator(&self) {
20        unsafe { sys::igSeparator() }
21    }
22
23    /// Call between widgets or groups to layout them horizontally.
24    ///
25    /// X position is given in window coordinates.
26    ///
27    /// This is equivalent to calling [same_line_with_pos](Self::same_line_with_pos)
28    /// with the `pos` set to 0.0, which uses `Style::item_spacing`.
29    #[doc(alias = "SameLine")]
30    pub fn same_line(&self) {
31        self.same_line_with_pos(0.0);
32    }
33
34    /// Call between widgets or groups to layout them horizontally.
35    ///
36    /// X position is given in window coordinates.
37    ///
38    /// This is equivalent to calling [same_line_with_spacing](Self::same_line_with_spacing)
39    /// with the `spacing` set to -1.0, which means no extra spacing.
40    #[doc(alias = "SameLine")]
41    pub fn same_line_with_pos(&self, pos_x: f32) {
42        self.same_line_with_spacing(pos_x, -1.0)
43    }
44
45    /// Call between widgets or groups to layout them horizontally.
46    ///
47    /// X position is given in window coordinates.
48    #[doc(alias = "SameLine")]
49    pub fn same_line_with_spacing(&self, pos_x: f32, spacing_w: f32) {
50        unsafe { sys::igSameLine(pos_x, spacing_w) }
51    }
52
53    /// Undo a `same_line` call or force a new line when in horizontal layout mode
54    #[doc(alias = "NewLine")]
55    pub fn new_line(&self) {
56        unsafe { sys::igNewLine() }
57    }
58    /// Adds vertical spacing
59    #[doc(alias = "Spacing")]
60    pub fn spacing(&self) {
61        unsafe { sys::igSpacing() }
62    }
63    /// Fills a space of `size` in pixels with nothing on the current window.
64    ///
65    /// Can be used to move the cursor on the window.
66    #[doc(alias = "Dummy")]
67    pub fn dummy(&self, size: [f32; 2]) {
68        unsafe { sys::igDummy(size.into()) }
69    }
70
71    /// Moves content position to the right by `Style::indent_spacing`
72    ///
73    /// This is equivalent to [indent_by](Self::indent_by) with `width` set to
74    /// `Style::ident_spacing`.
75    #[doc(alias = "Indent")]
76    pub fn indent(&self) {
77        self.indent_by(0.0)
78    }
79
80    /// Moves content position to the right by `width`
81    #[doc(alias = "Indent")]
82    pub fn indent_by(&self, width: f32) {
83        unsafe { sys::igIndent(width) };
84    }
85    /// Moves content position to the left by `Style::indent_spacing`
86    ///
87    /// This is equivalent to [unindent_by](Self::unindent_by) with `width` set to
88    /// `Style::ident_spacing`.
89    #[doc(alias = "Unindent")]
90    pub fn unindent(&self) {
91        self.unindent_by(0.0)
92    }
93    /// Moves content position to the left by `width`
94    #[doc(alias = "Unindent")]
95    pub fn unindent_by(&self, width: f32) {
96        unsafe { sys::igUnindent(width) };
97    }
98    /// Groups items together as a single item.
99    ///
100    /// May be useful to handle the same mouse event on a group of items, for example.
101    ///
102    /// Returns a `GroupToken` that must be ended by calling `.end()`
103    #[doc(alias = "BeginGroup")]
104    pub fn begin_group(&self) -> GroupToken<'_> {
105        unsafe { sys::igBeginGroup() };
106        GroupToken::new(self)
107    }
108    /// Creates a layout group and runs a closure to construct the contents.
109    ///
110    /// May be useful to handle the same mouse event on a group of items, for example.
111    #[doc(alias = "BeginGroup")]
112    pub fn group<R, F: FnOnce() -> R>(&self, f: F) -> R {
113        let group = self.begin_group();
114        let result = f();
115        group.end();
116        result
117    }
118    /// Returns the cursor position (in window coordinates)
119    #[doc(alias = "GetCursorPos")]
120    pub fn cursor_pos(&self) -> [f32; 2] {
121        let mut out = sys::ImVec2::zero();
122        unsafe { sys::igGetCursorPos(&mut out) };
123        out.into()
124    }
125    /// Sets the cursor position (in window coordinates).
126    ///
127    /// This sets the point on which the next widget will be drawn.
128    #[doc(alias = "SetCursorPos")]
129    pub fn set_cursor_pos(&self, pos: [f32; 2]) {
130        unsafe { sys::igSetCursorPos(pos.into()) };
131    }
132    /// Returns the initial cursor position (in window coordinates)
133    #[doc(alias = "GetCursorStartPos")]
134    pub fn cursor_start_pos(&self) -> [f32; 2] {
135        let mut out = sys::ImVec2::zero();
136        unsafe { sys::igGetCursorStartPos(&mut out) };
137        out.into()
138    }
139    /// Returns the cursor position (in absolute screen coordinates).
140    ///
141    /// This is especially useful for drawing, as the drawing API uses screen coordinates.
142    #[doc(alias = "GetCursorScreenPos")]
143    pub fn cursor_screen_pos(&self) -> [f32; 2] {
144        let mut out = sys::ImVec2::zero();
145        unsafe { sys::igGetCursorScreenPos(&mut out) };
146        out.into()
147    }
148    /// Sets the cursor position (in absolute screen coordinates)
149    #[doc(alias = "SetCursorScreenPos")]
150    pub fn set_cursor_screen_pos(&self, pos: [f32; 2]) {
151        unsafe { sys::igSetCursorScreenPos(pos.into()) }
152    }
153    /// Vertically aligns text baseline so that it will align properly to regularly frame items.
154    ///
155    /// Call this if you have text on a line before a framed item.
156    #[doc(alias = "AlignTextToFramePadding")]
157    pub fn align_text_to_frame_padding(&self) {
158        unsafe { sys::igAlignTextToFramePadding() };
159    }
160    #[doc(alias = "GetTextLineHeight")]
161    pub fn text_line_height(&self) -> f32 {
162        unsafe { sys::igGetTextLineHeight() }
163    }
164    #[doc(alias = "GetTextLineHeightWithSpacing")]
165    pub fn text_line_height_with_spacing(&self) -> f32 {
166        unsafe { sys::igGetTextLineHeightWithSpacing() }
167    }
168    #[doc(alias = "GetFrameHeight")]
169    pub fn frame_height(&self) -> f32 {
170        unsafe { sys::igGetFrameHeight() }
171    }
172    #[doc(alias = "GetFrameLineHeightWithSpacing")]
173    pub fn frame_height_with_spacing(&self) -> f32 {
174        unsafe { sys::igGetFrameHeightWithSpacing() }
175    }
176}