Skip to content

Commit c93d763

Browse files
committed
Updated code to use modern user-interface-base standard, some code from here will be pushed into user-interface-base instead, code now imports from user-interface-base and uses microgui namespace.
1 parent 1610e41 commit c93d763

11 files changed

Lines changed: 473 additions & 615 deletions

analytics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
namespace microcode {
1+
namespace microgui {
22
export interface AnalyticsEvent {
33
type: "event"
44
msg: string
5-
data?: { [name: string]: string | number }
5+
data?: { [name: string]: string | number }
66
}
77

88
/**

app.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
namespace microcode {
1+
namespace microgui {
2+
import AppInterface = user_interface_base.AppInterface
3+
import Scene = user_interface_base.Scene
4+
import SceneManager = user_interface_base.SceneManager
5+
26
// Auto-save slot
37
export const SAVESLOT_AUTO = "sa"
48

@@ -7,13 +11,17 @@ namespace microcode {
711
version?: string
812
}
913

14+
// application configuration
15+
// user_interface_base.getIcon = (id) => icons.get(id)
16+
user_interface_base.resolveTooltip = (ariaId: string) => ariaId
17+
18+
1019
export class App {
11-
private sceneManager: SceneManager
20+
private sceneManager: SceneManager
1221

1322
constructor() {
1423
// One interval delay to ensure all static constructors have executed.
1524
basic.pause(10)
16-
reportEvent("app.start")
1725

1826
this.sceneManager = new SceneManager()
1927
datalogger.includeTimestamp(FlashLogTimeStampFormat.None)
@@ -26,5 +34,13 @@ namespace microcode {
2634
public popScene() {
2735
this.sceneManager.popScene()
2836
}
37+
38+
public save(slot: string, buffer: Buffer): boolean {
39+
return true;
40+
}
41+
42+
public load(slot: string): Buffer {
43+
return Buffer.create(0)
44+
}
2945
}
3046
}

button.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ namespace microcode {
55
public bottom: number,
66
public left: number,
77
public right: number
8-
) {}
8+
) { }
99
}
1010

1111
export class ButtonStyle {
1212
constructor(
1313
public fill: number,
1414
public borders: Borders,
1515
public shadow: boolean
16-
) {}
16+
) { }
1717
}
1818

1919
export namespace ButtonStyles {
@@ -147,8 +147,8 @@ namespace microcode {
147147
return !this.icon.invisible
148148
}
149149

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

153153
isOffScreenX(): boolean {
154154
return this.icon.isOffScreenX()
@@ -291,7 +291,7 @@ namespace microcode {
291291
? icons.get(this.iconId)
292292
: this.iconId
293293
}
294-
294+
295295
public setIcon(iconId: string, img?: Bitmap) {
296296
this.iconId = iconId
297297
if (img) this.icon.setImage(img)
@@ -315,7 +315,7 @@ namespace microcode {
315315
super.draw()
316316

317317
if (this.dynamicBoundaryColorsOn) {
318-
const boundaryColour = (this.selected && this.pressable) ? 7: this.boundaryColor
318+
const boundaryColour = (this.selected && this.pressable) ? 7 : this.boundaryColor
319319

320320
for (let dist = 1; dist <= 3; dist++) {
321321
Screen.outlineBoundsXfrm(

graphableFunction.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace microcode {
1+
namespace microgui {
22

33
export interface IGraphableFunction {
44
draw(fromX: number, color: number): void;
@@ -35,23 +35,23 @@ namespace microcode {
3535
this.fnToSample = fnToSample
3636
}
3737

38-
getName(): string {return "name"}
39-
getReading(): number {return 0}
40-
getValueAt(x: number): number {return this.fnToSample(x);}
41-
getNormalisedReading(): number {return Math.abs(this.getReading()) / (Math.abs(this.getMinimum()) + this.getMaximum())}
42-
getMinimum(): number {return 0;}
43-
getMaximum(): number {return 100;}
44-
45-
getMaxBufferSize(): number {return this.maxBufferSize}
46-
getNthReading(n: number): number {return this.dataBuffer[n]}
47-
getNthHeightNormalisedReading(n: number): number {return this.heightNormalisedDataBuffer[n]}
48-
getBufferLength(): number {return this.dataBuffer.length}
49-
getHeightNormalisedBufferLength(): number {return this.heightNormalisedDataBuffer.length}
38+
getName(): string { return "name" }
39+
getReading(): number { return 0 }
40+
getValueAt(x: number): number { return this.fnToSample(x); }
41+
getNormalisedReading(): number { return Math.abs(this.getReading()) / (Math.abs(this.getMinimum()) + this.getMaximum()) }
42+
getMinimum(): number { return 0; }
43+
getMaximum(): number { return 100; }
44+
45+
getMaxBufferSize(): number { return this.maxBufferSize }
46+
getNthReading(n: number): number { return this.dataBuffer[n] }
47+
getNthHeightNormalisedReading(n: number): number { return this.heightNormalisedDataBuffer[n] }
48+
getBufferLength(): number { return this.dataBuffer.length }
49+
getHeightNormalisedBufferLength(): number { return this.heightNormalisedDataBuffer.length }
5050
// getPeriod(): number {return this.config.period;}
5151
// getMeasurements(): number {return this.config.measurements}
5252
// hasMeasurements(): boolean {return this.config.measurements > 0;}
5353

54-
54+
5555
/**
5656
* Change the size of the buffer used for this.dataBuffer & this.normalisedBuffer
5757
* Will shift out old this.dataBuffer & this.normalisedBuffer values from the front.
@@ -120,13 +120,13 @@ namespace microcode {
120120
for (let j = -(PLOT_SMOOTHING_CONSTANT / 2); j < PLOT_SMOOTHING_CONSTANT / 2; j++) {
121121
screen().drawLine(
122122
fromX + i - 1,
123-
this.heightNormalisedDataBuffer[i] + j ,//+ (screen().height / 2),
123+
this.heightNormalisedDataBuffer[i] + j,//+ (screen().height / 2),
124124
fromX + i,
125-
this.heightNormalisedDataBuffer[i + 1] + j ,//+ (screen().height / 2),
125+
this.heightNormalisedDataBuffer[i + 1] + j,//+ (screen().height / 2),
126126
color
127127
);
128128
}
129129
}
130130
}
131131
}
132-
}
132+
}

guiComponents.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
namespace microcode {
1+
namespace microgui {
2+
import AppInterface = user_interface_base.AppInterface
3+
import Scene = user_interface_base.Scene
4+
import SceneManager = user_interface_base.SceneManager
5+
6+
7+
import BACK_BUTTON_ERROR_KIND = user_interface_base.BACK_BUTTON_ERROR_KIND
8+
import FORWARD_BUTTON_ERROR_KIND = user_interface_base.FORWARD_BUTTON_ERROR_KIND
9+
import INavigator = user_interface_base.INavigator
10+
11+
12+
import Cursor = user_interface_base.Cursor
13+
import CursorDir = user_interface_base.CursorDir
14+
import Picker = user_interface_base.Picker
15+
16+
import Bounds = user_interface_base.Bounds
17+
import Screen = user_interface_base.Screen
18+
import Button = user_interface_base.Button
19+
import font = user_interface_base.font
20+
221

322
/**
423
* Util function used within this file, useful for ensuring that prior bindings are not kept when using a new component.
@@ -91,6 +110,7 @@ namespace microcode {
91110
border?: boolean,
92111
showBackground?: boolean
93112
}) {
113+
94114
super()
95115

96116
this.alignment = opts.alignment;
@@ -118,7 +138,7 @@ namespace microcode {
118138
const left = pos[0];
119139
const top = pos[1];
120140

121-
this.bounds = new microcode.Bounds({
141+
this.bounds = new Bounds({
122142
width: this.unscaledWidth * this.xScaling,
123143
height: this.unscaledHeight * this.yScaling,
124144
left,
@@ -200,7 +220,7 @@ namespace microcode {
200220
if (this.bounds != null) {
201221
this.xScaling = xScaling
202222
this.yScaling = yScaling
203-
this.bounds = new microcode.Bounds({
223+
this.bounds = new Bounds({
204224
width: this.unscaledWidth * this.xScaling,
205225
height: this.unscaledHeight * this.yScaling,
206226
left: this.bounds.left,
@@ -1385,7 +1405,7 @@ namespace microcode {
13851405
if (text) {
13861406
const pos = this.cursorBounds;
13871407
const n = text.length
1388-
const font = microcode.font
1408+
const font = user_interface_base.font
13891409
const w = font.charWidth * n
13901410
const h = font.charHeight
13911411
const x = Math.max(

inputMethods.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
namespace microcode {
1+
namespace microgui {
2+
import AppInterface = user_interface_base.AppInterface
3+
import Scene = user_interface_base.Scene
4+
import CursorSceneWithPriorPage = user_interface_base.CursorSceneWithPriorPage
5+
import GridNavigator = user_interface_base.GridNavigator
6+
import ButtonStyles = user_interface_base.ButtonStyles
7+
import Screen = user_interface_base.Screen
8+
import Button = user_interface_base.Button
9+
import font = user_interface_base.font
10+
11+
212
abstract class AbstractInputMethod extends Scene {
313
protected titleText: string;
414

@@ -16,6 +26,7 @@ namespace microcode {
1626
}
1727
}
1828

29+
1930
export class TickerMenu extends AbstractInputMethod {
2031
private tickerValues: number[];
2132
private tickerIncrements: number[];
@@ -25,7 +36,7 @@ namespace microcode {
2536
private back: () => void;
2637

2738
constructor(
28-
app: App,
39+
app: AppInterface,
2940
titleText: string,
3041
defaultTickerValues: number[],
3142
backgroundColor?: number,
@@ -181,8 +192,8 @@ namespace microcode {
181192
private shakeText: boolean
182193
private shakeTextCounter: number
183194

184-
constructor(app: App, next: (arg0: string) => void) {
185-
super(app, function () { }, new GridNavigator(5, 5, KeyboardMenu.WIDTHS))//, new GridNavigator(5, 10))
195+
constructor(app: AppInterface, next: (arg0: string) => void) {
196+
super(app, function() { }, new GridNavigator(5, 5, KeyboardMenu.WIDTHS))//, new GridNavigator(5, 10))
186197
this.text = ""
187198
this.upperCase = true
188199

@@ -399,7 +410,7 @@ namespace microcode {
399410
}
400411
}
401412

402-
413+
403414
export class CalculatorMenu extends CursorSceneWithPriorPage {
404415
private static WIDTHS: number[] = [10, 5, 4]
405416
private btns: Button[]
@@ -410,8 +421,8 @@ namespace microcode {
410421
private shakeText: boolean
411422
private shakeTextCounter: number
412423

413-
constructor(app: App, next: (arg0: GraphableFunction) => void) {
414-
super(app, function () { }, new GridNavigator(3, 1, CalculatorMenu.WIDTHS))
424+
constructor(app: AppInterface, next: (arg0: GraphableFunction) => void) {
425+
super(app, function() { }, new GridNavigator(3, 1, CalculatorMenu.WIDTHS))
415426
this.text = ""
416427

417428
this.btns = []
@@ -650,9 +661,9 @@ namespace microcode {
650661
private btnText: string[]
651662
private callbacks: ((btn: Button) => void)[][]
652663

653-
constructor(app: App, callbacks: ((btn: Button) => void)[][], priorFn?: () => void) {
664+
constructor(app: AppInterface, callbacks: ((btn: Button) => void)[][], priorFn?: () => void) {
654665
super(app,
655-
(priorFn != null) ? priorFn : function () { },
666+
(priorFn != null) ? priorFn : function() { },
656667
new GridNavigator(
657668
callbacks.length,
658669
(callbacks.length > 0) ? callbacks[0].length : 0
@@ -695,4 +706,4 @@ namespace microcode {
695706
this.btns.forEach(btn => btn.draw())
696707
}
697708
}
698-
}
709+
}

0 commit comments

Comments
 (0)