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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
use crate::prelude::*;
pub struct TheTreeItem {
id: TheId,
limiter: TheSizeLimiter,
state: TheWidgetState,
text: String,
sub_text: String,
dim: TheDim,
is_dirty: bool,
mouse_down_pos: Vec2<i32>,
mouse_down_in_widget: bool,
icon: Option<TheRGBABuffer>,
status: Option<String>,
layout_id: TheId,
scroll_offset: i32,
values: Vec<(i32, TheValue)>,
widget_column: Option<(i32, Box<dyn TheWidget>)>,
context_menu: Option<TheContextMenu>,
cursor_icon: Option<TheCursorIcon>,
background: Option<TheColor>,
}
impl TheWidget for TheTreeItem {
fn new(id: TheId) -> Self
where
Self: Sized,
{
let mut limiter = TheSizeLimiter::new();
limiter.set_max_height(22);
Self {
id,
limiter,
state: TheWidgetState::None,
text: "".to_string(),
sub_text: "".to_string(),
dim: TheDim::zero(),
is_dirty: true,
mouse_down_pos: Vec2::zero(),
mouse_down_in_widget: false,
icon: None,
status: None,
layout_id: TheId::empty(),
scroll_offset: 0,
values: Vec::new(),
widget_column: None,
context_menu: None,
cursor_icon: None,
background: None,
}
}
fn id(&self) -> &TheId {
&self.id
}
fn set_context_menu(&mut self, menu: Option<TheContextMenu>) {
self.context_menu = menu;
}
fn on_event(&mut self, event: &TheEvent, ctx: &mut TheContext) -> bool {
let mut redraw = false;
match event {
TheEvent::Context(coord) => {
if let Some(context_menu) = &self.context_menu {
ctx.ui.send(TheEvent::ShowContextMenu(
self.id().clone(),
*coord,
context_menu.clone(),
));
ctx.ui.set_focus(self.id());
redraw = true;
self.is_dirty = true;
}
}
TheEvent::MouseDown(coord) => {
if self.state != TheWidgetState::Selected || !self.id().equals(&ctx.ui.focus) {
self.is_dirty = true;
self.state = TheWidgetState::Selected;
ctx.ui.send_widget_state_changed(self.id(), self.state);
ctx.ui.send(TheEvent::NewListItemSelected(
self.id().clone(),
self.layout_id.clone(),
));
redraw = true;
}
ctx.ui.set_focus(self.id());
// Track if mouse down happened in embedded widget
self.mouse_down_in_widget = false;
if let Some((_width, w)) = &mut self.widget_column {
let dim = w.dim();
let widget_coord =
Vec2::new(coord.x - dim.x, coord.y - dim.y + self.scroll_offset);
// Check if the click is within the embedded widget bounds
if widget_coord.x >= 0
&& widget_coord.y >= 0
&& widget_coord.x < dim.width
&& widget_coord.y < dim.height
{
self.mouse_down_in_widget = true;
redraw = w.on_event(&TheEvent::MouseDown(widget_coord), ctx);
}
}
self.mouse_down_pos = Vec2::new(coord.x, coord.y + self.scroll_offset);
}
TheEvent::MouseUp(coord) => {
// If mouse down was in widget, forward mouse up (even if outside bounds)
if self.mouse_down_in_widget {
if let Some((_, w)) = &mut self.widget_column {
let dim = w.dim();
let widget_coord =
Vec2::new(coord.x - dim.x, coord.y - dim.y + self.scroll_offset);
redraw = w.on_event(&TheEvent::MouseUp(widget_coord), ctx);
self.is_dirty = true;
}
self.mouse_down_in_widget = false;
} else if let Some((_, w)) = &mut self.widget_column {
let dim = w.dim();
let widget_coord =
Vec2::new(coord.x - dim.x, coord.y - dim.y + self.scroll_offset);
// Check if the click is within the embedded widget bounds
if widget_coord.x >= 0
&& widget_coord.y >= 0
&& widget_coord.x < dim.width
&& widget_coord.y < dim.height
{
redraw = w.on_event(&TheEvent::MouseUp(widget_coord), ctx);
}
self.is_dirty = true;
}
}
TheEvent::Cut => {
if let Some((_, w)) = &mut self.widget_column {
redraw = w.on_event(event, ctx);
}
}
TheEvent::Copy => {
if let Some((_, w)) = &mut self.widget_column {
redraw = w.on_event(event, ctx);
}
}
TheEvent::Paste(value, app_type) => {
if let Some((_, w)) = &mut self.widget_column {
redraw = w.on_event(&TheEvent::Paste(value.clone(), app_type.clone()), ctx);
}
}
TheEvent::MouseDragged(coord) => {
// If mouse down happened in embedded widget, always forward drags to it
let mut handled_by_widget = false;
if self.mouse_down_in_widget {
if let Some((_, w)) = &mut self.widget_column {
let dim = w.dim();
let widget_coord =
Vec2::new(coord.x - dim.x, coord.y - dim.y + self.scroll_offset);
// Always forward drag events if mouse down was in widget (even if mouse is now outside)
redraw = w.on_event(&TheEvent::MouseDragged(widget_coord), ctx);
handled_by_widget = true;
}
}
// Only handle drag for tree item if not handled by embedded widget
if !handled_by_widget {
let coord = Vec2::new(coord.x, coord.y + self.scroll_offset);
if ctx.ui.drop.is_none()
&& Vec2::new(self.mouse_down_pos.x as f32, self.mouse_down_pos.y as f32)
.distance(Vec2::new(coord.x as f32, coord.y as f32))
>= 5.0
{
let mut text = self.text.clone();
if let Some((_, w)) = &mut self.widget_column {
if let TheValue::Text(t) = w.value() {
text = t.clone();
}
}
ctx.ui
.send(TheEvent::DragStarted(self.id().clone(), text, coord));
}
}
}
TheEvent::Hover(coord) => {
if self.state != TheWidgetState::Selected && !self.id().equals(&ctx.ui.hover) {
self.is_dirty = true;
ctx.ui.set_hover(self.id());
redraw = true;
}
// Pass hover events to embedded widget
if let Some((_, w)) = &mut self.widget_column {
let dim = w.dim();
let widget_coord = Vec2::new(coord.x - dim.x, coord.y - dim.y);
// Check if the hover is within the embedded widget bounds
if widget_coord.x >= 0
&& widget_coord.y >= 0
&& widget_coord.x < dim.width
&& widget_coord.y < dim.height
{
w.on_event(&TheEvent::Hover(widget_coord), ctx);
// Update cursor icon based on embedded widget
if let Some(cursor_icon) = w.cursor_icon() {
self.cursor_icon = Some(cursor_icon);
}
} else {
// Reset cursor icon when not hovering embedded widget
self.cursor_icon = None;
}
} else {
// Reset cursor icon when no embedded widget
self.cursor_icon = None;
}
}
TheEvent::MouseWheel(delta) => {
ctx.ui
.send(TheEvent::ScrollLayout(self.layout_id.clone(), *delta));
}
_ => {
// Only pass specific events to embedded widget that don't depend on mouse position
// This prevents embedded widgets from receiving events that should only go to the tree item
let has_focus = ctx.ui.has_focus(self.id());
if let Some((_, w)) = &mut self.widget_column {
match event {
// Pass focus events to embedded widget
TheEvent::GainedFocus(_) | TheEvent::LostFocus(_) => {
redraw = w.on_event(event, ctx);
}
// Pass keyboard events to embedded widget when parent tree item has focus
TheEvent::KeyDown(_)
| TheEvent::KeyUp(_)
| TheEvent::KeyCodeDown(_)
| TheEvent::KeyCodeUp(_) => {
if has_focus {
redraw = w.on_event(event, ctx);
}
}
// Pass modifier changes to embedded widget when parent tree item has focus
TheEvent::ModifierChanged(_, _, _, _) => {
if has_focus {
redraw = w.on_event(event, ctx);
}
}
// Pass undo/redo events to embedded widget when parent tree item has focus
TheEvent::Undo | TheEvent::Redo => {
if has_focus {
redraw = w.on_event(event, ctx);
}
}
// Don't pass other events to prevent unwanted value changes
_ => {}
}
}
}
}
redraw
}
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;
// Set dimension for embedded widget column
if let Some((width, widget)) = &mut self.widget_column {
widget.calculate_size(ctx);
let height = widget.limiter().get_max_height();
let y = (22 - height) / 2;
// Position widget at the right side with +9 offset (matching draw method)
let widget_x = self.dim.width - *width;
widget.set_dim(
TheDim::new(widget_x + 9, y, *width as i32 - 10, height),
ctx,
);
}
}
}
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 set_needs_redraw(&mut self, redraw: bool) {
self.is_dirty = redraw;
}
fn state(&self) -> TheWidgetState {
self.state
}
fn set_state(&mut self, state: TheWidgetState) {
self.state = state;
self.is_dirty = true;
}
fn supports_hover(&mut self) -> bool {
true
}
fn supports_text_input(&self) -> bool {
if let Some((_, widget)) = &self.widget_column {
return widget.supports_text_input();
}
false
}
fn cursor_icon(&self) -> Option<TheCursorIcon> {
// Return cursor icon from embedded widget if available, otherwise None
if let Some(cursor_icon) = self.cursor_icon {
Some(cursor_icon)
} else if let Some((_, widget)) = &self.widget_column {
widget.cursor_icon()
} else {
None
}
}
fn set_cursor_icon(&mut self, icon: Option<TheCursorIcon>) {
self.cursor_icon = icon;
}
fn supports_clipboard(&mut self) -> bool {
if let Some((_, widget)) = &mut self.widget_column {
widget.supports_clipboard()
} else {
false
}
}
fn value(&self) -> TheValue {
TheValue::Text(self.text.clone())
}
fn set_value(&mut self, value: TheValue) {
match value {
TheValue::Empty => {
self.text = "".to_string();
self.is_dirty = true;
}
TheValue::Text(text) => {
self.text.clone_from(&text);
self.is_dirty = true;
}
TheValue::Image(image) => {
self.icon = Some(image);
self.is_dirty = true;
}
_ => {}
}
}
fn status_text(&self) -> Option<String> {
self.status.clone()
}
fn set_status_text(&mut self, text: &str) {
self.status = Some(text.to_string());
}
fn draw(
&mut self,
buffer: &mut TheRGBABuffer,
style: &mut Box<dyn TheStyle>,
ctx: &mut TheContext,
) {
if !self.dim().is_valid() {
return;
}
// Fundamental safety check: ensure we don't draw outside buffer bounds
// Use buffer coordinates (which are relative to the content buffer)
let buffer_width = buffer.dim().width as i32;
let buffer_height = buffer.dim().height as i32;
let item_buffer_x = self.dim().buffer_x;
let item_buffer_y = self.dim().buffer_y;
if item_buffer_x < 0
|| item_buffer_y < 0
|| item_buffer_x + self.dim().width > buffer_width
|| item_buffer_y + self.dim().height > buffer_height
{
return;
}
let mut color = if self.state == TheWidgetState::Selected {
if !self.id().equals(&ctx.ui.focus) {
*style.theme().color(ListItemSelectedNoFocus)
} else {
*style.theme().color(ListItemSelected)
}
} else if let Some(background) = &self.background {
background.to_u8_array()
} else {
*style.theme().color(ListItemNormal)
};
if self.state != TheWidgetState::Selected && self.id().equals(&ctx.ui.hover) {
color = *style.theme().color(ListItemHover)
}
let stride = buffer.stride();
let mut shrinker = TheDimShrinker::zero();
// Safety check: ensure tree item is within buffer bounds before drawing outline
// Adjust for transparent top/bottom areas: draw 1px lower and 2px shorter
let mut adjusted_utuple = self.dim.to_buffer_shrunk_utuple(&shrinker);
adjusted_utuple.1 += 1; // Draw 1px lower
adjusted_utuple.3 = adjusted_utuple.3.saturating_sub(2); // Reduce height by 2px
let buffer_width = buffer.dim().width as usize;
let buffer_height = buffer.dim().height as usize;
// Additional defensive check: ensure we don't draw outside buffer bounds
if adjusted_utuple.0 < buffer_width
&& adjusted_utuple.1 < buffer_height
&& adjusted_utuple.0 + adjusted_utuple.2 <= buffer_width
&& adjusted_utuple.1 + adjusted_utuple.3 <= buffer_height
{
ctx.draw.rect_outline_border_open(
buffer.pixels_mut(),
&adjusted_utuple,
stride,
&color,
1,
);
}
shrinker.shrink(1);
// Safety check: ensure tree item is within buffer bounds before drawing fill
// Adjust for transparent top/bottom areas: draw 1px lower and 2px shorter
let mut adjusted_utuple = self.dim.to_buffer_shrunk_utuple(&shrinker);
adjusted_utuple.1 += 1; // Draw 1px lower
adjusted_utuple.3 = adjusted_utuple.3.saturating_sub(2); // Reduce height by 2px
let buffer_width = buffer.dim().width as usize;
let buffer_height = buffer.dim().height as usize;
// Additional defensive check: ensure we don't draw outside buffer bounds
if adjusted_utuple.0 < buffer_width
&& adjusted_utuple.1 < buffer_height
&& adjusted_utuple.0 + adjusted_utuple.2 <= buffer_width
&& adjusted_utuple.1 + adjusted_utuple.3 <= buffer_height
{
ctx.draw
.rect(buffer.pixels_mut(), &adjusted_utuple, stride, &color);
}
if let Some(icon) = &self.icon {
let ut = self.dim.to_buffer_shrunk_utuple(&shrinker);
let icon_rect = (ut.0 + 1, ut.1 + 2, 38, 38); // Adjust Y position by +1px
let buffer_width = buffer.dim().width as usize;
let buffer_height = buffer.dim().height as usize;
// Safety check: ensure icon is within buffer bounds before drawing
if icon_rect.0 < buffer_width
&& icon_rect.1 < buffer_height
&& icon_rect.0 + icon_rect.2 <= buffer_width
&& icon_rect.1 + icon_rect.3 <= buffer_height
{
ctx.draw.rect_outline_border(
buffer.pixels_mut(),
&icon_rect,
stride,
style.theme().color(ListItemIconBorder),
1,
);
}
let icon_copy_rect = (ut.0 + 2, ut.1 + 3, 36, 36); // Adjust Y position by +1px
let buffer_width = buffer.dim().width as usize;
let buffer_height = buffer.dim().height as usize;
// Safety check: ensure icon copy is within buffer bounds
if icon_copy_rect.0 < buffer_width
&& icon_copy_rect.1 < buffer_height
&& icon_copy_rect.0 + icon_copy_rect.2 <= buffer_width
&& icon_copy_rect.1 + icon_copy_rect.3 <= buffer_height
{
ctx.draw
.copy_slice(buffer.pixels_mut(), icon.pixels(), &icon_copy_rect, stride);
}
let text_rect = (
ut.0 + 38 + 7 + 5,
ut.1 + 6, // Adjust Y position by +1px
(self.dim.width - 38 - 7 - 10) as usize,
13,
);
let buffer_width = buffer.dim().width as usize;
let buffer_height = buffer.dim().height as usize;
// Safety check: ensure text is within buffer bounds before drawing
if text_rect.0 < buffer_width
&& text_rect.1 < buffer_height
&& text_rect.0 + text_rect.2 <= buffer_width
&& text_rect.1 + text_rect.3 <= buffer_height
{
ctx.draw.text_rect_blend(
buffer.pixels_mut(),
&text_rect,
stride,
&self.text,
TheFontSettings {
size: 12.0,
..Default::default()
},
style.theme().color(ListItemText),
TheHorizontalAlign::Left,
TheVerticalAlign::Center,
);
}
if !self.sub_text.is_empty() {
let sub_text_rect = (
ut.0 + 38 + 7 + 5,
ut.1 + 23, // Adjust Y position by +1px
(self.dim.width - 38 - 7 - 10) as usize,
13,
);
let buffer_width = buffer.dim().width as usize;
let buffer_height = buffer.dim().height as usize;
// Safety check: ensure sub text is within buffer bounds before drawing
if sub_text_rect.0 < buffer_width
&& sub_text_rect.1 < buffer_height
&& sub_text_rect.0 + sub_text_rect.2 <= buffer_width
&& sub_text_rect.1 + sub_text_rect.3 <= buffer_height
{
ctx.draw.text_rect_blend(
buffer.pixels_mut(),
&sub_text_rect,
stride,
&self.sub_text,
TheFontSettings {
size: 12.0,
..Default::default()
},
style.theme().color(ListItemText),
TheHorizontalAlign::Left,
TheVerticalAlign::Center,
);
}
}
} else {
let mut right_width = 5;
for v in self.values.iter() {
right_width += v.0;
}
if let Some((width, _)) = &self.widget_column {
right_width += *width;
}
shrinker.shrink_by(9, 0, 0, 0);
let mut rect: (usize, usize, usize, usize) =
self.dim.to_buffer_shrunk_utuple(&shrinker);
let text_rect = (
rect.0,
rect.1 + 1,
rect.2 - right_width as usize,
rect.3.saturating_sub(2),
); // Adjust Y position by +1px and reduce height by 2px
let buffer_width = buffer.dim().width as usize;
let buffer_height = buffer.dim().height as usize;
// Safety check: ensure text is within buffer bounds before drawing
if text_rect.0 < buffer_width
&& text_rect.1 < buffer_height
&& text_rect.0 + text_rect.2 <= buffer_width
&& text_rect.1 + text_rect.3 <= buffer_height
{
ctx.draw.text_rect_blend(
buffer.pixels_mut(),
&text_rect,
stride,
&self.text,
TheFontSettings {
size: 13.0,
..Default::default()
},
style.theme().color(ListItemText),
TheHorizontalAlign::Left,
TheVerticalAlign::Center,
);
}
rect.0 += rect.2 - right_width as usize;
if let Some((_width, widget)) = &mut self.widget_column {
ctx.draw.rect(
buffer.pixels_mut(),
&(rect.0, rect.1 - 1, 1, rect.3 + 2),
stride,
style.theme().color(ListLayoutBackground),
);
// Set buffer offset for drawing (dimension should already be set in set_dim)
let y_offset = rect.1 as i32 + (22 - widget.dim().height) / 2;
widget
.dim_mut()
.set_buffer_offset(rect.0 as i32 + 9, y_offset);
widget.draw(buffer, style, ctx);
}
for (width, value) in self.values.iter() {
ctx.draw.rect(
buffer.pixels_mut(),
&(rect.0, rect.1 - 1, 1, rect.3 + 2),
stride,
style.theme().color(ListLayoutBackground),
);
#[allow(clippy::single_match)]
match value {
TheValue::Text(text) => {
let value_rect = (
rect.0 + 9,
rect.1 + 1,
*width as usize - 10,
rect.3.saturating_sub(2),
); // Adjust Y position by +1px and reduce height by 2px
let buffer_width = buffer.dim().width as usize;
let buffer_height = buffer.dim().height as usize;
// Safety check: ensure value text is within buffer bounds before drawing
if value_rect.0 < buffer_width
&& value_rect.1 < buffer_height
&& value_rect.0 + value_rect.2 <= buffer_width
&& value_rect.1 + value_rect.3 <= buffer_height
{
ctx.draw.text_rect_blend(
buffer.pixels_mut(),
&value_rect,
stride,
text,
TheFontSettings {
size: 13.0,
..Default::default()
},
style.theme().color(ListItemText),
TheHorizontalAlign::Left,
TheVerticalAlign::Center,
);
}
}
_ => {
let value_rect = (
rect.0 + 9,
rect.1 + 1,
*width as usize - 10,
rect.3.saturating_sub(2),
); // Adjust Y position by +1px and reduce height by 2px
let buffer_width = buffer.dim().width as usize;
let buffer_height = buffer.dim().height as usize;
// Safety check: ensure value text is within buffer bounds before drawing
if value_rect.0 < buffer_width
&& value_rect.1 < buffer_height
&& value_rect.0 + value_rect.2 <= buffer_width
&& value_rect.1 + value_rect.3 <= buffer_height
{
ctx.draw.text_rect_blend(
buffer.pixels_mut(),
&value_rect,
stride,
&value.describe(),
TheFontSettings {
size: 13.0,
..Default::default()
},
style.theme().color(ListItemText),
TheHorizontalAlign::Left,
TheVerticalAlign::Center,
);
}
}
}
}
}
self.is_dirty = false;
}
fn as_tree_item(&mut self) -> Option<&mut dyn TheTreeItemTrait> {
Some(self)
}
fn as_any(&mut self) -> &mut dyn std::any::Any {
self
}
fn draw_overlay(
&mut self,
style: &mut Box<dyn TheStyle>,
ctx: &mut TheContext,
) -> TheRGBABuffer {
if let Some((_, widget)) = &mut self.widget_column {
let mut buffer = widget.draw_overlay(style, ctx);
let d = buffer.dim_mut();
// d.x += self.dim().x;
// d.y += self.dim().y;
d.buffer_x = d.x + self.dim().x - 6;
d.buffer_y = d.y + self.dim().y + 1 - self.scroll_offset;
buffer
} else {
TheRGBABuffer::default()
}
}
}
pub trait TheTreeItemTrait {
fn set_background_color(&mut self, color: TheColor);
fn set_text(&mut self, text: String);
fn set_sub_text(&mut self, sub_text: String);
fn set_associated_layout(&mut self, id: TheId);
fn set_size(&mut self, size: i32);
fn set_icon(&mut self, icon: TheRGBABuffer);
fn set_scroll_offset(&mut self, offset: i32);
fn add_value_column(&mut self, width: i32, value: TheValue);
fn add_widget_column(&mut self, width: i32, value: Box<dyn TheWidget>);
fn embedded_widget_mut(&mut self) -> Option<&mut Box<dyn TheWidget>>;
}
impl TheTreeItemTrait for TheTreeItem {
fn set_background_color(&mut self, color: TheColor) {
self.background = Some(color);
self.is_dirty = true;
}
fn set_text(&mut self, text: String) {
self.text = text;
self.is_dirty = true;
}
fn set_sub_text(&mut self, sub_text: String) {
self.sub_text = sub_text;
self.is_dirty = true;
}
fn set_associated_layout(&mut self, layout_id: TheId) {
self.layout_id = layout_id;
}
fn set_size(&mut self, size: i32) {
self.limiter_mut().set_max_height(size);
self.is_dirty = true;
}
fn set_icon(&mut self, icon: TheRGBABuffer) {
self.icon = Some(icon);
}
fn set_scroll_offset(&mut self, offset: i32) {
self.scroll_offset = offset;
}
fn add_value_column(&mut self, width: i32, value: TheValue) {
self.values.push((width, value));
}
fn add_widget_column(&mut self, width: i32, mut widget: Box<dyn TheWidget>) {
widget.set_embedded(true);
widget.set_parent_id(self.id.clone());
self.widget_column = Some((width, widget));
}
fn embedded_widget_mut(&mut self) -> Option<&mut Box<dyn TheWidget>> {
self.widget_column.as_mut().map(|(_, widget)| widget)
}
}