wasm-demo/ui/src
Manos Pitsidianakis 7d6526dede
ui: add BraillePixelIter
Iterate on 2x4 pixel blocks from a bitmap and return a unicode braille character for each
block. The iterator holds four lines of bitmaps encoded as `u16` numbers in swapped bit
order, like the `xbm` graphics format. The bitmap is split to `u16` columns.

```rust
/* BEE is the contents of a 48x48 xbm file. xbm is a C-like array of 8bit values, and
 * each pair was manually (macro-ually?) condensed into a single 16bit value. Each 3 items
 * represent one pixel row.
 */
const BEE: [u16; 3 * 48] = [
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
    0x0000, 0x0002, 0x0000, 0x0000, 0xe003, 0x0000, 0x0000, 0xfc00, 0x0000, 0x0000, 0x3f00,
    0x0000, 0x00e0, 0x0f00, 0x0000, 0x00f8, 0x0300, 0x0000, 0x00fe, 0x0000, 0x0080, 0x8f0d,
    0x0000, 0x00e0, 0xff7f, 0x0000, 0x00f8, 0xffff, 0x0300, 0x00fc, 0xffff, 0x0f00, 0x00fe,
    0xffff, 0x3f00, 0x00ff, 0xffff, 0xff00, 0xc0ff, 0xffff, 0xff01, 0xc0ff, 0xff77, 0xff07,
    0xf0f9, 0xffff, 0xff07, 0xf0f0, 0xffef, 0xfd0f, 0xf0e0, 0xffff, 0xfb1f, 0xf0e1, 0xffc1,
    0xfb0f, 0xe0f3, 0xffc3, 0xf307, 0xc0f7, 0xffc0, 0xe100, 0xc0ff, 0xd9e0, 0x3f00, 0x803e,
    0xc1f8, 0x5f00, 0x8076, 0x43f4, 0xbf18, 0x806c, 0x43fc, 0xf325, 0x0009, 0xc3df, 0x4326,
    0x001a, 0xcf3f, 0x622d, 0x0034, 0xff01, 0x2224, 0x00f0, 0xff00, 0x8312, 0x00a0, 0x5700,
    0x0309, 0x00f8, 0x1b00, 0x8f06, 0x0048, 0x6000, 0xcd03, 0x0018, 0x6624, 0xdf00, 0x0030,
    0x820f, 0x3f00, 0x00c0, 0xf0ff, 0x3f00, 0x0080, 0x03fe, 0x7f00, 0x0000, 0x7ce0, 0x0f00,
    0x0000, 0x809f, 0x1c00, 0x0000, 0x0000, 0x3800, 0x0000, 0x0000, 0x7000, 0x0000, 0x0000,
    0xe000,
];

for lines in BEE.chunks(12) {
    let iter = ui::BraillePixelIter::from(lines);
    for b in iter {
        print!("{}", b);
    }
    println!("");
}
```

Output:

```text
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣶⠾⠛⠉⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢀⣠⣤⣤⣀⣠⣔⣾⣛⡛⠉⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣀⠀⠀⠀⠀
⠀⠀⣤⣿⠟⠻⣿⣿⣿⣿⣿⣿⣿⣯⢿⣯⡿⣿⣿⣿⣷⣆⠀⠀
⠀⠀⠻⣿⣦⡀⣼⣿⣿⣿⣿⣿⠯⠉⠉⣿⡿⠘⢿⣿⠿⠟⠁⠀
⠀⠀⠀⢹⠹⣟⢿⡍⣧⠈⠁⡟⠀⣔⣾⣿⣿⠿⣯⣢⡀⡠⢄⠀
⠀⠀⠀⠀⠑⠜⣦⣀⣿⣶⣤⣿⠟⠛⠓⠉⣹⠀⠰⢃⢊⠗⡸⠀
⠀⠀⠀⠀⠀⢰⡚⠞⢛⡑⢣⡅⠀⡀⢀⠀⣟⣶⡀⣴⠵⠊⠀⠀
⠀⠀⠀⠀⠀⠀⠉⠲⠬⣀⣒⡚⠻⠿⢶⣶⣿⣿⠿⠄⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠁⠈⠀⠙⢷⣄⠀⠀⠀
```
2020-02-04 02:58:24 +02:00
..
components Rename `mime_apps` dependency to `xdg-utils` 2020-02-04 02:58:24 +02:00
conf ui/themes: add NO_COLOR support 2020-01-27 20:17:46 +02:00
execute melib: add ThreadGroup 2020-01-20 16:03:06 +02:00
plugins Fix some unused etc warnings 2020-01-27 17:32:12 +02:00
terminal Add missing copyright preambles 2020-01-31 03:54:58 +02:00
types Plugins WIP #2 2019-12-27 17:57:48 +02:00
cache.rs Replace StackVec with smallvec::SmallVec 2020-01-20 15:58:59 +02:00
components.rs ui: remove unnecessary unreachable panics in set_and_join_box 2020-02-04 02:58:24 +02:00
conf.rs ui/conf: replace include macro with m4 include macro 2020-01-29 05:54:13 +02:00
execute.rs melib/imap: add mailbox creation ability 2020-01-20 15:58:59 +02:00
lib.rs Rename `mime_apps` dependency to `xdg-utils` 2020-02-04 02:58:24 +02:00
mailcap.rs melib: Replace String with Cow<'static, str> 2020-01-07 12:55:27 +02:00
plugins.rs plugin-backend: add BackendOp for PluginBackend 2020-01-02 00:13:18 +02:00
sample-plugin.py Plugins WIP 2019-12-23 17:08:57 +02:00
sqlite3.rs Replace StackVec with smallvec::SmallVec 2020-01-20 15:58:59 +02:00
state.rs ui/themes: add NO_COLOR support 2020-01-27 20:17:46 +02:00
terminal.rs ui: add BraillePixelIter 2020-02-04 02:58:24 +02:00
types.rs Minor changes 2020-01-22 00:04:14 +02:00
workers.rs Add missing copyright preambles 2020-01-31 03:54:58 +02:00