Skip to content

Commit 5c46d55

Browse files
committed
7338 - tile: architecture starting to crystallize
In particular, I'm starting to have opinions about how to scalably position the cursor at the end of each frame. One advantage of text mode without a pointer device (mouse/trackpad): only one cursor to track. UI can't be modified anywhere. That simplifies any reactive UI framework.
1 parent 4ef29dc commit 5c46d55

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

apps/tile/data.mu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ type sandbox {
33
data: (handle line)
44
# display data
55
cursor-call-path: (handle call-path-element)
6+
cursor-row: int
7+
cursor-col: int
68
expanded-words: (handle call-path)
79
partial-name-for-cursor-word: (handle word) # only when renaming word
810
partial-name-for-function: (handle word) # only when defining function

apps/tile/environment.mu

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# The architecture that seems to be crystallizing: the environment has two
2+
# areas: functions and sandbox.
3+
#
4+
# Rendering the environment requires rendering all areas.
5+
# Displaying the cursor requires displaying cursor for the area controlling the cursor.
6+
# Processing events for the environment requires processing events for the area controlling the cursor.
7+
#
8+
# Areas can have dialogs.
9+
# There can also be global dialogs (currently just one: goto function).
10+
# Areas are responsible for rendering their dialogs.
11+
# In practice this results in dialogs encapsulating the state they need to
12+
# decide whether to render.
13+
#
14+
# This will be useful if we add more areas in the future.
15+
116
type environment {
217
screen: (handle screen)
318
functions: (handle function)
@@ -1085,6 +1100,17 @@ fn render _env: (addr environment) {
10851100
#? print-string 0, "render-sandbox }\n"
10861101
# dialogs
10871102
render-goto-dialog screen, env
1103+
#
1104+
position-cursor screen, env
1105+
}
1106+
1107+
fn position-cursor screen: (addr screen), _env: (addr environment) {
1108+
var env/eax: (addr environment) <- copy _env
1109+
var cursor-sandbox-ah/eax: (addr handle sandbox) <- get env, cursor-sandbox
1110+
var cursor-sandbox/eax: (addr sandbox) <- lookup *cursor-sandbox-ah
1111+
var cursor-row/ecx: (addr int) <- get cursor-sandbox, cursor-row
1112+
var cursor-col/eax: (addr int) <- get cursor-sandbox, cursor-col
1113+
move-cursor screen, *cursor-row, *cursor-col
10881114
}
10891115

10901116
fn render-goto-dialog screen: (addr screen), _env: (addr environment) {
@@ -1135,13 +1161,11 @@ fn render-sandbox screen: (addr screen), functions: (addr handle function), bind
11351161
#
11361162
var curr-row/edx: int <- copy top-row
11371163
# cursor row, col
1138-
var cursor-row: int
11391164
var cursor-row-addr: (addr int)
1140-
var tmp/eax: (addr int) <- address cursor-row
1165+
var tmp/eax: (addr int) <- get sandbox, cursor-row
11411166
copy-to cursor-row-addr, tmp
1142-
var cursor-col: int
11431167
var cursor-col-addr: (addr int)
1144-
tmp <- address cursor-col
1168+
tmp <- get sandbox, cursor-col
11451169
copy-to cursor-col-addr, tmp
11461170
# render all but final line without stack
11471171
#? print-string 0, "render all but final line\n"
@@ -1165,9 +1189,8 @@ fn render-sandbox screen: (addr screen), functions: (addr handle function), bind
11651189
#
11661190
render-final-line-with-stack screen, functions, bindings, sandbox, curr-row, left-col, cursor-row-addr, cursor-col-addr
11671191
# at most one of the following dialogs will be rendered
1168-
render-rename-dialog screen, sandbox, cursor-row, cursor-col
1169-
render-define-dialog screen, sandbox, cursor-row, cursor-col
1170-
move-cursor screen, cursor-row, cursor-col
1192+
render-rename-dialog screen, sandbox
1193+
render-define-dialog screen, sandbox
11711194
}
11721195

11731196
fn render-final-line-with-stack screen: (addr screen), functions: (addr handle function), bindings: (addr table), _sandbox: (addr sandbox), top-row: int, left-col: int, cursor-row-addr: (addr int), cursor-col-addr: (addr int) {
@@ -1222,20 +1245,22 @@ fn final-line _sandbox: (addr sandbox), out: (addr handle line) {
12221245
copy-object curr-line-ah, out
12231246
}
12241247

1225-
fn render-rename-dialog screen: (addr screen), _sandbox: (addr sandbox), cursor-row: int, cursor-col: int {
1248+
fn render-rename-dialog screen: (addr screen), _sandbox: (addr sandbox) {
12261249
var sandbox/edi: (addr sandbox) <- copy _sandbox
12271250
var rename-word-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-cursor-word
12281251
var rename-word-mode?/eax: (addr word) <- lookup *rename-word-mode-ah?
12291252
compare rename-word-mode?, 0 # false
12301253
break-if-=
12311254
# clear a space for the dialog
1232-
var top-row/eax: int <- copy cursor-row
1255+
var cursor-row/ebx: (addr int) <- get sandbox, cursor-row
1256+
var top-row/eax: int <- copy *cursor-row
12331257
top-row <- subtract 3
1234-
var bottom-row/ecx: int <- copy cursor-row
1258+
var bottom-row/ecx: int <- copy *cursor-row
12351259
bottom-row <- add 3
1236-
var left-col/edx: int <- copy cursor-col
1260+
var cursor-col/ebx: (addr int) <- get sandbox, cursor-col
1261+
var left-col/edx: int <- copy *cursor-col
12371262
left-col <- subtract 0x10
1238-
var right-col/ebx: int <- copy cursor-col
1263+
var right-col/ebx: int <- copy *cursor-col
12391264
right-col <- add 0x10
12401265
clear-rect screen, top-row, left-col, bottom-row, right-col
12411266
draw-box screen, top-row, left-col, bottom-row, right-col
@@ -1254,30 +1279,34 @@ fn render-rename-dialog screen: (addr screen), _sandbox: (addr sandbox), cursor-
12541279
reset-formatting screen
12551280
print-string screen, " rename "
12561281
# draw the word, positioned appropriately around the cursor
1257-
var start-col/ecx: int <- copy cursor-col
1282+
var cursor-col/ebx: (addr int) <- get sandbox, cursor-col
1283+
var start-col/ecx: int <- copy *cursor-col
12581284
var word-ah?/edx: (addr handle word) <- get sandbox, partial-name-for-cursor-word
12591285
var word/eax: (addr word) <- lookup *word-ah?
12601286
var cursor-index/eax: int <- cursor-index word
12611287
start-col <- subtract cursor-index
1262-
move-cursor screen, cursor-row, start-col
1288+
var cursor-row/ebx: (addr int) <- get sandbox, cursor-row
1289+
move-cursor screen, *cursor-row, start-col
12631290
var word/eax: (addr word) <- lookup *word-ah?
12641291
print-word screen, word
12651292
}
12661293

1267-
fn render-define-dialog screen: (addr screen), _sandbox: (addr sandbox), cursor-row: int, cursor-col: int {
1294+
fn render-define-dialog screen: (addr screen), _sandbox: (addr sandbox) {
12681295
var sandbox/edi: (addr sandbox) <- copy _sandbox
12691296
var define-function-mode-ah?/ecx: (addr handle word) <- get sandbox, partial-name-for-function
12701297
var define-function-mode?/eax: (addr word) <- lookup *define-function-mode-ah?
12711298
compare define-function-mode?, 0 # false
12721299
break-if-=
12731300
# clear a space for the dialog
1274-
var top-row/eax: int <- copy cursor-row
1301+
var cursor-row/ebx: (addr int) <- get sandbox, cursor-row
1302+
var top-row/eax: int <- copy *cursor-row
12751303
top-row <- subtract 3
1276-
var bottom-row/ecx: int <- copy cursor-row
1304+
var bottom-row/ecx: int <- copy *cursor-row
12771305
bottom-row <- add 3
1278-
var left-col/edx: int <- copy cursor-col
1306+
var cursor-col/ebx: (addr int) <- get sandbox, cursor-col
1307+
var left-col/edx: int <- copy *cursor-col
12791308
left-col <- subtract 0x10
1280-
var right-col/ebx: int <- copy cursor-col
1309+
var right-col/ebx: int <- copy *cursor-col
12811310
right-col <- add 0x10
12821311
clear-rect screen, top-row, left-col, bottom-row, right-col
12831312
draw-box screen, top-row, left-col, bottom-row, right-col
@@ -1296,12 +1325,14 @@ fn render-define-dialog screen: (addr screen), _sandbox: (addr sandbox), cursor-
12961325
reset-formatting screen
12971326
print-string screen, " define "
12981327
# draw the word, positioned appropriately around the cursor
1299-
var start-col/ecx: int <- copy cursor-col
1328+
var cursor-col/ebx: (addr int) <- get sandbox, cursor-col
1329+
var start-col/ecx: int <- copy *cursor-col
13001330
var word-ah?/edx: (addr handle word) <- get sandbox, partial-name-for-function
13011331
var word/eax: (addr word) <- lookup *word-ah?
13021332
var cursor-index/eax: int <- cursor-index word
13031333
start-col <- subtract cursor-index
1304-
move-cursor screen, cursor-row, start-col
1334+
var cursor-row/ebx: (addr int) <- get sandbox, cursor-row
1335+
move-cursor screen, *cursor-row, start-col
13051336
var word/eax: (addr word) <- lookup *word-ah?
13061337
print-word screen, word
13071338
}

0 commit comments

Comments
 (0)