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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
|
//! The backend end to end, with no terminal.
//!
//! Every one of these mounts real nodes through the same calls the ABI makes,
//! paints a real frame, and asserts on the lines that came out — which is the
//! whole reason painting goes through a grid. Nothing here needs a TTY, a
//! display or raw mode, so it all runs in CI.
use crate::screen::attr;
use crate::tree::Value;
use crate::ui::Ui;
fn ui() -> Ui {
Ui::new(24, 8)
}
/// Mount `tag` under `parent` with the string props given.
fn node(ui: &mut Ui, parent: u32, tag: &str, props: &[(&str, &str)]) -> u32 {
let id = ui.tree.new_node(tag);
for (key, value) in props {
ui.tree.set(id, key, Value::Str((*value).to_owned()));
}
ui.tree.append(parent, id);
id
}
fn events(ui: &mut Ui) -> Vec<(u32, String, String, f64)> {
let mut out = Vec::new();
while ui.tree.poll() {
let event = ui.tree.current().unwrap();
out.push((
event.node,
event.name.to_owned(),
event.text.clone(),
event.num,
));
}
out
}
#[test]
fn a_column_paints_its_children_down_the_page() {
let mut ui = ui();
let root = ui.tree.root();
node(&mut ui, root, "label", &[("label", "first")]);
node(&mut ui, root, "label", &[("label", "second")]);
ui.frame();
assert_eq!(ui.screen.line(0), "first");
assert_eq!(ui.screen.line(1), "second");
}
#[test]
fn a_row_paints_its_children_across_with_its_spacing_between_them() {
let mut ui = ui();
let root = ui.tree.root();
let row = node(&mut ui, root, "hbox", &[("orientation", "horizontal")]);
ui.tree.set(row, "spacing", Value::Num(2.0));
node(&mut ui, row, "label", &[("label", "aa")]);
node(&mut ui, row, "label", &[("label", "bb")]);
ui.frame();
assert_eq!(ui.screen.line(0), "aa bb");
}
#[test]
fn a_label_wraps_to_the_width_it_was_given() {
let mut ui = Ui::new(10, 4);
let root = ui.tree.root();
node(&mut ui, root, "label", &[("label", "one two three four")]);
ui.frame();
assert_eq!(ui.screen.line(0), "one two");
assert_eq!(ui.screen.line(1), "three four");
}
#[test]
fn a_frame_draws_a_border_with_its_label_in_the_top_edge() {
let mut ui = Ui::new(12, 4);
let root = ui.tree.root();
let frame = node(&mut ui, root, "frame", &[("label", "Task")]);
node(&mut ui, frame, "label", &[("label", "hi")]);
ui.frame();
assert_eq!(ui.screen.line(0), "┌ Task ────┐");
assert_eq!(ui.screen.line(1), "│hi │");
assert_eq!(ui.screen.line(2), "└──────────┘");
}
#[test]
fn the_first_focusable_widget_takes_focus_and_tab_walks_the_ring() {
let mut ui = ui();
let root = ui.tree.root();
let first = node(&mut ui, root, "button", &[("label", "one")]);
let second = node(&mut ui, root, "button", &[("label", "two")]);
ui.frame();
assert_eq!(ui.focus(), first);
ui.key("tab");
assert_eq!(ui.focus(), second);
ui.key("tab");
assert_eq!(ui.focus(), first, "the ring wraps");
ui.key("shift+tab");
assert_eq!(ui.focus(), second);
}
#[test]
fn autofocus_beats_paint_order() {
let mut ui = ui();
let root = ui.tree.root();
node(&mut ui, root, "button", &[("label", "one")]);
let wanted = node(&mut ui, root, "entry", &[]);
ui.tree.set(wanted, "autofocus", Value::Bool(true));
ui.frame();
assert_eq!(ui.focus(), wanted);
}
#[test]
fn a_focused_button_is_drawn_in_reverse_and_activates_on_enter() {
let mut ui = ui();
let root = ui.tree.root();
let button = node(&mut ui, root, "button", &[("label", "go")]);
ui.frame();
assert_eq!(ui.screen.line(0), "[ go ]");
assert!(ui.screen.cell(0, 0).unwrap().style.has(attr::REVERSE));
ui.key("enter");
assert_eq!(
events(&mut ui),
vec![(button, "click".into(), String::new(), 0.0)]
);
}
#[test]
fn a_checkbutton_writes_its_new_state_back_as_well_as_reporting_it() {
let mut ui = ui();
let root = ui.tree.root();
let check = node(&mut ui, root, "checkbutton", &[("label", "live")]);
ui.frame();
assert_eq!(ui.screen.line(0), "[ ] live");
ui.key("space");
assert_eq!(
events(&mut ui),
vec![(check, "toggled".into(), String::new(), 1.0)]
);
// A caller that ignores the event still has a working control.
assert_eq!(ui.tree.props(check).bool("active", false), true);
ui.frame();
assert_eq!(ui.screen.line(0), "[x] live");
}
#[test]
fn typing_in_an_entry_edits_its_text_and_reports_every_change() {
let mut ui = ui();
let root = ui.tree.root();
let entry = node(&mut ui, root, "entry", &[("placeholder", "name")]);
ui.frame();
assert_eq!(
ui.screen.line(0),
"name",
"the placeholder shows until it is typed in"
);
for key in ["h", "i", "space", "there"] {
for name in [key] {
if name.chars().count() > 1 && name != "space" {
for ch in name.chars() {
ui.key(&ch.to_string());
}
} else {
ui.key(name);
}
}
}
assert_eq!(ui.tree.props(entry).str("text"), "hi there");
let changes = events(&mut ui);
assert_eq!(changes.len(), 8);
assert_eq!(changes.last().unwrap().2, "hi there");
ui.frame();
assert_eq!(ui.screen.line(0), "hi there");
}
#[test]
fn readline_keys_edit_where_the_caret_is() {
let mut ui = ui();
let root = ui.tree.root();
let entry = node(&mut ui, root, "entry", &[("text", "one two three")]);
ui.frame();
ui.key("ctrl+w");
assert_eq!(ui.tree.props(entry).str("text"), "one two ");
ui.key("ctrl+a");
ui.key("delete");
assert_eq!(ui.tree.props(entry).str("text"), "ne two ");
ui.key("ctrl+e");
ui.key("backspace");
assert_eq!(ui.tree.props(entry).str("text"), "ne two");
ui.key("ctrl+u");
assert_eq!(ui.tree.props(entry).str("text"), "");
}
#[test]
fn enter_in_an_entry_activates_rather_than_typing() {
let mut ui = ui();
let root = ui.tree.root();
let entry = node(&mut ui, root, "entry", &[("text", "search")]);
ui.frame();
ui.key("enter");
assert_eq!(
events(&mut ui),
vec![(entry, "activate".into(), "search".into(), 0.0)]
);
assert_eq!(ui.tree.props(entry).str("text"), "search");
}
#[test]
fn a_listbox_moves_its_cursor_with_the_arrows_and_with_j_and_k() {
let mut ui = ui();
let root = ui.tree.root();
let list = node(&mut ui, root, "listbox", &[]);
for name in ["alpha", "beta", "gamma"] {
node(&mut ui, list, "label", &[("label", name)]);
}
ui.frame();
assert_eq!(ui.screen.line(0), "› alpha");
ui.key("j");
assert_eq!(
events(&mut ui),
vec![(list, "select".into(), "beta".into(), 1.0)]
);
ui.key("G");
assert_eq!(ui.tree.props(list).num("selected", -1.0), 2.0);
ui.key("enter");
assert_eq!(
events(&mut ui),
vec![
(list, "select".into(), "gamma".into(), 2.0),
(list, "activate".into(), "gamma".into(), 2.0)
]
);
ui.frame();
assert_eq!(ui.screen.line(2), "› gamma");
}
#[test]
fn a_key_nothing_wanted_reaches_the_caller_as_an_event() {
let mut ui = ui();
let root = ui.tree.root();
let button = node(&mut ui, root, "button", &[("label", "go")]);
ui.frame();
assert!(!ui.key("f5"));
assert_eq!(
events(&mut ui),
vec![(button, "key".into(), "f5".into(), 0.0)]
);
}
#[test]
fn ctrl_c_asks_the_loop_to_stop() {
let mut ui = ui();
assert!(!ui.should_close());
ui.key("ctrl+c");
assert!(ui.should_close());
}
#[test]
fn an_insensitive_subtree_is_dimmed_and_out_of_the_focus_ring() {
let mut ui = ui();
let root = ui.tree.root();
let column = node(&mut ui, root, "vbox", &[]);
ui.tree.set(column, "sensitive", Value::Bool(false));
node(&mut ui, column, "button", &[("label", "go")]);
let live = node(&mut ui, root, "button", &[("label", "live")]);
ui.frame();
assert!(ui.screen.cell(0, 0).unwrap().style.has(attr::DIM));
assert_eq!(ui.focus(), live);
}
#[test]
fn a_click_focuses_and_activates_what_is_under_it() {
let mut ui = ui();
let root = ui.tree.root();
node(&mut ui, root, "button", &[("label", "one")]);
let second = node(&mut ui, root, "button", &[("label", "two")]);
ui.frame();
assert!(ui.click(2, 1));
assert_eq!(ui.focus(), second);
assert_eq!(
events(&mut ui),
vec![(second, "click".into(), String::new(), 0.0)]
);
assert!(!ui.click(20, 7), "a click on nothing is not an event");
}
#[test]
fn a_scroll_shows_a_window_of_its_content_and_will_not_go_past_the_end() {
let mut ui = Ui::new(10, 3);
let root = ui.tree.root();
let scroll = node(&mut ui, root, "scroll", &[]);
for i in 0..6 {
node(&mut ui, scroll, "label", &[("label", &format!("row {i}"))]);
}
ui.frame();
assert_eq!(ui.screen.lines(), vec!["row 0", "row 1", "row 2"]);
ui.wheel(1, 1, 2);
ui.frame();
assert_eq!(ui.screen.lines(), vec!["row 2", "row 3", "row 4"]);
ui.wheel(1, 1, 40);
ui.frame();
assert_eq!(ui.screen.lines(), vec!["row 3", "row 4", "row 5"]);
// The clamped viewport is written back, so the next scroll up starts from
// where the reader actually is.
assert_eq!(ui.tree.props(scroll).num("offset", -1.0), 3.0);
}
#[test]
fn the_wheel_scrolls_the_list_under_the_pointer_not_the_first_one_painted() {
// frq's wide layout: the chats list down the left, the conversation beside
// it, and both of them scrolls. A wheel over the conversation used to move
// the sidebar — every scroll answered to a pointer anywhere on screen, so
// the first one the walk reached took the lot.
let mut ui = Ui::new(20, 3);
let root = ui.tree.root();
let row = node(&mut ui, root, "hbox", &[("orientation", "horizontal")]);
let sidebar = node(&mut ui, row, "scroll", &[]);
ui.tree.set(sidebar, "width-request", Value::Num(10.0));
for i in 0..6 {
node(&mut ui, sidebar, "label", &[("label", &format!("chat {i}"))]);
}
let backlog = node(&mut ui, row, "scroll", &[]);
ui.tree.set(backlog, "width-request", Value::Num(10.0));
for i in 0..6 {
node(&mut ui, backlog, "label", &[("label", &format!("line {i}"))]);
}
ui.frame();
assert_eq!(ui.screen.line(0), "chat 0 line 0");
ui.wheel(15, 1, 2);
ui.frame();
assert_eq!(
ui.screen.line(0),
"chat 0 line 2",
"the wheel was over the backlog, and only the backlog moved"
);
ui.wheel(2, 1, 1);
ui.frame();
assert_eq!(
ui.screen.line(0),
"chat 1 line 2",
"and over the sidebar it is the sidebar that moves"
);
}
#[test]
fn page_keys_move_the_backlog_while_the_entry_keeps_the_focus() {
let mut ui = Ui::new(10, 4);
let root = ui.tree.root();
let scroll = node(&mut ui, root, "scroll", &[]);
for i in 0..9 {
node(&mut ui, scroll, "label", &[("label", &format!("row {i}"))]);
}
// What a reader is typing into, under the list they are reading.
let entry = node(&mut ui, root, "entry", &[("text", "hi")]);
ui.frame();
assert_eq!(ui.screen.line(0), "row 0");
assert!(ui.key("page-down"), "the page was taken, not passed on");
ui.frame();
// A page is the viewport less the line that says where you were.
assert_eq!(ui.screen.line(0), "row 2");
assert_eq!(ui.focus(), entry, "and the entry still has the keyboard");
ui.key("page-up");
ui.frame();
assert_eq!(ui.screen.line(0), "row 0");
assert!(events(&mut ui).iter().all(|(_, name, _, _)| name != "key"));
}
#[test]
fn a_wheel_between_a_re_render_and_a_frame_moves_from_where_the_list_was() {
// A render clears a node's props and writes them again; a wheel or a page
// key that landed in that gap used to read an offset of zero and answer
// with the top of the buffer.
let mut ui = Ui::new(10, 3);
let root = ui.tree.root();
let scroll = node(&mut ui, root, "scroll", &[("scroll-key", "backlog")]);
for i in 0..9 {
node(&mut ui, scroll, "label", &[("label", &format!("row {i}"))]);
}
ui.frame();
ui.wheel(1, 1, 4);
ui.frame();
assert_eq!(ui.screen.line(0), "row 4");
// The caller re-renders the list: props off, props on, no frame between.
ui.tree.clear_props(scroll);
ui.tree
.set(scroll, "scroll-key", Value::Str("backlog".into()));
ui.wheel(1, 1, 1);
ui.frame();
assert_eq!(ui.screen.line(0), "row 5");
}
#[test]
fn a_reaction_paints_its_glyph_and_answers_a_click_on_it() {
let mut ui = Ui::new(20, 2);
let root = ui.tree.root();
let row = node(&mut ui, root, "hbox", &[("orientation", "horizontal")]);
ui.tree.set(row, "spacing", Value::Num(1.0));
let pill = node(&mut ui, row, "reaction", &[("emoji", "👍")]);
ui.tree.set(pill, "count", Value::Num(2.0));
ui.tree.set(pill, "mine", Value::Bool(true));
let chip = node(&mut ui, row, "reaction", &[("emoji", "🙂")]);
ui.frame();
// The tally where there is one; the bare glyph where there is not — that
// is the chip you press to start one.
assert_eq!(ui.screen.line(0), "👍 2 🙂");
// Two cells for the glyph, so the chip after it starts where it looks
// like it starts.
assert!(ui.click(5, 0), "the chip took the click");
assert_eq!(
events(&mut ui),
vec![(chip, "click".into(), String::new(), 0.0)]
);
// And by keyboard, for a terminal with no pointer at all.
ui.key("shift+tab");
ui.key("enter");
assert_eq!(
events(&mut ui),
vec![(pill, "click".into(), String::new(), 0.0)]
);
}
#[test]
fn a_glyph_keeps_the_selector_that_says_to_draw_it_as_a_picture() {
let mut ui = Ui::new(10, 2);
let root = ui.tree.root();
// The reply chip: an arrow, and a selector asking for the emoji rather
// than the small mono arrow a terminal draws without it.
node(&mut ui, root, "reaction", &[("emoji", "↩️")]);
ui.frame();
assert_eq!(ui.screen.line(0), "↩\u{fe0f}");
// And it is two columns, like the emoji beside it on the row.
assert_eq!(ui.screen.cell(1, 0).map(|c| c.trail), Some(true));
}
#[test]
fn an_emoji_is_two_columns_wide_and_what_follows_it_knows_that() {
let mut ui = Ui::new(12, 3);
let root = ui.tree.root();
let row = node(&mut ui, root, "hbox", &[("orientation", "horizontal")]);
node(&mut ui, row, "label", &[("label", "👍")]);
let after = node(&mut ui, row, "button", &[("label", "ok")]);
// A label that has to wrap wraps by column, not by character.
node(&mut ui, root, "label", &[("label", "👍👍👍👍👍👍👍")]);
ui.frame();
assert_eq!(ui.screen.line(0), "👍[ ok ]");
assert_eq!(ui.screen.line(1), "👍👍👍👍👍👍");
// The button starts at column 2, because the glyph before it took two.
assert!(ui.click(2, 0));
assert_eq!(
events(&mut ui),
vec![(after, "click".into(), String::new(), 0.0)]
);
}
#[test]
fn an_overlay_floats_in_the_middle_over_whatever_was_under_it() {
let mut ui = Ui::new(14, 5);
let root = ui.tree.root();
node(&mut ui, root, "label", &[("label", "beneath")]);
let overlay = node(&mut ui, root, "overlay", &[("label", "Sure?")]);
node(&mut ui, overlay, "label", &[("label", "yes")]);
ui.frame();
assert_eq!(ui.screen.line(1), " ┌ Sure? ┐");
assert_eq!(ui.screen.line(2), " │yes │");
ui.key("esc");
assert_eq!(
events(&mut ui),
vec![(overlay, "close".into(), String::new(), 0.0)]
);
}
#[test]
fn a_progress_bar_fills_the_share_of_its_width_it_was_given() {
let mut ui = Ui::new(10, 2);
let root = ui.tree.root();
let bar = node(&mut ui, root, "progress", &[]);
ui.tree.set(bar, "value", Value::Num(0.5));
ui.frame();
assert_eq!(ui.screen.line(0), "█████░░░░░");
}
#[test]
fn colours_and_attributes_are_inherited_by_a_subtree() {
let mut ui = ui();
let root = ui.tree.root();
let column = node(&mut ui, root, "vbox", &[("color", "red")]);
ui.tree.set(column, "bold", Value::Bool(true));
node(&mut ui, column, "label", &[("label", "hi")]);
ui.frame();
let cell = ui.screen.cell(0, 0).unwrap();
assert_eq!(cell.style.fg, crate::screen::Color::Indexed(1));
assert!(cell.style.has(attr::BOLD));
}
#[test]
fn an_unknown_tag_still_shows_its_children() {
let mut ui = ui();
let root = ui.tree.root();
let odd = node(&mut ui, root, "sparkline", &[]);
node(&mut ui, odd, "label", &[("label", "inside")]);
ui.frame();
assert_eq!(ui.screen.line(0), "inside");
}
#[test]
fn focus_survives_a_repaint_and_lands_somewhere_when_its_widget_is_unmounted() {
let mut ui = ui();
let root = ui.tree.root();
let first = node(&mut ui, root, "button", &[("label", "one")]);
let second = node(&mut ui, root, "button", &[("label", "two")]);
ui.frame();
ui.key("tab");
assert_eq!(ui.focus(), second);
ui.frame();
assert_eq!(ui.focus(), second, "a repaint does not move the focus");
ui.tree.remove(root, second);
ui.frame();
assert_eq!(ui.focus(), first);
}
#[test]
fn an_unknown_leaf_paints_its_own_text() {
// A tag this backend does not know paints as a box so its children still
// show — but a leaf has none, and a `:status` badge or a `:link` in the
// middle of a message would otherwise be a hole in the sentence.
let mut ui = ui();
let root = ui.tree.root();
node(&mut ui, root, "status", &[("label", "joined")]);
node(&mut ui, root, "label", &[("label", "after")]);
ui.frame();
assert_eq!(ui.screen.line(0), "joined");
assert_eq!(ui.screen.line(1), "after");
}
#[test]
fn a_nested_column_paints_every_child_and_not_only_the_first() {
// Its rows were shared out by measuring each child at the *rows* it had
// rather than the columns, so a label wrapped to a paragraph, the overrun
// came off the end, and everything after the first child was handed
// nothing. Two levels down is where it showed: the top box is as wide as
// the screen and as tall, so the two numbers were close enough to hide it.
let mut ui = ui();
let root = ui.tree.root();
let col = node(&mut ui, root, "vbox", &[("orientation", "vertical")]);
node(&mut ui, col, "label", &[("label", "the first line")]);
node(&mut ui, col, "button", &[("label", "Open")]);
ui.frame();
assert_eq!(ui.screen.line(0), "the first line");
assert_eq!(ui.screen.line(1), "[ Open ]");
}
#[test]
fn an_unknown_leaf_that_names_a_picture_paints_nothing() {
// An `:avatar`'s label is the nick behind the face — words for something
// that cannot be drawn here, and in frq already on the row beside it.
let mut ui = ui();
let root = ui.tree.root();
node(
&mut ui,
root,
"avatar",
&[("label", "nandi.uk"), ("src", "/tmp/a.png")],
);
node(&mut ui, root, "label", &[("label", "nandi.uk")]);
ui.frame();
assert_eq!(ui.screen.line(0), "nandi.uk");
assert_eq!(ui.screen.line(1), "");
}
#[test]
fn a_sticky_viewport_opens_at_the_bottom_and_stays_there() {
// A backlog taller than its viewport, in a scroll that follows its own
// bottom: the newest line is what a chat client opens on, and a line
// arriving must not drag the screen out from under a reader who scrolled
// up to read history.
let mut ui = Ui::new(20, 3);
let root = ui.tree.root();
let scroll = node(
&mut ui,
root,
"scroll",
&[("scroll-key", "backlog"), ("stick-to-bottom", "true")],
);
for n in 1..=6 {
node(&mut ui, scroll, "label", &[("label", &format!("line {n}"))]);
}
ui.frame();
assert_eq!(ui.screen.line(2), "line 6");
// Scrolled up, and it stays where it was put across a re-render — the
// position lives under the key, not in a prop the next render clears.
ui.wheel(0, 0, -3);
ui.frame();
assert_eq!(ui.screen.line(0), "line 1");
ui.tree.clear_props(scroll);
ui.tree.set(scroll, "scroll-key", Value::Str("backlog".into()));
ui.tree
.set(scroll, "stick-to-bottom", Value::Bool(true));
ui.frame();
assert_eq!(ui.screen.line(0), "line 1");
// Back down to the bottom, and it follows again.
ui.wheel(0, 0, 9);
ui.frame();
node(&mut ui, scroll, "label", &[("label", "line 7")]);
ui.frame();
assert_eq!(ui.screen.line(2), "line 7");
}
#[test]
fn a_column_that_asks_for_a_width_gets_it_and_no_more() {
// Two panes in a row, the first with a width of its own. Its content is
// one long line, so measured naturally it is wider than the screen and the
// pane beside it is left nothing — which is the split view painting a
// sidebar and a ten-cell column of wrapped fragments.
let mut ui = Ui::new(40, 2);
let root = ui.tree.root();
let row = node(&mut ui, root, "hbox", &[("orientation", "horizontal")]);
let side = node(&mut ui, row, "vbox", &[]);
// A number, as the ABI sends one: a width read as a string is no width.
ui.tree.set(side, "width-request", Value::Num(10.0));
node(
&mut ui,
side,
"label",
&[("label", "a preview far longer than ten cells")],
);
let main = node(&mut ui, row, "vbox", &[]);
node(&mut ui, main, "label", &[("label", "the conversation")]);
ui.frame();
assert_eq!(ui.screen.line(0), "a preview the conversation");
}
#[test]
fn a_backlog_taller_than_the_screen_leaves_the_compose_bar_its_row() {
// The shape of frq's chat screen: a viewport holding more than fits, and
// under it the things you act with. A column that cannot shrink hands the
// scroll every row it asks for and paints the entry off the bottom edge.
let mut ui = Ui::new(20, 4);
let root = ui.tree.root();
let scroll = node(&mut ui, root, "scroll", &[("scroll-key", "backlog")]);
for n in 1..=10 {
node(&mut ui, scroll, "label", &[("label", &format!("line {n}"))]);
}
node(&mut ui, root, "separator", &[]);
node(&mut ui, root, "entry", &[("placeholder", "Message")]);
ui.frame();
assert_eq!(ui.screen.line(3), "Message");
}
|