1 module rpui.widgets.list_menu_items_divider.renderer;
2 
3 import rpui.primitives;
4 import rpui.basic_rpdl_exts;
5 import rpui.math;
6 import rpui.theme;
7 import rpui.events;
8 import rpui.widget;
9 import rpui.widgets.list_menu_items_divider.widget;
10 import rpui.render.components;
11 import rpui.render.components_factory;
12 import rpui.render.renderer;
13 import rpui.render.transforms;
14 
15 final class ListMenuItemsDividerRenderer : Renderer {
16     private ListMenuItemsDivider widget;
17     private Theme theme;
18 
19     private FrameRect dividerOffsets;
20     private Geometry dividerInner;
21     private Geometry dividerOuter;
22     private QuadTransforms dividerInnerTransforms;
23     private QuadTransforms dividerOuterTransforms;
24     private vec4 innerColor;
25     private vec4 outerColor;
26 
27     override void onCreate(Widget widget, in string style) {
28         this.theme = widget.view.theme;
29         this.widget = cast(ListMenuItemsDivider) widget;
30         this.dividerInner = createGeometry();
31         this.dividerOuter = createGeometry();
32         this.dividerOffsets = this.theme.tree.data.getFrameRect(style ~ ".dividerOffsets");
33         this.innerColor = this.theme.tree.data.getNormColor(style ~ ".innerColor");
34         this.outerColor = this.theme.tree.data.getNormColor(style ~ ".outerColor");
35         this.widget.height = 2 + this.dividerOffsets.top + this.dividerOffsets.bottom;
36     }
37 
38     override void onRender() {
39         renderColorQuad(theme, dividerInner, innerColor, dividerInnerTransforms);
40         renderColorQuad(theme, dividerOuter, outerColor, dividerOuterTransforms);
41     }
42 
43     override void onProgress(in ProgressEvent event) {
44         const size = vec2(widget.size.x - dividerOffsets.left - dividerOffsets.right, 1);
45 
46         dividerInnerTransforms = updateQuadTransforms(
47             widget.view.cameraView(),
48             widget.absolutePosition + vec2(dividerOffsets.left, dividerOffsets.top - 1),
49             size
50         );
51 
52         dividerOuterTransforms = updateQuadTransforms(
53             widget.view.cameraView(),
54             widget.absolutePosition + vec2(dividerOffsets.left, dividerOffsets.top),
55             size
56         );
57     }
58 }