-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapphost.ts
More file actions
104 lines (89 loc) · 2.86 KB
/
Copy pathapphost.ts
File metadata and controls
104 lines (89 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
namespace microcode {
export const UI_SCREEN_WIDTH = 160
export const UI_SCREEN_HEIGHT = 120
class AppAssetResolver implements ui.UiAssetResolver {
public getBitmap(
id: string | number,
nullIfMissing?: boolean,
): Bitmap | undefined {
if (id == "wordLogo") return wordLogo
const bitmap = icons.get(id, !!nullIfMissing)
if (bitmap) return bitmap
if (nullIfMissing) return undefined
return icons.get("MISSING")
}
public getText(id: string): string {
return resolveTooltip(id)
}
}
/**
* Owns the screen runtime and app-level navigation.
*/
export class AppHost {
private app_: App
private runtime_: ui.UiRuntime
get runtime() {
return this.runtime_
}
constructor(app: App) {
this.app_ = app
this.runtime_ = new ui.UiRuntime(
new ui.DisplayShieldFrameAdapter(),
new AppAssetResolver(),
)
}
/**
* Opens the screen runtime with a root screen.
*/
public open(root: ui.UiScreen): void {
this.runtime_.push(root)
this.runtime_.start()
}
public push(screen: ui.UiScreen): void {
if (!this.runtime_) {
this.open(screen)
return
}
this.runtime_.push(screen)
}
public replace(screen: ui.UiScreen): void {
if (!this.runtime_.depth()) {
this.open(screen)
return
}
this.runtime_.replace(screen)
}
public pop(): void {
if (!this.runtime_ || this.runtime_.depth() <= 1) return
this.runtime_.pop()
}
public launchHome(): void {
const screen = new HomeScreen(this)
if (this.runtime_) this.replace(screen)
else this.open(screen)
}
public launchEditor(): void {
const screen = new EditorScreen(this, this.app_)
if (this.runtime_) this.replace(screen)
else this.open(screen)
}
public launchSamples(): void {
this.push(new SamplesGalleryScreen(this))
}
public launchSettings(): void {
this.push(new SettingsScreen(this))
}
public close(): void {
if (!this.runtime_) return
this.runtime_.stop()
while (this.runtime_.depth()) this.runtime_.pop()
this.runtime_ = undefined
}
public currentEditorProgram(): ProgramDefn {
const screen = this.runtime_ ? this.runtime_.top() : undefined
return screen instanceof EditorScreen
? screen.currentProgram()
: undefined
}
}
}