tirbofish/dropbear
main / crates / kino-ui / src / widgets / mod.rs · 2898 bytes
crates/kino-ui/src/widgets/mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
pub mod layout;
pub mod rect;
pub mod shorthand;
pub mod text;
use crate::{KinoState, UiNode, WidgetId};
use glam::Vec2;
use std::any::Any;
/// Determines how the object is anchored.
#[derive(Clone)]
#[cfg_attr(any(feature = "ser"), derive(serde::Serialize, serde::Deserialize))]
pub enum Anchor {
/// A center anchor is when the position is based on the center of the object (such as the
/// center of a circle)
Center,
/// A top left anchor is when the position is based on the top left corner of the rectangle.
TopLeft,
}
/// Defines a widget with no children.
pub trait NativeWidget: Send + Sync {
/// Renders the widget.
///
/// The state is provided for you to manipulate, such as adding a new response based on the
/// [`WidgetId`].
fn render(self: Box<Self>, state: &mut KinoState);
fn size(&self) -> Vec2;
fn id(&self) -> WidgetId;
fn as_any(&self) -> &dyn Any;
}
pub trait ContaineredWidget: Send + Sync {
fn render(self: Box<Self>, children: Vec<UiNode>, state: &mut KinoState);
fn size(&self, children: &[UiNode]) -> Vec2;
fn id(&self) -> WidgetId;
fn as_any(&self) -> &dyn Any;
}
/// Describes the colour that the widget will be filled in with.
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(any(feature = "ser"), derive(serde::Serialize, serde::Deserialize))]
pub struct Fill {
/// The colour of the fill described as RGBA between the range `0.0` <-> `1.0`.
///
/// If a texture is applied to the colour, it will create a tinted texture on the quad.
pub colour: [f32; 4],
}
impl Fill {
/// Creates a new [`Fill`]
pub fn new(colour: [f32; 4]) -> Self {
Fill { colour }
}
}
impl Default for Fill {
fn default() -> Self {
Fill {
colour: [1.0, 1.0, 1.0, 1.0],
}
}
}
/// Describes the properties of the border/stroke of the widget.
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(any(feature = "ser"), derive(serde::Serialize, serde::Deserialize))]
pub struct Border {
/// The colour of the border described as RGBA between the range `0.0` <-> `1.0`.
pub colour: [f32; 4],
/// The width of the border.
pub width: f32,
}
impl Border {
/// Creates a new [`Border`].
pub fn new(colour: [f32; 4], width: f32) -> Self {
Self { colour, width }
}
}
/// States the different types of widgets.
///
/// Also serves as a little task checklist for this library.
///
/// Also it was ripped from the egui library.
pub enum WidgetType {
Label,
TextEdit,
Button,
Checkbox,
RadioButton,
SelectableLabel,
ComboBox,
Slider,
DragValue,
ColourButton,
Image,
CollapsingHeader,
Panel,
ProgressIndicator,
/// If you cannot fit any of the above slots.
///
/// If this is something you think should be added, file an issue.
Other,
}