| 1 | //! Gallery: the Braille whale, its states, its pod and its compact sizes. |
| 2 | |
| 3 | use ratatui::{buffer::Buffer, layout::Rect}; |
| 4 | |
| 5 | use super::Entry; |
| 6 | use crate::{Paint, Theme, Whale, WhaleState}; |
| 7 | |
| 8 | fn whale(state: WhaleState) -> impl Fn(Rect, &mut Buffer, &Theme) { |
| 9 | move |area, buf, theme| Whale::new(state).paint(area, buf, theme) |
| 10 | } |
| 11 | |
| 12 | /// All 17 actions of the v2 whale at the compact size, three to a row. |
| 13 | fn whale_actions(area: Rect, buf: &mut Buffer, theme: &Theme) { |
| 14 | let area = area.intersection(buf.area); |
| 15 | if area.is_empty() { |
| 16 | return; |
| 17 | } |
| 18 | const CELL_W: u16 = 28; |
| 19 | const CELL_H: u16 = 11; |
| 20 | for (i, state) in WhaleState::ALL.into_iter().enumerate() { |
| 21 | let i = u16::try_from(i).unwrap_or(u16::MAX); |
| 22 | let cell = Rect { |
| 23 | x: area.x.saturating_add((i % 3) * CELL_W), |
| 24 | y: area.y.saturating_add((i / 3) * CELL_H), |
| 25 | width: CELL_W, |
| 26 | height: CELL_H, |
| 27 | } |
| 28 | .intersection(area); |
| 29 | Whale::new(state).paint(cell, buf, theme); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | pub(crate) fn entries() -> Vec<Entry> { |
| 34 | vec![ |
| 35 | Entry { |
| 36 | name: "whale-rest", |
| 37 | width: 36, |
| 38 | height: 17, |
| 39 | draw: |a, b, t| whale(WhaleState::Rest)(a, b, t), |
| 40 | }, |
| 41 | Entry { |
| 42 | name: "whale-busy", |
| 43 | width: 36, |
| 44 | height: 17, |
| 45 | draw: |a, b, t| whale(WhaleState::Busy)(a, b, t), |
| 46 | }, |
| 47 | Entry { |
| 48 | name: "whale-needs", |
| 49 | width: 36, |
| 50 | height: 17, |
| 51 | draw: |a, b, t| whale(WhaleState::NeedsYou)(a, b, t), |
| 52 | }, |
| 53 | Entry { |
| 54 | name: "whale-done", |
| 55 | width: 36, |
| 56 | height: 17, |
| 57 | draw: |a, b, t| whale(WhaleState::Done)(a, b, t), |
| 58 | }, |
| 59 | Entry { |
| 60 | name: "whale-pod-1", |
| 61 | width: 36, |
| 62 | height: 17, |
| 63 | draw: |a, b, t| whale(WhaleState::Pod { calves: 1 })(a, b, t), |
| 64 | }, |
| 65 | Entry { |
| 66 | name: "whale-pod-3", |
| 67 | width: 36, |
| 68 | height: 17, |
| 69 | draw: |a, b, t| whale(WhaleState::Pod { calves: 3 })(a, b, t), |
| 70 | }, |
| 71 | Entry { |
| 72 | name: "whale-actions", |
| 73 | width: 84, |
| 74 | height: 66, |
| 75 | draw: whale_actions, |
| 76 | }, |
| 77 | Entry { |
| 78 | name: "whale-compact", |
| 79 | width: 24, |
| 80 | height: 11, |
| 81 | draw: |a, b, t| whale(WhaleState::Busy)(a, b, t), |
| 82 | }, |
| 83 | Entry { |
| 84 | name: "whale-words-only", |
| 85 | width: 14, |
| 86 | height: 3, |
| 87 | draw: |a, b, t| whale(WhaleState::NeedsYou)(a, b, t), |
| 88 | }, |
| 89 | ] |
| 90 | } |
| 91 |