Skip to main content

dear_imgui_rs/layout/
spacing.rs

1use super::validation::{assert_finite_f32, assert_finite_vec2};
2use crate::Ui;
3use crate::sys;
4
5impl Ui {
6    /// Call between widgets or groups to layout them horizontally.
7    ///
8    /// X position is given in window coordinates.
9    ///
10    /// This is equivalent to calling [same_line_with_pos](Self::same_line_with_pos)
11    /// with the `pos` set to 0.0, which uses `Style::item_spacing`.
12    #[doc(alias = "SameLine")]
13    pub fn same_line(&self) {
14        self.same_line_with_pos(0.0);
15    }
16
17    /// Call between widgets or groups to layout them horizontally.
18    ///
19    /// X position is given in window coordinates.
20    ///
21    /// This is equivalent to calling [same_line_with_spacing](Self::same_line_with_spacing)
22    /// with the `spacing` set to -1.0, which means no extra spacing.
23    #[doc(alias = "SameLine")]
24    pub fn same_line_with_pos(&self, pos_x: f32) {
25        self.same_line_with_spacing(pos_x, -1.0)
26    }
27
28    /// Call between widgets or groups to layout them horizontally.
29    ///
30    /// X position is given in window coordinates.
31    #[doc(alias = "SameLine")]
32    pub fn same_line_with_spacing(&self, pos_x: f32, spacing_w: f32) {
33        assert_finite_f32("Ui::same_line_with_spacing()", "pos_x", pos_x);
34        assert_finite_f32("Ui::same_line_with_spacing()", "spacing_w", spacing_w);
35        self.run_with_bound_context(|| unsafe { sys::igSameLine(pos_x, spacing_w) });
36    }
37
38    /// Undo a `same_line` call or force a new line when in horizontal layout mode
39    #[doc(alias = "NewLine")]
40    pub fn new_line(&self) {
41        self.run_with_bound_context(|| unsafe { sys::igNewLine() });
42    }
43
44    /// Adds vertical spacing
45    #[doc(alias = "Spacing")]
46    pub fn spacing(&self) {
47        self.run_with_bound_context(|| unsafe { sys::igSpacing() });
48    }
49
50    /// Fills a space of `size` in pixels with nothing on the current window.
51    ///
52    /// Can be used to move the cursor on the window.
53    #[doc(alias = "Dummy")]
54    pub fn dummy(&self, size: impl Into<[f32; 2]>) {
55        let size = size.into();
56        assert_finite_vec2("Ui::dummy()", "size", size);
57        let size_vec: sys::ImVec2 = size.into();
58        self.run_with_bound_context(|| unsafe { sys::igDummy(size_vec) });
59    }
60
61    /// Moves content position to the right by `Style::indent_spacing`
62    ///
63    /// This is equivalent to [indent_by](Self::indent_by) with `width` set to
64    /// `Style::indent_spacing`.
65    #[doc(alias = "Indent")]
66    pub fn indent(&self) {
67        self.indent_by(0.0)
68    }
69
70    /// Moves content position to the right by `width`
71    #[doc(alias = "Indent")]
72    pub fn indent_by(&self, width: f32) {
73        assert_finite_f32("Ui::indent_by()", "width", width);
74        self.run_with_bound_context(|| unsafe { sys::igIndent(width) });
75    }
76
77    /// Moves content position to the left by `Style::indent_spacing`
78    ///
79    /// This is equivalent to [unindent_by](Self::unindent_by) with `width` set to
80    /// `Style::indent_spacing`.
81    #[doc(alias = "Unindent")]
82    pub fn unindent(&self) {
83        self.unindent_by(0.0)
84    }
85
86    /// Moves content position to the left by `width`
87    #[doc(alias = "Unindent")]
88    pub fn unindent_by(&self, width: f32) {
89        assert_finite_f32("Ui::unindent_by()", "width", width);
90        self.run_with_bound_context(|| unsafe { sys::igUnindent(width) });
91    }
92}
93
94impl Ui {
95    /// Vertically align upcoming text baseline to FramePadding.y (align text to framed items).
96    #[doc(alias = "AlignTextToFramePadding")]
97    pub fn align_text_to_frame_padding(&self) {
98        self.run_with_bound_context(|| unsafe { sys::igAlignTextToFramePadding() });
99    }
100}