1 module rpui.widgets.tab_layout.renderer;
2 
3 import rpui.math;
4 import rpui.events;
5 import rpui.theme;
6 import rpui.widget;
7 import rpui.widgets.tab_layout.widget;
8 import rpui.widgets.tab_button.widget;
9 import rpui.render.components;
10 import rpui.render.components_factory;
11 import rpui.render.transforms;
12 import rpui.render.renderer;
13 
14 final class TabLayoutRenderer : Renderer {
15     private TabLayout widget;
16 
17     private Theme theme;
18     private vec4 borderColor;
19     private Geometry border;
20     private QuadTransforms borderTransforms;
21 
22     override void onCreate(Widget widget, in string style) {
23         this.widget = cast(TabLayout) widget;
24         this.theme = widget.view.theme;
25         this.borderColor = theme.tree.data.getNormColor(style ~ ".borderColor");
26         this.border = createGeometry();
27     }
28 
29     override void onProgress(in ProgressEvent event) {
30         borderTransforms = updateQuadTransforms(
31             widget.view.cameraView,
32             widget.absolutePosition + vec2(-widget.outerOffsetStart.x, widget.size.y - 1),
33             vec2(widget.outerSize.x, 1)
34         );
35     }
36 
37     override void onRender() {
38         TabButton activeTab = null;
39 
40         foreach (Widget child; widget.children) {
41             TabButton tab = cast(TabButton) child.associatedWidget;
42 
43             if (tab !is null) {
44                 if (tab.checked) {
45                     activeTab = tab;
46                 } else {
47                     tab.onRender();
48                 }
49             }
50         }
51 
52         if (widget.showBorder) {
53             renderColorQuad(theme, border, borderColor, borderTransforms);
54         }
55 
56         if (activeTab !is null) {
57             activeTab.onRender();
58         }
59     }
60 }