1 module rpui.widgets.multiline_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.multiline_label.renderer; 9 10 class MultilineLabel : Widget { 11 @field Align textAlign = Align.left; 12 @field VerticalAlign textVerticalAlign = VerticalAlign.middle; 13 @field float lineHeightFactor = 1; 14 @field utf32string caption = "Label"; 15 16 package struct Measure { 17 float lineHeight; 18 float maxLineWidth; 19 size_t linesCount; 20 } 21 22 package Measure measure; 23 24 this(in string style = "Label") { 25 super(style); 26 this.drawChildren = false; 27 this.renderer = new MultilineLabelRenderer(); 28 } 29 30 override void onProgress(in ProgressEvent event) { 31 locator.updateAbsolutePosition(); 32 locator.updateLocationAlign(); 33 locator.updateVerticalLocationAlign(); 34 updateSize(); 35 renderer.onProgress(event); 36 } 37 38 protected: 39 override void onCreate() { 40 super.onCreate(); 41 focusable = false; 42 } 43 44 override void updateSize() { 45 super.updateSize(); 46 47 if (heightType == SizeType.wrapContent) { 48 const textLineHeight = measure.lineHeight * lineHeightFactor; 49 const boundaryHeight = textLineHeight * measure.linesCount; 50 size.y = boundaryHeight + innerOffsetSize.y; 51 } 52 53 if (widthType == SizeType.wrapContent) { 54 size.x = measure.maxLineWidth + innerOffsetSize.x; 55 } 56 } 57 }