1 module rpui.widgets.text_input.renderer;
2 
3 import rpdl.tree;
4 
5 import rpui.primitives;
6 import rpui.theme;
7 import rpui.events;
8 import rpui.widget;
9 import rpui.widgets.text_input.widget;
10 import rpui.widgets.text_input.render_system;
11 import rpui.widgets.text_input.transforms_system;
12 import rpui.render.components;
13 import rpui.render.components_factory;
14 import rpui.render.renderer;
15 import rpui.render.transforms;
16 
17 final class TextInputRenderer : Renderer {
18     private UiText text;
19     private UiTextTransforms textTransforms;
20     private TextInput widget;
21     private Theme theme;
22     private TextInputRenderSystem renderSystem;
23     private TextInputTransformsSystem transformsSystem;
24     private RenderData renderData;
25     private RenderTransforms transforms;
26 
27     override void onCreate(Widget widget, in string style) {
28         this.theme = widget.view.theme;
29         this.widget = cast(TextInput) widget;
30 
31         renderSystem = new TextInputRenderSystem(this.widget, &renderData, &transforms);
32         transformsSystem = new TextInputTransformsSystem(this.widget, &renderData, &transforms);
33 
34         loadRenderData(widget.view.theme, style);
35         this.widget.editComponent.attach(this.widget, transformsSystem);
36     }
37 
38     private void loadRenderData(Theme theme, in string style) {
39         auto data = theme.tree.data;
40 
41         renderData.background = createStatefulChainFromRdpl(theme, Orientation.horizontal, style);
42         renderData.focusGlow = createChainFromRdpl(theme, Orientation.horizontal, style ~ ".Focus");
43         renderData.carriage = createTexAtlasTextureQuadFromRdpl(theme, style, "carriage");
44         renderData.leftArrow = createStatefulTexAtlasTextureQuadFromRdpl(theme, style, "Arrow.left");
45         renderData.rightArrow = createStatefulTexAtlasTextureQuadFromRdpl(theme, style, "Arrow.right");
46         renderData.text = createStatefulUiTextFromRdpl(theme, style, "Text");
47         renderData.prefix = createStatefulUiTextFromRdpl(theme, style, "PrefixText");
48         renderData.postfix = createStatefulUiTextFromRdpl(theme, style, "PostfixText");
49         renderData.selectRegion = createGeometry();
50         renderData.selectRegionColor = data.getNormColor(style ~ ".selectColor");
51         renderData.selectedTextColor = data.getNormColor(style ~ ".selectedTextColor");
52 
53         transforms.focusOffsets = data.getVec2f(style ~ ".Focus.offsets.0");
54         transforms.focusResize = data.getNumber(style ~ ".Focus.offsets.1");
55         transforms.selectRegionHeight = data.getNumber(style ~ ".selectRegionHeight.0");
56         transforms.selectRegionOffset = data.getVec2f(style ~ ".selectRegionOffset");
57         transforms.arrowOffsets = data.getVec2f(style ~ ".arrowOffsets");
58         transforms.prefixMargin = data.getNumber(style ~ ".prefixMargin.0");
59         transforms.postfixMargin = data.getNumber(style ~ ".postfixMargin.0");
60         transforms.softPostfixMargin = data.getNumber(style ~ ".softPostfixMargin.0");
61     }
62 
63     override void onRender() {
64         renderSystem.onRender();
65     }
66 
67     override void onProgress(in ProgressEvent event) {
68         transformsSystem.onProgress(event);
69     }
70 }