Skip to content

Commit 4223d3a

Browse files
committed
Button: all args are optional, checks are done in constructor
1 parent 38f0c55 commit 4223d3a

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

button.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
namespace user_interface_base {
2-
32
export class Borders {
43
constructor(
54
public top: number,
65
public bottom: number,
76
public left: number,
87
public right: number
9-
) {}
8+
) { }
109
}
1110

1211
export class ButtonStyle {
1312
constructor(
1413
public fill: number,
1514
public borders: Borders,
1615
public shadow: boolean
17-
) {}
16+
) { }
1817
}
1918

2019
export namespace ButtonStyles {
@@ -148,8 +147,8 @@ namespace user_interface_base {
148147
return !this.icon.invisible
149148
}
150149

151-
public hover(hov: boolean) {}
152-
public update() {}
150+
public hover(hov: boolean) { }
151+
public update() { }
153152

154153
isOffScreenX(): boolean {
155154
return this.icon.isOffScreenX()
@@ -202,13 +201,11 @@ namespace user_interface_base {
202201
public selected: boolean
203202
private dynamicBoundaryColorsOn: boolean
204203
private boundaryColor: number
204+
public state: number[]
205205
public pressable: boolean
206206

207207
public get ariaId(): string {
208-
return (
209-
this._ariaId ||
210-
(typeof this.iconId === "string" ? <string>this.iconId : "")
211-
)
208+
return this._ariaId
212209
}
213210

214211
public set ariaId(value: string) {
@@ -221,29 +218,30 @@ namespace user_interface_base {
221218
value: this.ariaId,
222219
force,
223220
}
224-
accessibility.setLiveContent(msg)
221+
accessibility.setLiveContent(msg)
225222
}
226223

227224
constructor(opts: {
228225
parent?: IPlaceable
229226
style?: ButtonStyle
230-
icon: string | Bitmap
227+
icon?: string | Bitmap
231228
ariaId?: string
232-
x: number
233-
y: number
229+
x?: number
230+
y?: number
234231
onClick?: (button: Button) => void,
235232
dynamicBoundaryColorsOn?: boolean
236233
boundaryColor?: number,
237-
flipIcon?: boolean
234+
flipIcon?: boolean,
235+
state?: number[]
238236
}) {
239237
super(
240-
opts.x,
241-
opts.y,
238+
(opts.x != null) ? opts.x : 0,
239+
(opts.y != null) ? opts.y : 0,
242240
opts.style || ButtonStyles.Transparent,
243241
opts.parent && opts.parent.xfrm
244242
)
245243
this.iconId = opts.icon
246-
this._ariaId = opts.ariaId
244+
this._ariaId = (opts.ariaId != null) ? opts.ariaId : ""
247245
this.onClick = opts.onClick
248246
this.buildSprite(this.image_())
249247

@@ -267,6 +265,8 @@ namespace user_interface_base {
267265
this.dynamicBoundaryColorsOn = true
268266
this.boundaryColor = opts.boundaryColor
269267
}
268+
269+
this.state = opts.state
270270
}
271271

272272
public getIcon() {
@@ -283,10 +283,10 @@ namespace user_interface_base {
283283

284284
private image_() {
285285
return typeof this.iconId == "string"
286-
? getIcon(this.iconId,false)
286+
? getIcon(this.iconId, false)
287287
: this.iconId
288288
}
289-
289+
290290
public setIcon(iconId: string, img?: Bitmap) {
291291
this.iconId = iconId
292292
if (img) this.icon.setImage(img)
@@ -310,7 +310,7 @@ namespace user_interface_base {
310310
super.draw()
311311

312312
if (this.dynamicBoundaryColorsOn) {
313-
const boundaryColour = (this.selected && this.pressable) ? 7: this.boundaryColor
313+
const boundaryColour = (this.selected && this.pressable) ? 7 : this.boundaryColor
314314

315315
for (let dist = 1; dist <= 3; dist++) {
316316
Screen.outlineBoundsXfrm(

cursor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace user_interface_base {
2323
}
2424

2525
export interface CursorState {
26-
navigator: INavigator
26+
navigator: INavigator
2727
pos: Vec2
2828
ariaId: string
2929
size: Bounds
@@ -48,7 +48,7 @@ namespace user_interface_base {
4848
this.cancelHandlerStack = []
4949
this.moveDest = new Vec2()
5050
this.setSize()
51-
51+
5252
this.cursorOutlineColour = DEFAULT_CURSOR_OUTLINE_COLOUR
5353
}
5454

@@ -70,7 +70,7 @@ namespace user_interface_base {
7070
public snapTo(x: number, y: number, ariaId: string, sizeHint: Bounds) {
7171
this.setSize(
7272
sizeHint ||
73-
new Bounds({ left: 0, top: 0, width: 16, height: 16 })
73+
new Bounds({ left: 0, top: 0, width: 16, height: 16 })
7474
)
7575
this.moveDest.x = this.xfrm.localPos.x = x
7676
this.moveDest.y = this.xfrm.localPos.y = y

0 commit comments

Comments
 (0)