Skip to content

Commit

Permalink
text display
Browse files Browse the repository at this point in the history
  • Loading branch information
j committed Oct 23, 2024
1 parent 63766b1 commit 71b082b
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions haxe/ui/backend/TextDisplayImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ class TextDisplayImpl extends TextBase {
public function new() {
super();
visual = new Visual();
visual.depthRange = -1;
visual.active = true;
visual.visible = false;
visual.inheritAlpha = true;

text_visual = new Text();
text_visual.depth = -4;

var font = Screen.instance.options.default_text_font;
// font = AppImpl.assets.font(Fonts.ROBOTO_REGULAR);

Expand Down Expand Up @@ -86,6 +85,19 @@ class TextDisplayImpl extends TextBase {
measureTextRequired = true;
}

if (_textStyle.fontWeight != null) {
var weights = Screen.instance.options.font_weights;
var font = null;
if (!weights.exists(_textStyle.fontWeight)) {
font = Screen.instance.options.default_text_font;
} else {
font = weights.get(_textStyle.fontWeight);
}

text_visual.font = font;
measureTextRequired = true;
}

var font_name = _textStyle.fontName;
if (font_name != null) {
var font = App.app.assets.font(font_name);
Expand Down Expand Up @@ -122,14 +134,22 @@ class TextDisplayImpl extends TextBase {
private override function validatePosition() {
switch (text_visual.align) {
case CENTER:
text_visual.x = Std.int(_left + (_width / 2) - (text_visual.width / 2));
text_visual.x = (_left + (_width / 2) - (text_visual.width / 2));
case RIGHT:
text_visual.x = Std.int(_width - text_visual.width);
text_visual.x = (_width - text_visual.width);
case LEFT:
text_visual.x = Std.int(_left);
text_visual.x = (_left);
}

visual.y = _top;

if (text_visual.numLines == 1) {
var offset = Screen.instance.options.text_offset;
if (offset == null) {
offset = Math.floor(text_visual.height - text_visual.pointSize);
}
visual.y = _top + offset;
}
}

private override function validateDisplay() {
Expand All @@ -149,10 +169,19 @@ class TextDisplayImpl extends TextBase {

private override function measureText() {
visual.computeContent();
var w = Math.fround(text_visual.width);
var h = Math.fround(text_visual.height);

var w = (text_visual.width);
var h = (text_visual.pointSize);

if (Screen.instance.options.text_offset != null) {
h = text_visual.height;
}

if (text_visual.numLines > 1) {
h = text_visual.height;
}

_textWidth = w;
_textHeight = h;
}
}
}

0 comments on commit 71b082b

Please sign in to comment.