From eb13a2d1658526e48dd641fdf27b75fa67a21b9e Mon Sep 17 00:00:00 2001 From: Joe Weaver Date: Mon, 5 Apr 2021 11:13:57 -0400 Subject: [PATCH] added support for vAlign modification for Labels --- src/Wolfie2D/Nodes/UIElements/Label.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Wolfie2D/Nodes/UIElements/Label.ts b/src/Wolfie2D/Nodes/UIElements/Label.ts index e42f3ec..e89eb80 100644 --- a/src/Wolfie2D/Nodes/UIElements/Label.ts +++ b/src/Wolfie2D/Nodes/UIElements/Label.ts @@ -72,6 +72,10 @@ export default class Label extends UIElement{ this.hAlign = align; } + setVAlign(align: string): void { + this.vAlign = align; + } + /** * Calculate the offset of the text - this is used for rendering text with different alignments * @param ctx The rendering context @@ -83,16 +87,16 @@ export default class Label extends UIElement{ let offset = new Vec2(0, 0); let hDiff = this.size.x - textWidth; - if(this.hAlign === "center"){ + if(this.hAlign === HAlign.CENTER){ offset.x = hDiff/2; - } else if (this.hAlign === "right"){ + } else if (this.hAlign === HAlign.RIGHT){ offset.x = hDiff; } - if(this.vAlign === "top"){ + if(this.vAlign === VAlign.TOP){ ctx.textBaseline = "top"; offset.y = 0; - } else if (this.vAlign === "bottom"){ + } else if (this.vAlign === VAlign.BOTTOM){ ctx.textBaseline = "bottom"; offset.y = this.size.y; } else { @@ -133,4 +137,16 @@ export default class Label extends UIElement{ sizeToText(): void { this.sizeAssigned = false; } +} + +export enum VAlign { + TOP = "top", + CENTER = "center", + BOTTOM = "bottom" +} + +export enum HAlign { + LEFT = "left", + CENTER = "center", + RIGHT = "right" } \ No newline at end of file