From b7a0d7fe4a88a450389af3960bf12799f2a52ab5 Mon Sep 17 00:00:00 2001 From: Erik Corry Date: Mon, 18 Dec 2023 21:55:03 +0100 Subject: [PATCH] Add Style contructor flags for alignment (#90) * Add Style contructor flags for alignment * Update src/style.toit Co-authored-by: Florian Loitsch --------- Co-authored-by: Florian Loitsch --- src/style.toit | 5 +++++ tests/icons-visualized.toit | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/style.toit b/src/style.toit index 2591335..4680b67 100644 --- a/src/style.toit +++ b/src/style.toit @@ -638,6 +638,8 @@ class Style: --class-map/Map?=null --id-map/Map?=null --type-map/Map?=null + --align-right/bool=false + --align-center/bool=false .map_={:}: if x != null: map_["x"] = x if y != null: map_["y"] = y @@ -646,6 +648,9 @@ class Style: if color != null: map_["color"] = color if font != null: map_["font"] = font if border != null: map_["border"] = border + if align-right and align-center: throw "INVALID_ARGUMENT" + if align-right: map_["alignment"] = ALIGN-RIGHT + if align-center: map_["alignment"] = ALIGN-CENTER Background.check-valid background if background: map_["background"] = background class-map_ = class-map diff --git a/tests/icons-visualized.toit b/tests/icons-visualized.toit index 09626a0..2111645 100644 --- a/tests/icons-visualized.toit +++ b/tests/icons-visualized.toit @@ -57,7 +57,7 @@ main args: // Also includes the initial style parameters. off-style := Style --type-map={ - "label": Style --x=30 --y=47 --color=0xc0c0c0 {"alignment": ALIGN_CENTER}, + "label": Style --x=30 --y=47 --color=0xc0c0c0 --align-center, } --class-map={ "button-outer": Style --y=20 --w=70 --h=70 --border=rounded-35 --background=outer-background,