cosmic_applet_avestruz/views/components/mod.rs
1// SPDX-License-Identifier: MIT
2
3//! Reusable UI components for Avestruz.
4//!
5//! Most of what is on screen is a list of notes, and a note's row is
6//! most of these put together:
7//!
8//! ```mermaid
9//! flowchart TB
10//! subgraph scroller["The scroller, with its ScrollPosition first"]
11//! subgraph list["VirtualList: only the rows in view are built"]
12//! subgraph row["note_row: one note"]
13//! direction TB
14//! head["avatar, name, when"]
15//! text["What it says: text, links, mentions"]
16//! media["media_placeholder: its pictures, their room held"]
17//! video["video_box: its videos, played where they are"]
18//! quote["quoted_note: a card, and a card in it"]
19//! preview["link_preview: a card for the page it links to"]
20//! actions["Reply, repost (menu), react (emoji), zap, share link, bookmark, relays seen on"]
21//! head --- text --- media --- video --- quote --- preview --- actions
22//! end
23//! end
24//! end
25//! ```
26//!
27//! | Module | What it is |
28//! |---|---|
29//! | [`avatar`](mod@avatar) | Someone's picture, round, or what stands in for it |
30//! | [`card`](mod@card) | How something shown inside a note is set apart from it |
31//! | [`chip`](mod@chip) | A small choice button |
32//! | [`constants`](mod@constants) | Sizes shared between views, and the scroller they share |
33//! | [`icons`](mod@icons) | The app icon, embedded |
34//! | [`link_preview`](mod@link_preview) | What a web page a note links to says of itself, as a card |
35//! | [`media_placeholder`](mod@media_placeholder) | The space a picture will take, held while it loads |
36//! | [`menu`](mod@menu) | A small menu that opens under what was pressed |
37//! | [`note_row`](mod@note_row) | One note as a row of a list |
38//! | [`notification_row`](mod@notification_row) | One thing the account is told of, as a row of a list |
39//! | [`picture`](mod@picture) | A picture in a note, drawn pixel for pixel where it can be |
40//! | [`qr_code`](mod@qr_code) | A QR code, as a picture |
41//! | [`reaction_menu`](mod@reaction_menu) | What a note can be reacted to with: the emoji used most, and all there are |
42//! | [`quoted_note`](mod@quoted_note) | A note another note quotes, as a card under it |
43//! | [`scroll_position`](mod@scroll_position) | The scroller the views' lists are in, and how far it is scrolled |
44//! | [`status_line`](mod@status_line) | A line of small centred text |
45//! | [`video_box`](mod@video_box) | A video a note links to, where it plays, and the bar it is played by |
46//! | [`virtual_list`](mod@virtual_list) | A virtual list of rows of any height: what the feed, threads and profiles scroll in |
47
48pub mod avatar;
49pub mod badge;
50pub mod card;
51pub mod chip;
52pub mod constants;
53pub mod icons;
54pub mod link_preview;
55pub mod media_placeholder;
56pub mod menu;
57pub mod note_row;
58pub mod notification_row;
59pub mod picture;
60pub mod qr_code;
61pub mod quoted_note;
62pub mod reaction_menu;
63pub mod scroll_position;
64pub mod status_line;
65pub mod table_grid;
66pub mod video_box;
67pub mod virtual_list;
68
69pub use avatar::avatar;
70pub use badge::{count_badge, dot_badge};
71pub use card::{CARD_BORDER, CARD_RADIUS, card_style};
72pub use chip::chip;
73pub use constants::{
74 LIST_MAX_WIDTH, LIST_PADDING_LEFT, LIST_PADDING_RIGHT, LIST_SCROLL_ID, POPUP_MAX_HEIGHT_UNMEASURED, POPUP_MAX_WIDTH,
75 POPUP_MIN_HEIGHT, POPUP_MIN_WIDTH,
76};
77pub use icons::{
78 app_icon, bell_icon, bookmark_icon, fold_icon, like_icon, link_icon, relays_icon, reply_icon, repost_icon, zap_icon,
79};
80pub use link_preview::{link_preview, link_preview_height};
81pub use media_placeholder::{MediaPlaceholder, shown_size};
82pub use menu::{MENU_GAP, MENU_WIDTH, choice_menu, menu, menu_at, menu_height};
83pub use note_row::{
84 Bookmarking, Reacting, RowContext, RowSizes, estimated_note_height, link_line, marking, note_being_written, note_row,
85 opening_thread,
86};
87pub use notification_row::{estimated_notification_height, notification_row};
88pub use picture::Picture;
89pub use qr_code::qr_code;
90pub use quoted_note::{quote_link, quoted_note, quoted_note_height};
91pub use reaction_menu::{emoji_search_id, reaction_menu};
92pub use scroll_position::{PlaceInScroller, Restoring, ScrollPosition, list_scroller};
93pub use status_line::status_line;
94pub use table_grid::TableGrid;
95pub use video_box::{video_box, video_height};
96pub use virtual_list::{RowHeights, VirtualList};
97
98/// What the tests of the views are run with.
99#[cfg(test)]
100pub(crate) mod testing {
101 use std::pin::pin;
102 use std::task::{Context, Poll, Waker};
103
104 use cosmic::iced::core::renderer::Headless;
105
106 /// The renderer rows are laid out by in tests: the CPU one, whichever
107 /// the program is built to draw with, and with no window to draw in.
108 pub(crate) fn renderer() -> cosmic::Renderer {
109 let made = pin!(<cosmic::Renderer as Headless>::new(cosmic::iced::Font::default(), 14.0.into(), Some("tiny-skia")));
110 // Making it waits for nothing: it is there at the first asking.
111 match made.poll(&mut Context::from_waker(Waker::noop())) {
112 Poll::Ready(Some(renderer)) => renderer,
113 _ => panic!("the CPU renderer is always to be had"),
114 }
115 }
116}