1 module rpui.widgets.label.widget;
2 
3 import rpui.events;
4 import rpui.input;
5 import rpui.math;
6 import rpui.primitives;
7 import rpui.widget;
8 import rpui.widgets.label.renderer;
9 
10 class Label : Widget {
11     @field Align textAlign = Align.left;
12     @field VerticalAlign textVerticalAlign = VerticalAlign.middle;
13     @field float lineHeightFactor = 1.5;
14     @field utf32string caption = "Label";
15 
16     package struct Measure {
17         float lineHeight;
18         float textWidth;
19     }
20 
21     package Measure measure;
22 
23     this(in string style = "Label") {
24         super(style);
25 
26         this.drawChildren = false;
27         this.renderer = new LabelRenderer();
28         this.heightType = SizeType.wrapContent;
29         this.widthType = SizeType.wrapContent;
30     }
31 
32     override void onProgress(in ProgressEvent event) {
33         locator.updateAbsolutePosition();
34         locator.updateLocationAlign();
35         locator.updateVerticalLocationAlign();
36         updateSize();
37         renderer.onProgress(event);
38     }
39 
40 protected:
41     override void onCreate() {
42         super.onCreate();
43         focusable = false;
44     }
45 
46     override void updateSize() {
47         super.updateSize();
48 
49         if (heightType == SizeType.wrapContent) {
50             size.y = measure.lineHeight * lineHeightFactor + innerOffsetSize.y;
51         }
52 
53         if (widthType == SizeType.wrapContent) {
54             size.x = measure.textWidth + innerOffsetSize.x;
55         }
56     }
57 }