1 module rpui.widgets.button.renderer;
2 
3 import rpui.events;
4 import rpui.theme;
5 import rpui.widget;
6 import rpui.render.transforms;
7 import rpui.render.renderer;
8 import rpui.widgets.button.widget;
9 import rpui.widgets.button.transforms_system;
10 import rpui.widgets.button.render_system;
11 import rpui.render.components;
12 import rpui.render.components_factory;
13 
14 class ButtonRenderer : Renderer {
15     private Button widget;
16     private Theme theme;
17     protected RenderData renderData;
18     private RenderTransforms transforms;
19     private string style;
20 
21     protected ButtonTransformsSystem transformSystem;
22     protected RenderSystem renderSystem;
23 
24     override void onCreate(Widget widget, in string style) {
25         this.widget = cast(Button) widget;
26         this.theme = widget.view.theme;
27         this.style = style;
28         this.renderData = this.widget.themeLoader.loadRenderData(theme, style);
29 
30         renderSystem = new ButtonRenderSystem(this.widget, &renderData, &transforms);
31         transformSystem = new ButtonTransformsSystem(this.widget, &renderData, &transforms);
32 
33         createIcons();
34     }
35 
36     private void createIcons() {
37         auto iconsResources = widget.view.resources.icons;
38         const iconsTexture = iconsResources.getTextureForIcons(widget.iconsGroup);
39 
40         foreach (const iconName; widget.icons) {
41             const icon = iconsResources.getIcon(widget.iconsGroup, iconName);
42             const quad = createTexAtlasTextureQuad(iconsTexture, icon.texCoord);
43 
44             renderData.icons.insert(quad);
45             transforms.icons.insert(QuadTransforms());
46         }
47     }
48 
49     override void onRender() {
50         renderSystem.onRender();
51     }
52 
53     override void onProgress(in ProgressEvent event) {
54         transformSystem.onProgress(event);
55     }
56 }