Skip to main content

grafix_toolbox/gui/
elements.rs

1pub use {button::*, hypertext::*, label::*, layout::*, lineedit::*, selector::*, slider::*, slidernum::*, textedit::*};
2
3#[derive(Default, Debug)]
4pub struct Theme {
5	pub easing: f32,
6	pub bg: Color,
7	pub bg_focus: Color,
8	pub fg: Color,
9	pub fg_focus: Color,
10	pub highlight: Color,
11	pub text: Color,
12	pub text_focus: Color,
13	pub text_highlight: Color,
14	pub font: Arc<Font>,
15	pub font_size: f32,
16}
17impl Theme {
18	pub fn ease(&self, easing: &mut f32, increase: bool) {
19		let delta = 1. / (self.easing * (*easing - 2.).abs());
20		*easing = (*easing + delta.or_val(increase, || -delta)).clamp(0., 1.)
21	}
22	pub fn fg<A, B>(&self, focus: A, highlight: B) -> Color
23	where
24		f32: Cast<A>,
25		f32: Cast<B>,
26	{
27		let (f, h) = Vec2((focus, highlight));
28		self.fg.mix(self.fg_focus, f).mix(self.highlight, h)
29	}
30	pub fn text<A, B>(&self, focus: A, highlight: B) -> Color
31	where
32		f32: Cast<A>,
33		f32: Cast<B>,
34	{
35		let (f, h) = Vec2((focus, highlight));
36		self.text.mix(self.text_focus, f).mix(self.text_highlight, h)
37	}
38}
39
40pub fn NumericOnly() -> &'static HashSet<char> {
41	LocalStatic!(HashSet<char>, { HashSet::from(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '+', '.', 'e']) })
42}
43
44mod button;
45mod hypertext;
46mod label;
47mod layout;
48mod lineedit;
49mod selector;
50mod slider;
51mod slidernum;
52mod textedit;
53mod util;
54
55macro_rules! element_lock {
56	($($t: ident),+) => {
57		pub(super) mod Lock {
58			#![allow(dead_code)]
59			$(impl super::$t {
60				pub fn lock<'s, 'l: 'a, 'a>(&'s mut self, r: &'a mut RenderLock<'l>) -> $t<'s, 'l, 'a>
61				{
62					let t = r.theme();
63					$t { s: self, r, t }
64				}
65			}
66			pub struct $t<'s, 'l: 'a, 'a> {
67				pub(super) s: &'s mut super::$t,
68				pub(super) r: &'a mut RenderLock<'l>,
69				pub(super) t: &'l Theme,
70			})+
71			use super::*;
72		}
73	};
74}
75element_lock!(Button, HyperText, Label, Layout, LineEdit, Selector, Slider, SliderNum, TextEdit);
76
77use {super::*, util as u};