anathema-default-widgets 0.2.7

Default widget implementations for Anathema
Documentation
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
use std::ops::ControlFlow;
use std::str::FromStr;

use anathema_geometry::{LocalPos, Pos, Region, Size};
use anathema_value_resolver::{AttributeStorage, Attributes, ValueKind};
use anathema_widgets::error::Result;
use anathema_widgets::layout::{Constraints, LayoutCtx, PositionCtx};
use anathema_widgets::paint::{Glyph, Glyphs, PaintCtx, SizePos};
use anathema_widgets::{AnyWidget, LayoutForEach, PaintChildren, PositionChildren, Widget, WidgetId};

use crate::layout::Axis;
use crate::layout::border::BorderLayout;
use crate::{HEIGHT, MAX_HEIGHT, MAX_WIDTH, MIN_HEIGHT, MIN_WIDTH, WIDTH};

pub const BORDER_STYLE: &str = "border_style";

// -----------------------------------------------------------------------------
//     - Indices -
//     Index into `DEFAULT_SLIM_EDGES` or `DEFAULT_THICK_EDGES`
// -----------------------------------------------------------------------------
pub const BORDER_EDGE_TOP_LEFT: usize = 0;
pub const BORDER_EDGE_TOP: usize = 1;
pub const BORDER_EDGE_TOP_RIGHT: usize = 2;
pub const BORDER_EDGE_RIGHT: usize = 3;
pub const BORDER_EDGE_BOTTOM_RIGHT: usize = 4;
pub const BORDER_EDGE_BOTTOM: usize = 5;
pub const BORDER_EDGE_BOTTOM_LEFT: usize = 6;
pub const BORDER_EDGE_LEFT: usize = 7;

// -----------------------------------------------------------------------------
//     - Sides -
// -----------------------------------------------------------------------------
bitflags::bitflags! {
    /// Border sides
    /// ```ignore
    /// let sides = Sides::TOP | Sides::LEFT;
    /// ```
    #[derive(Debug, Copy, Clone, PartialEq, Eq)]
    pub struct Sides: u8 {
        /// Empty
        const EMPTY = 0x0;
        /// Top border
        const TOP = 0b0001;
        /// Right border
        const RIGHT = 0b0010;
        /// Bottom border
        const BOTTOM = 0b0100;
        /// Left border
        const LEFT = 0b1000;
        /// All sides
        const ALL = Self::TOP.bits() | Self::RIGHT.bits() | Self::BOTTOM.bits() | Self::LEFT.bits();
    }
}

impl Default for Sides {
    fn default() -> Self {
        Self::ALL
    }
}

impl TryFrom<&ValueKind<'_>> for Sides {
    type Error = ();

    fn try_from(value: &ValueKind<'_>) -> Result<Self, Self::Error> {
        let mut sides = Sides::EMPTY;
        match value {
            ValueKind::Str(cow) => Sides::from_str(cow),
            ValueKind::List(list) => {
                for x in list {
                    sides |= Sides::try_from(x)?;
                }
                Ok(sides)
            }
            ValueKind::DynList(value) => {
                let Some(state) = value.as_state() else { return Err(()) };
                let Some(list) = state.as_any_list() else { return Err(()) };
                for i in 0..list.len() {
                    if sides == Sides::ALL {
                        break;
                    }
                    let value = list.lookup(i).ok_or(())?;
                    let value = value.as_state().ok_or(())?;
                    let s = value.as_str().ok_or(())?;
                    sides |= Sides::from_str(s)?;
                }
                Ok(sides)
            }
            _ => Err(()),
        }
    }
}

impl FromStr for Sides {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let sides = match s {
            "all" => Sides::ALL,
            "top" => Sides::TOP,
            "left" => Sides::LEFT,
            "right" => Sides::RIGHT,
            "bottom" => Sides::BOTTOM,
            _ => Sides::EMPTY,
        };
        Ok(sides)
    }
}

// -----------------------------------------------------------------------------
//   - Border types -
// -----------------------------------------------------------------------------
pub const DEFAULT_SLIM_EDGES: [Glyph; 8] = [
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
];

pub const DEFAULT_THICK_EDGES: [Glyph; 8] = [
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
    Glyph::from_char('', 1),
];

/// The style of the border.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub enum BorderStyle {
    /// ```text
    /// ┌─────┐
    /// │hello│
    /// └─────┘
    /// ```
    #[default]
    Thin,
    /// ```text
    /// ╔═════╗
    /// ║hello║
    /// ╚═════╝
    /// ```
    Thick,
    /// ```text
    /// 0111112
    /// 7hello3
    /// 6555554
    /// ```
    Custom([Glyph; 8]),
}

impl BorderStyle {
    pub fn edges(&self) -> [Glyph; 8] {
        match self {
            BorderStyle::Thin => DEFAULT_SLIM_EDGES,
            BorderStyle::Thick => DEFAULT_THICK_EDGES,
            BorderStyle::Custom(edges) => *edges,
        }
    }
}

struct Brush {
    glyph: Glyph,
    width: u8,
}

impl Brush {
    pub fn new(glyph: Glyph, width: u8) -> Self {
        Self { width, glyph }
    }
}

struct BorderPainter {
    top: Line,
    bottom: Line,
    left: Line,
    right: Line,
}

struct Line {
    start_cap: Option<Brush>,
    middle: Option<Brush>,
    end_cap: Option<Brush>,
    start: LocalPos,
    end: u16,
    axis: Axis,
}

impl Line {
    fn will_draw(&self) -> bool {
        self.start_cap.is_some() || self.end_cap.is_some() || self.middle.is_some()
    }

    fn draw<F>(&self, f: &mut F)
    where
        F: FnMut(LocalPos, Glyph),
    {
        let mut pos = self.start;
        let mut end = self.end;

        if let Some(brush) = &self.start_cap {
            f(pos, brush.glyph);
            match self.axis {
                Axis::Horizontal => pos.x += brush.width as u16,
                Axis::Vertical => pos.y += 1,
            }
        }

        if let Some(brush) = &self.end_cap {
            let pos = match self.axis {
                Axis::Horizontal => {
                    end -= brush.width as u16;
                    LocalPos::new(end, pos.y)
                }
                Axis::Vertical => {
                    end -= 1;
                    LocalPos::new(pos.x, end)
                }
            };
            f(pos, brush.glyph);
        }

        if let Some(brush) = &self.middle {
            loop {
                match self.axis {
                    Axis::Horizontal => {
                        if pos.x + brush.width as u16 > end {
                            break;
                        }
                        f(pos, brush.glyph);
                        pos.x += brush.width as u16;
                    }
                    Axis::Vertical => {
                        if pos.y + 1 > end {
                            break;
                        }
                        f(pos, brush.glyph);
                        pos.y += 1;
                    }
                }
            }
        }
    }
}

impl BorderPainter {
    fn new(glyphs: &[Glyph; 8], border_size: BorderSize, size: Size) -> Self {
        let mut height = size.height;

        let top = Line {
            start_cap: (border_size.top_left > 0).then(|| Brush::new(glyphs[0], border_size.top_left)),
            middle: (border_size.top > 0).then(|| Brush::new(glyphs[1], border_size.top)),
            end_cap: (border_size.top_right > 0).then(|| Brush::new(glyphs[2], border_size.top_right)),
            start: LocalPos::ZERO,
            axis: Axis::Horizontal,
            end: size.width,
        };

        let bottom = Line {
            start_cap: (border_size.bottom_left > 0).then(|| Brush::new(glyphs[6], border_size.bottom_left)),
            middle: (border_size.bottom > 0).then(|| Brush::new(glyphs[5], border_size.bottom)),
            end_cap: (border_size.bottom_right > 0).then(|| Brush::new(glyphs[4], border_size.bottom_right)),
            start: LocalPos::new(0, height - 1),
            axis: Axis::Horizontal,
            end: size.width,
        };

        if bottom.will_draw() {
            height -= 1;
        }

        let mut offset = 0;
        if top.will_draw() {
            offset += 1;
        }

        let left = Line {
            start_cap: None,
            middle: (border_size.left > 0).then(|| Brush::new(glyphs[7], border_size.left)),
            end_cap: None,
            start: LocalPos::new(0, offset),
            axis: Axis::Vertical,
            end: height,
        };

        let right = Line {
            start_cap: None,
            middle: (border_size.right > 0).then(|| Brush::new(glyphs[3], border_size.right)),
            end_cap: None,
            start: LocalPos::new(size.width - border_size.right as u16, offset),
            axis: Axis::Vertical,
            end: height,
        };

        Self {
            top,
            bottom,
            left,
            right,
        }
    }

    fn paint<F>(&mut self, mut f: F)
    where
        F: FnMut(LocalPos, Glyph),
    {
        self.top.draw(&mut f);
        self.bottom.draw(&mut f);
        self.left.draw(&mut f);
        self.right.draw(&mut f);
    }
}

/// Width of every character that makes up the border
#[derive(Debug, Default, Copy, Clone)]
pub(crate) struct BorderSize {
    pub top_left: u8,
    pub top: u8,
    pub top_right: u8,
    pub right: u8,
    pub bottom_right: u8,
    pub bottom: u8,
    pub bottom_left: u8,
    pub left: u8,
}

impl BorderSize {
    pub(crate) fn as_size(&self) -> Size {
        let left_width = self.left.max(self.top_left).max(self.bottom_left) as u16;
        let right_width = self.right.max(self.top_right).max(self.bottom_right) as u16;

        Size::new(left_width + right_width, (self.top + self.bottom) as u16)
    }
}

/// Draw a border around an element.
///
/// The border will size it self around the child if it has one.
///
/// If a width and / or a height is provided then the border will produce tight constraints
/// for the child.
///
/// If a border has no size (width and height) and no child then nothing will be rendered.
///
/// To render a border with no child provide a width and a height.
#[derive(Debug)]
pub struct Border {
    /// The border style decides the characters
    /// to be used for each side of the border.
    border_style: BorderStyle,
    /// Which sides of the border should be rendered.
    sides: Sides,
    /// All the characters for the border, starting from the top left moving clockwise.
    /// This means the top-left corner is `edges[0]`, the top if `edges[1]` and the top right is
    /// `edges[2]` etc.
    edges: [Glyph; 8],
}

impl Border {
    // The additional size of the border
    // to subtract from the constraint.
    fn border_size(&self, sides: Sides) -> BorderSize {
        // Get the size of the border (thickness).
        // This is NOT including the child.

        let mut border_size = BorderSize::default();

        if sides.contains(Sides::LEFT | Sides::TOP) {
            border_size.top_left = self.edges[BORDER_EDGE_TOP_LEFT].width() as u8;
        }

        if sides.contains(Sides::LEFT | Sides::BOTTOM) {
            border_size.bottom_left = self.edges[BORDER_EDGE_BOTTOM_LEFT].width() as u8;
        }

        if sides.contains(Sides::RIGHT | Sides::BOTTOM) {
            border_size.bottom_right = self.edges[BORDER_EDGE_BOTTOM_RIGHT].width() as u8;
        }

        if sides.contains(Sides::RIGHT | Sides::TOP) {
            border_size.top_right = self.edges[BORDER_EDGE_TOP_RIGHT].width() as u8;
        }

        if sides.contains(Sides::LEFT) {
            border_size.left = self.edges[BORDER_EDGE_LEFT].width() as u8;
        }

        if sides.contains(Sides::RIGHT) {
            border_size.right = self.edges[BORDER_EDGE_RIGHT].width() as u8;
        }

        if sides.contains(Sides::TOP) {
            border_size.top = self.edges[BORDER_EDGE_TOP].width() as u8;
        }

        if sides.contains(Sides::BOTTOM) {
            border_size.bottom = self.edges[BORDER_EDGE_BOTTOM].width() as u8;
        }

        border_size
    }
}

impl Widget for Border {
    fn layout<'bp>(
        &mut self,
        children: LayoutForEach<'_, 'bp>,
        constraints: Constraints,
        id: WidgetId,
        ctx: &mut LayoutCtx<'_, 'bp>,
    ) -> Result<Size> {
        let attributes = ctx.attribute_storage.get_mut(id);

        self.sides = attributes.get_as::<Sides>("sides").unwrap_or_default();

        self.border_style = match attributes.get(BORDER_STYLE) {
            None => BorderStyle::Thin,
            Some(val) => {
                let s = val.as_str();
                let mut edges = DEFAULT_SLIM_EDGES;
                let mut index = 0;

                match s {
                    Some("thin") | None => BorderStyle::default(),
                    Some("thick") => BorderStyle::Thick,
                    Some(s) => {
                        let mut glyphs = Glyphs::new(s);
                        while let Some(g) = glyphs.next(ctx.glyph_map) {
                            edges[index] = g;
                            index += 1;
                            if index >= DEFAULT_SLIM_EDGES.len() {
                                break;
                            };
                        }
                        BorderStyle::Custom(edges)
                    }
                }
            }
        };
        self.edges = self.border_style.edges();

        let mut layout = BorderLayout {
            min_width: attributes.get_as::<u16>(MIN_WIDTH),
            min_height: attributes.get_as::<u16>(MIN_HEIGHT),
            max_width: attributes.get_as::<u16>(MAX_WIDTH),
            max_height: attributes.get_as::<u16>(MAX_HEIGHT),
            height: attributes.get_as::<u16>(HEIGHT),
            width: attributes.get_as::<u16>(WIDTH),
            border_size: self.border_size(self.sides),
        };

        layout.layout(children, constraints, ctx)
    }

    fn position<'bp>(
        &mut self,
        mut children: PositionChildren<'_, 'bp>,
        _: WidgetId,
        attribute_storage: &AttributeStorage<'bp>,
        mut ctx: PositionCtx,
    ) {
        _ = children.each(|child, children| {
            if self.sides.contains(Sides::TOP) {
                ctx.pos.y += 1;
            }

            if self.sides.contains(Sides::LEFT) {
                ctx.pos.x += self.edges[BORDER_EDGE_LEFT].width() as i32;
            }

            child.position(children, ctx.pos, attribute_storage, ctx.viewport);
            ControlFlow::Break(())
        });
    }

    fn paint<'bp>(
        &mut self,
        mut children: PaintChildren<'_, 'bp>,
        _id: WidgetId,
        attribute_storage: &AttributeStorage<'bp>,
        mut ctx: PaintCtx<'_, SizePos>,
    ) {
        let border_size = self.border_size(self.sides);

        _ = children.each(|child, children| {
            let ctx = ctx.to_unsized();
            child.paint(children, ctx, attribute_storage);
            ControlFlow::Break(())
        });

        // Draw the border
        // Only draw corners if there are connecting sides:
        // e.g Sides::Left | Sides::Top
        //
        // Don't draw corners if there are no connecting sides:
        // e.g Sides::Top | Sides::Bottom

        if ctx.local_size.width == 0 || ctx.local_size.height == 0 {
            return;
        }

        let mut painter = BorderPainter::new(&self.edges, border_size, ctx.local_size);
        let paint = |pos, glyph| {
            ctx.place_glyph(glyph, pos);
        };

        painter.paint(paint);
    }

    fn inner_bounds(&self, mut pos: Pos, mut size: Size) -> Region {
        let bs = self.border_size(self.sides);
        pos.x += bs.top_left.max(bs.bottom_left).max(bs.left) as i32;
        pos.y += bs.top as i32;
        size.width = size
            .width
            .saturating_sub(bs.top_right.max(bs.bottom_right).max(bs.right) as u16);
        size.height = size.height.saturating_sub(bs.bottom as u16);
        Region::from((pos, size))
    }
}

pub(crate) fn make(attributes: &Attributes<'_>) -> Box<dyn AnyWidget> {
    let sides = attributes.get_as::<Sides>("sides").unwrap_or_default();

    let text = Border {
        sides,
        edges: DEFAULT_SLIM_EDGES,
        border_style: BorderStyle::Thin,
    };

    Box::new(text)
}
//}

#[cfg(test)]
mod test {
    use crate::testing::TestRunner;

    #[test]
    fn thin_border() {
        let tpl = "border [width: 6, height: 4]";

        let expected = "
            ╔════════╗
            ║┌────┐  ║
            ║│    │  ║
            ║│    │  ║
            ║└────┘  ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn thick_border() {
        let tpl = "border [width: 6, height: 4, border_style: 'thick']";

        let expected = "
            ╔════════╗
            ║╔════╗  ║
            ║║    ║  ║
            ║║    ║  ║
            ║╚════╝  ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn custom_border() {
        let tpl = "border [width: 6, height: 4, border_style: '╔─╗│╝─╚│']";

        let expected = "
            ╔════════╗
            ║╔────╗  ║
            ║│    │  ║
            ║│    │  ║
            ║╚────╝  ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn border_top() {
        let tpl = "border [sides: 'top', width: 6, height: 4, border_style: '╔─╗│╝─╚│']";

        let expected = "
            ╔════════╗
            ║──────  ║
            ║        ║
            ║        ║
            ║        ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn border_top_bottom() {
        let tpl = "border [sides: 'bottom', width: 6, height: 4, border_style: '╔─╗│╝─╚│']";

        let expected = "
            ╔════════╗
            ║        ║
            ║        ║
            ║        ║
            ║──────  ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn border_left() {
        let tpl = "border [sides: 'left', width: 6, height: 4, border_style: '╔─╗│╝─╚│']";

        let expected = "
            ╔════════╗
            ║│       ║
            ║│       ║
            ║│       ║
            ║│       ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn border_right() {
        let tpl = "border [sides: 'right', width: 6, height: 4, border_style: '╔─╗│╝─╚│']";

        let expected = "
            ╔════════╗
            ║     │  ║
            ║     │  ║
            ║     │  ║
            ║     │  ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn border_top_left() {
        let tpl = "border [sides: ['top', 'left'], width: 6, height: 4, border_style: '╔─╗│╝─╚│']";

        let expected = "
            ╔════════╗
            ║╔─────  ║
            ║│       ║
            ║│       ║
            ║│       ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn border_bottom_right() {
        let tpl = "border [sides: ['bottom', 'right'], width: 6, height: 4]";

        let expected = "
            ╔════════╗
            ║     │  ║
            ║     │  ║
            ║     │  ║
            ║─────┘  ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn unsized_empty_border() {
        let tpl = "
            border [sides: '']
                text 'hi'
        ";

        let expected = "
            ╔════════╗
            ║hi      ║
            ║        ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 4)).instance().render_assert(expected);
    }

    #[test]
    fn sized_by_child() {
        let tpl = "
            border 
                text 'hello world'
            ";

        let expected = "
            ╔════════╗
            ║┌──────┐║
            ║│hello │║
            ║│world │║
            ║└──────┘║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }

    #[test]
    fn fixed_size() {
        let tpl = "
            border [width: 3 + 2, height: 2 + 2]
                text 'hello world'
            ";

        let expected = "
            ╔════════╗
            ║┌───┐   ║
            ║│hel│   ║
            ║│lo │   ║
            ║└───┘   ║
            ║        ║
            ║        ║
            ╚════════╝
        ";

        TestRunner::new(tpl, (8, 6)).instance().render_assert(expected);
    }
}