Skip to content

Commit

Permalink
Make x, y, w, h all configurable with style sheets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Corry committed Dec 12, 2023
1 parent 48d609a commit d0f7e5b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/element.toit
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ abstract class Element implements Window:
invalidate
border_ = value
invalidate
else if key == "x":
x = value
else if key == "y":
y = value
else:
print "Unknown style key: '$key'"

abstract type -> string

Expand Down Expand Up @@ -289,9 +295,9 @@ class Div extends Element:
invalidate

set-attribute_ key/string value -> none:
if key == "width":
if key == "w":
w = value
else if key == "height":
else if key == "h":
h = value
else:
super key value
Expand Down Expand Up @@ -334,6 +340,8 @@ class Label extends Element implements ColoredElement:
orientation = value
else if key == "alignment":
alignment = value
else if key == "label":
label = value
else:
super key value

Expand Down
8 changes: 8 additions & 0 deletions src/style.toit
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ class Style:
constructor.empty: return EMPTY-STYLE_

constructor
--x/int?=null
--y/int?=null
--w/int?=null
--h/int?=null
--color/int?=null
--font/Font?=null
--background=null
Expand All @@ -632,6 +636,10 @@ class Style:
--id-map/Map?=null
--type-map/Map?=null
.map_={:}:
if x != null: map_["x"] = x
if y != null: map_["y"] = y
if w != null: map_["w"] = w
if h != null: map_["h"] = h
if color != null: map_["color"] = color
if font != null: map_["font"] = font
if border != null: map_["border"] = border
Expand Down
4 changes: 2 additions & 2 deletions tests/horizontal-slider-visualized.toit
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ main args:
"slider": Style {
"background-hi": heat,
"background-lo": cold,
"width": 120,
"height": 20,
"w": 120,
"h": 20,
"horizontal": true,
},
"label": Style --font=sans10 --color=0xffffff,
Expand Down
4 changes: 1 addition & 3 deletions tests/slider-rotated-visualized.toit
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ main args:

style := Style
--type-map={
"slider": Style {
"slider": Style --w=20 --h=100 {
"background-hi": heat,
"background-lo": cold,
"width": 20,
"height": 100,
},
"label": Style --font=sans10 --color=0xffffff,
}
Expand Down
4 changes: 2 additions & 2 deletions tests/slider-visualized.toit
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ main args:
"slider": Style {
"background-hi": heat,
"background-lo": cold,
"width": 20,
"height": 100,
"w": 20,
"h": 100,
},
"label": Style --font=sans10 --color=0xffffff,
}
Expand Down

0 comments on commit d0f7e5b

Please sign in to comment.