Skip to main content

dear_imgui_rs/style/
tree.rs

1#![allow(
2    clippy::cast_possible_truncation,
3    clippy::cast_sign_loss,
4    clippy::as_conversions
5)]
6
7use super::Style;
8use super::validation::assert_non_negative_f32;
9use crate::sys;
10
11/// Tree hierarchy guide-line drawing mode stored in `ImGuiStyle::TreeLinesFlags`.
12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
13pub struct TreeLineMode(i32);
14
15impl TreeLineMode {
16    /// No tree hierarchy guide lines are drawn.
17    pub const NONE: Self = Self(sys::ImGuiTreeNodeFlags_DrawLinesNone as i32);
18    /// Draw full tree hierarchy guide lines.
19    pub const FULL: Self = Self(sys::ImGuiTreeNodeFlags_DrawLinesFull as i32);
20    /// Draw tree hierarchy guide lines only to nodes.
21    pub const TO_NODES: Self = Self(sys::ImGuiTreeNodeFlags_DrawLinesToNodes as i32);
22
23    #[inline]
24    pub const fn bits(self) -> i32 {
25        self.0
26    }
27
28    #[inline]
29    pub(crate) const fn from_bits_retain(bits: i32) -> Self {
30        Self(bits)
31    }
32
33    #[inline]
34    pub(crate) fn validate(self, caller: &str) {
35        assert!(
36            matches!(self, Self::NONE | Self::FULL | Self::TO_NODES),
37            "{caller} accepts only TreeLineMode::NONE, FULL, or TO_NODES"
38        );
39    }
40}
41
42impl Style {
43    pub fn tree_lines_mode(&self) -> TreeLineMode {
44        TreeLineMode::from_bits_retain(self.inner().TreeLinesFlags as i32)
45    }
46
47    pub fn set_tree_lines_mode(&mut self, mode: TreeLineMode) {
48        mode.validate("Style::set_tree_lines_mode()");
49        self.inner_mut().TreeLinesFlags = mode.bits() as sys::ImGuiTreeNodeFlags;
50    }
51
52    pub fn tree_lines_size(&self) -> f32 {
53        self.inner().TreeLinesSize
54    }
55    pub fn set_tree_lines_size(&mut self, v: f32) {
56        assert_non_negative_f32("Style::set_tree_lines_size()", "v", v);
57        self.inner_mut().TreeLinesSize = v;
58    }
59
60    pub fn tree_lines_rounding(&self) -> f32 {
61        self.inner().TreeLinesRounding
62    }
63    pub fn set_tree_lines_rounding(&mut self, v: f32) {
64        assert_non_negative_f32("Style::set_tree_lines_rounding()", "v", v);
65        self.inner_mut().TreeLinesRounding = v;
66    }
67}