-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
47 lines (42 loc) · 1.14 KB
/
mod.rs
File metadata and controls
47 lines (42 loc) · 1.14 KB
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
pub mod button;
pub mod checkbox;
pub mod file_picker;
pub mod label;
pub mod menu_bar;
pub mod panel;
pub mod scroll_bar;
pub mod slider;
pub mod tab_bar;
use libgfx::color::Color;
use libgfx::framebuf::FrameBuf;
use libgfx::shapes;
use crate::input::{InputState, WidgetEvent};
use crate::rect::Rect;
use crate::theme::Theme;
/// Optional trait for uniform widget handling.
pub trait Widget {
fn rect(&self) -> Rect;
fn draw(&self, fb: &mut FrameBuf, theme: &Theme);
fn update(&mut self, input: &InputState) -> WidgetEvent;
}
/// Draw a filled background for a widget, selecting color based on hover/pressed state.
pub fn draw_widget_bg(
fb: &mut FrameBuf,
rect: &Rect,
theme: &Theme,
hovered: bool,
pressed: bool,
) {
let bg = if pressed {
theme.widget_bg_active
} else if hovered {
theme.widget_bg_hover
} else {
theme.widget_bg
};
shapes::fill_rect(fb, rect.x, rect.y, rect.w, rect.h, bg);
}
/// Draw a border around a widget rectangle.
pub fn draw_widget_border(fb: &mut FrameBuf, rect: &Rect, color: Color) {
shapes::draw_rect(fb, rect.x, rect.y, rect.w, rect.h, color);
}