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
use crate::prelude::*;
pub struct TheSectionbar {
id: TheId,
limiter: TheSizeLimiter,
dim: TheDim,
is_dirty: bool,
}
impl TheWidget for TheSectionbar {
fn new(id: TheId) -> Self
where
Self: Sized,
{
let mut limiter = TheSizeLimiter::new();
limiter.set_max_height(21);
Self {
id,
limiter,
dim: TheDim::zero(),
is_dirty: false,
}
}
fn id(&self) -> &TheId {
&self.id
}
// fn on_event(&mut self, event: &TheEvent, ctx: &mut TheContext) -> bool {
// false
// }
fn dim(&self) -> &TheDim {
&self.dim
}
fn dim_mut(&mut self) -> &mut TheDim {
&mut self.dim
}
fn set_dim(&mut self, dim: TheDim, _ctx: &mut TheContext) {
if self.dim != dim {
self.dim = dim;
self.is_dirty = true;
}
}
fn limiter(&self) -> &TheSizeLimiter {
&self.limiter
}
fn limiter_mut(&mut self) -> &mut TheSizeLimiter {
&mut self.limiter
}
fn needs_redraw(&mut self) -> bool {
self.is_dirty
}
fn draw(
&mut self,
buffer: &mut TheRGBABuffer,
style: &mut Box<dyn TheStyle>,
ctx: &mut TheContext,
) {
if !self.dim().is_valid() {
return;
}
let stride = buffer.stride();
let utuple: (usize, usize, usize, usize) = self.dim.to_buffer_utuple();
ctx.draw.rect_outline(
buffer.pixels_mut(),
&utuple,
stride,
style.theme().color(SwitchbarBorder),
);
if let Some(icon) = ctx.ui.icon("dark_sectionbar") {
for x in 1..utuple.2 - 1 {
let r = (utuple.0 + x, utuple.1, 1, icon.dim().height as usize);
ctx.draw
.copy_slice(buffer.pixels_mut(), icon.pixels(), &r, stride);
}
}
self.is_dirty = false;
// if let Some(icon) = ctx.ui.icon("switchbar_icon") {
// let r = (utuple.0 + 6, utuple.1 + 6, icon.1 as usize, icon.2 as usize);
// ctx.draw
// .blend_slice(buffer.pixels_mut(), &icon.0, &r, stride);
// }
// let mut shrinker = TheDimShrinker::zero();
// shrinker.shrink_by(30, 1, 0, 0);
// if let Some(font) = &ctx.ui.font {
// ctx.draw.text_rect_blend(
// buffer.pixels_mut(),
// &self.dim.to_buffer_shrunk_utuple(&shrinker),
// stride,
// font,
// 15.0,
// &self.id().name,
// &WHITE,
// TheHorizontalAlign::Left,
// TheVerticalAlign::Center,
// );
// }
}
fn as_any(&mut self) -> &mut dyn std::any::Any {
self
}
}