1use crate::PopupPlacement;
2use std::cell::Cell;
3
4thread_local! {
5 static NEXT_TOOL_TIP_ID: Cell<u64> = const { Cell::new(1) };
6}
7
8fn next_tool_tip_id() -> u64 {
9 NEXT_TOOL_TIP_ID.with(|slot| {
10 let id = slot.get();
11 slot.set(id.wrapping_add(1).max(1));
12 id
13 })
14}
15
16#[derive(Clone, Debug)]
17pub struct ToolTip {
18 id: u64,
19 text_value: String,
20 initial_show_delay_ms: i32,
21 between_show_delay_ms: i32,
22 show_duration_ms: i32,
23 placement: PopupPlacement,
24 horizontal_offset: f32,
25 vertical_offset: f32,
26 open_on_focus: bool,
27 panel_background_color: u32,
28 text_color: u32,
29 panel_background_overridden: bool,
30 text_color_overridden: bool,
31}
32
33impl Default for ToolTip {
34 fn default() -> Self {
35 Self {
36 id: next_tool_tip_id(),
37 text_value: String::new(),
38 initial_show_delay_ms: 700,
39 between_show_delay_ms: 100,
40 show_duration_ms: 5000,
41 placement: PopupPlacement::Top,
42 horizontal_offset: 0.0,
43 vertical_offset: 0.0,
44 open_on_focus: true,
45 panel_background_color: 0,
46 text_color: 0,
47 panel_background_overridden: false,
48 text_color_overridden: false,
49 }
50 }
51}
52
53impl PartialEq for ToolTip {
54 fn eq(&self, other: &Self) -> bool {
55 self.id == other.id
56 }
57}
58
59impl ToolTip {
60 pub fn new() -> Self {
61 Self::default()
62 }
63
64 pub fn text(value: impl Into<String>) -> Self {
65 Self::new().with_text(value)
66 }
67
68 pub fn with_text(mut self, value: impl Into<String>) -> Self {
69 self.text_value = value.into();
70 self
71 }
72
73 pub fn content_text(&self) -> &str {
74 &self.text_value
75 }
76
77 pub fn initial_show_delay(mut self, value: i32) -> Self {
78 self.initial_show_delay_ms = value.max(0);
79 self
80 }
81
82 pub fn initial_show_delay_ms(&self) -> i32 {
83 self.initial_show_delay_ms
84 }
85
86 pub fn between_show_delay(mut self, value: i32) -> Self {
87 self.between_show_delay_ms = value.max(0);
88 self
89 }
90
91 pub fn between_show_delay_ms(&self) -> i32 {
92 self.between_show_delay_ms
93 }
94
95 pub fn show_duration(mut self, value: i32) -> Self {
96 self.show_duration_ms = value.max(0);
97 self
98 }
99
100 pub fn show_duration_ms(&self) -> i32 {
101 self.show_duration_ms
102 }
103
104 pub fn placement(mut self, value: PopupPlacement) -> Self {
105 self.placement = value;
106 self
107 }
108
109 pub fn popup_placement(&self) -> PopupPlacement {
110 self.placement
111 }
112
113 pub fn horizontal_offset(mut self, value: f32) -> Self {
114 self.horizontal_offset = value;
115 self
116 }
117
118 pub fn horizontal_offset_px(&self) -> f32 {
119 self.horizontal_offset
120 }
121
122 pub fn vertical_offset(mut self, value: f32) -> Self {
123 self.vertical_offset = value;
124 self
125 }
126
127 pub fn vertical_offset_px(&self) -> f32 {
128 self.vertical_offset
129 }
130
131 pub fn open_on_focus(mut self, flag: bool) -> Self {
132 self.open_on_focus = flag;
133 self
134 }
135
136 pub fn opens_on_focus(&self) -> bool {
137 self.open_on_focus
138 }
139
140 pub fn panel_color(mut self, color: u32) -> Self {
141 self.panel_background_overridden = true;
142 self.panel_background_color = color;
143 self
144 }
145
146 pub fn has_panel_color_override(&self) -> bool {
147 self.panel_background_overridden
148 }
149
150 pub fn panel_background_color(&self) -> u32 {
151 self.panel_background_color
152 }
153
154 pub fn text_color(mut self, color: u32) -> Self {
155 self.text_color_overridden = true;
156 self.text_color = color;
157 self
158 }
159
160 pub fn has_text_color_override(&self) -> bool {
161 self.text_color_overridden
162 }
163
164 pub fn tooltip_text_color(&self) -> u32 {
165 self.text_color
166 }
167}