feat(gui): the company is named once in the frame: a tab, with a hue; its card at the foot; no header, no heading
The tab, the sidebar's header and the Overview's heading all said the company's name side by side. Now the tab is the company's identity (badge and name); the sidebar header and the Overview heading are gone (the summary sentence leads the page, at the theme's heading size); and the status card at the foot of the sidebar opens with a heading row, the badge and the name (the rail shows the badge alone, the name on hover), so "these are this company's books: verified, live" is on every page, at the opposite corner from the tabs. The top of the sidebar is an empty `top_slot` for the assistant's connection state, a later unit. Each company has one of eight badge hues (theme::BADGE_HUES, light and dark) chosen by FNV-1a of the id of its books: a function of the id alone, so it is the same on its tab and its card, after a restart, in any order of opening and on every machine. A test computes the contrast of every hue in both themes: letter 4.5:1, badge 3:1 on each surface it sits on. No figure, date or amount changed. Regenerated: the tall sidebar's shapes and pixel goldens (header gone, links moved up, card heading row, hue) and the eight tabs_* snapshots (hue, Overview lead, the rail's badge). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dce7898e96
commit
1b28da26e6
19 files changed
+721
-88
No files matched your search
@@ -617,6 +617,7 @@ impl eframe::App for App {
|
||||
_ => title.clone(),
|
||||
},
|
||||
title,
|
||||
hue_key: v.hue_key(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -32,7 +32,6 @@ use crate::owner::Owner;
|
||||
use crate::pages;
|
||||
use crate::receipts::Receipts;
|
||||
use crate::scheme_menu::SchemeMenu;
|
||||
use crate::schemes;
|
||||
use crate::theme::{self, pal};
|
||||
use egui::{Align, CornerRadius, Frame, Key, Layout, Margin, RichText, Sense, Stroke, Ui, vec2};
|
||||
use egui_phosphor::regular as icon;
|
||||
@@ -203,20 +202,51 @@ impl CompanyView {
|
||||
pub fn title(&self) -> String {
|
||||
self.name()
|
||||
.or_else(|| self.book_id())
|
||||
.or_else(|| {
|
||||
let dir = self.data_dir.as_deref()?;
|
||||
// A demo's or a copy's folder is `books-data`: its parent
|
||||
// names it.
|
||||
let name = dir.file_name()?.to_str()?;
|
||||
let parent = dir.parent().and_then(|p| p.file_name()?.to_str());
|
||||
Some(match (name, parent) {
|
||||
("books-data", Some(p)) => p.to_string(),
|
||||
_ => name.to_string(),
|
||||
})
|
||||
})
|
||||
.or_else(|| self.folder_name())
|
||||
.unwrap_or_else(|| "Company".to_string())
|
||||
}
|
||||
|
||||
/// The books' folder's name: a demo's or a copy's folder is
|
||||
/// `books-data`, which its parent names.
|
||||
fn folder_name(&self) -> Option<String> {
|
||||
let dir = self.data_dir.as_deref()?;
|
||||
let name = dir.file_name()?.to_str()?;
|
||||
let parent = dir.parent().and_then(|p| p.file_name()?.to_str());
|
||||
Some(match (name, parent) {
|
||||
("books-data", Some(p)) => p.to_string(),
|
||||
_ => name.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
/// What this company's badge hue is chosen from: the id of its books
|
||||
/// (theme.rs `hue_of`), else the name of their folder, which is that
|
||||
/// id for books in a data root: a function of where the books are
|
||||
/// kept and never of the name they carry, so renaming a company
|
||||
/// leaves its colour.
|
||||
pub fn hue_key(&self) -> String {
|
||||
self.book_id()
|
||||
.or_else(|| self.folder_name())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The status card's heading: this company's badge and name.
|
||||
fn card_head(&self, ctx: &egui::Context) -> CardHead {
|
||||
CardHead {
|
||||
initial: self.initial(),
|
||||
title: self.title(),
|
||||
hue: theme::badge_hue(ctx, &self.hue_key()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The letter on this company's badge: its title's first, upper case.
|
||||
fn initial(&self) -> char {
|
||||
self.title()
|
||||
.chars()
|
||||
.next()
|
||||
.map(|c| c.to_uppercase().next().unwrap_or(c))
|
||||
.unwrap_or('W')
|
||||
}
|
||||
|
||||
/// The books as last loaded (tests).
|
||||
pub fn books(&self) -> Option<&Arc<Books>> {
|
||||
self.books.as_ref()
|
||||
@@ -592,6 +622,7 @@ impl CompanyView {
|
||||
}
|
||||
let p = pal(ui.ctx());
|
||||
let books = self.books.clone();
|
||||
let head = self.card_head(ui.ctx());
|
||||
egui::Panel::left("sidebar")
|
||||
.exact_size(224.0)
|
||||
.resizable(false)
|
||||
@@ -601,37 +632,7 @@ impl CompanyView {
|
||||
.inner_margin(Margin::symmetric(12, 16)),
|
||||
)
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let (r, _) = ui.allocate_exact_size(vec2(28.0, 28.0), Sense::hover());
|
||||
ui.painter().rect_filled(r, CornerRadius::same(8), p.accent);
|
||||
let initial = books
|
||||
.as_ref()
|
||||
.and_then(|b| b.company_name().chars().next())
|
||||
.unwrap_or('W');
|
||||
ui.painter().text(
|
||||
r.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
initial,
|
||||
theme::bold(15.0),
|
||||
schemes::on(p.accent),
|
||||
);
|
||||
ui.vertical(|ui| {
|
||||
ui.spacing_mut().item_spacing.y = 0.0;
|
||||
let name = books
|
||||
.as_ref()
|
||||
.map(|b| b.company_name().to_string())
|
||||
.unwrap_or_else(|| "wanderbooks".into());
|
||||
ui.add(
|
||||
egui::Label::new(RichText::new(name).font(theme::semibold(13.5)))
|
||||
.truncate(),
|
||||
);
|
||||
ui.label(
|
||||
RichText::new("Books")
|
||||
.font(theme::regular(11.5))
|
||||
.color(p.muted),
|
||||
);
|
||||
});
|
||||
});
|
||||
top_slot(ui);
|
||||
let current = self.nav.current.section();
|
||||
let attention = books.as_ref().map(|b| b.attention.len()).unwrap_or(0);
|
||||
// Short windows give way in steps (Fit): the status card
|
||||
@@ -731,6 +732,7 @@ impl CompanyView {
|
||||
ui.input(|i| i.time) - self.updated_at,
|
||||
self.loader.is_some() || self.live_label,
|
||||
fit.folded,
|
||||
&head,
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -742,6 +744,7 @@ impl CompanyView {
|
||||
fn rail(&mut self, ui: &mut Ui, schemes: &mut SchemeMenu) {
|
||||
let p = pal(ui.ctx());
|
||||
let books = self.books.clone();
|
||||
let head = self.card_head(ui.ctx());
|
||||
egui::Panel::left("rail")
|
||||
.exact_size(RAIL_W)
|
||||
.resizable(false)
|
||||
@@ -751,24 +754,7 @@ impl CompanyView {
|
||||
.inner_margin(Margin::symmetric(10, 16)),
|
||||
)
|
||||
.show(ui, |ui| {
|
||||
let name = books
|
||||
.as_ref()
|
||||
.map(|b| b.company_name().to_string())
|
||||
.unwrap_or_else(|| "wanderbooks".into());
|
||||
let (r, _) =
|
||||
ui.allocate_exact_size(vec2(ui.available_width(), 28.0), Sense::hover());
|
||||
let logo = egui::Rect::from_center_size(r.center(), vec2(28.0, 28.0));
|
||||
ui.painter()
|
||||
.rect_filled(logo, CornerRadius::same(8), p.accent);
|
||||
ui.painter().text(
|
||||
logo.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
name.chars().next().unwrap_or('W'),
|
||||
theme::bold(15.0),
|
||||
schemes::on(p.accent),
|
||||
);
|
||||
ui.interact(r, ui.id().with("logo"), Sense::hover())
|
||||
.on_hover_text(format!("{name} · Books"));
|
||||
top_slot(ui);
|
||||
let current = self.nav.current.section();
|
||||
let attention = books.as_ref().map(|b| b.attention.len()).unwrap_or(0);
|
||||
// As the sidebar's, with no card to fold.
|
||||
@@ -873,6 +859,13 @@ impl CompanyView {
|
||||
));
|
||||
}
|
||||
resp.on_hover_text(tip);
|
||||
// The company, above its status (the footer is laid
|
||||
// out bottom up): its badge alone, its name on hover.
|
||||
ui.add_space(2.0);
|
||||
let (r, resp) =
|
||||
ui.allocate_exact_size(vec2(RAIL_BADGE, RAIL_BADGE), Sense::hover());
|
||||
head.paint(ui, r, 6);
|
||||
resp.on_hover_text(&head.title);
|
||||
}
|
||||
});
|
||||
memo.measured(ui, "rail", fit.form(), footer.response.rect);
|
||||
@@ -1158,8 +1151,8 @@ const RAIL_W: f32 = 60.0;
|
||||
/// The footer's height (the status box and the menus under the sidebar's
|
||||
/// links; the rail's equivalent) before it is first measured. After the
|
||||
/// first frame its drawn heights are used ([`FooterMemo`]).
|
||||
const SIDEBAR_FOOTER: f32 = 172.0;
|
||||
const RAIL_FOOTER: f32 = 84.0;
|
||||
const SIDEBAR_FOOTER: f32 = 192.0;
|
||||
const RAIL_FOOTER: f32 = 112.0;
|
||||
/// How much shorter the footer is tightened ([`tighten`]), before it is
|
||||
/// measured so.
|
||||
const SIDEBAR_TIGHTEN: f32 = 36.0;
|
||||
@@ -1168,9 +1161,12 @@ const RAIL_TIGHTEN: f32 = 36.0;
|
||||
/// Space kept between the last link and the footer.
|
||||
const FOOTER_GAP: f32 = 8.0;
|
||||
|
||||
/// Tightened: the space between links, and under the header.
|
||||
/// Tightened: the space between links, and under the top slot. The slot
|
||||
/// draws nothing (`top_slot`), and the panel's margin is the first link's
|
||||
/// room under the tab bar, so both gaps are nothing today.
|
||||
const GAP_MIN: f32 = 2.0;
|
||||
const HEAD_GAP_TIGHT: f32 = 8.0;
|
||||
const HEAD_GAP: f32 = 0.0;
|
||||
const HEAD_GAP_TIGHT: f32 = 0.0;
|
||||
|
||||
/// A panel's links: how many, their height and spacing, the least height
|
||||
/// they tighten to, the gap above them, and whether its status card folds.
|
||||
@@ -1197,7 +1193,7 @@ const SIDEBAR_ROWS: Rows = Rows {
|
||||
// 22, not 24, since Invoices & Bills made 13 links (2026-10-24): so
|
||||
// they still fit the owner's 1479x519 window unscrolled.
|
||||
row_min: 22.0,
|
||||
head_gap: 18.0,
|
||||
head_gap: HEAD_GAP,
|
||||
foldable: true,
|
||||
};
|
||||
|
||||
@@ -1208,7 +1204,7 @@ const RAIL_ROWS: Rows = Rows {
|
||||
// As low as the sidebar's: at 28 the rail scrolled in the owner's
|
||||
// window (review, 2026-10-22), and at 24 once there were 13 links.
|
||||
row_min: 22.0,
|
||||
head_gap: 18.0,
|
||||
head_gap: HEAD_GAP,
|
||||
foldable: false,
|
||||
};
|
||||
|
||||
@@ -1530,12 +1526,58 @@ fn footer_layout<R>(
|
||||
}
|
||||
}
|
||||
|
||||
/// The top of the sidebar (and of the rail): where the assistant's
|
||||
/// connection state goes, in a later unit. It draws nothing today, so the
|
||||
/// links begin at the panel's top margin, under the tab bar. A block put
|
||||
/// here adds its own height and gap below it ([`HEAD_GAP`],
|
||||
/// [`HEAD_GAP_TIGHT`] are what the fit leaves under it).
|
||||
fn top_slot(_ui: &mut Ui) {}
|
||||
|
||||
/// What the status card says of its company: the heading row's badge
|
||||
/// (its hue, its letter) and name.
|
||||
struct CardHead {
|
||||
initial: char,
|
||||
title: String,
|
||||
hue: egui::Color32,
|
||||
}
|
||||
|
||||
/// The status card's badge, and the rail's.
|
||||
const CARD_BADGE: f32 = 16.0;
|
||||
const RAIL_BADGE: f32 = 24.0;
|
||||
|
||||
impl CardHead {
|
||||
fn paint(&self, ui: &Ui, rect: egui::Rect, radius: u8) {
|
||||
let font = theme::bold(if rect.width() > 20.0 { 13.0 } else { 10.0 });
|
||||
theme::paint_badge(ui.painter(), rect, radius, self.initial, self.hue, font);
|
||||
}
|
||||
|
||||
/// The card's heading row: the badge, small, and the name, cut with
|
||||
/// an ellipsis to the card's width.
|
||||
fn row(&self, ui: &mut Ui) -> egui::Response {
|
||||
ui.horizontal(|ui| {
|
||||
let (r, _) = ui.allocate_exact_size(vec2(CARD_BADGE, CARD_BADGE), Sense::hover());
|
||||
self.paint(ui, r, 4);
|
||||
ui.add(
|
||||
egui::Label::new(RichText::new(&self.title).font(theme::semibold(12.5))).truncate(),
|
||||
)
|
||||
})
|
||||
.inner
|
||||
}
|
||||
}
|
||||
|
||||
/// The status card: whether the books are live, their newest event, and
|
||||
/// the integrity checks. Folded (a short window), one line, the checks
|
||||
/// in its tooltip.
|
||||
fn live_status(ui: &mut Ui, b: &Books, since_update: f64, live: bool, folded: bool) {
|
||||
fn live_status(
|
||||
ui: &mut Ui,
|
||||
b: &Books,
|
||||
since_update: f64,
|
||||
live: bool,
|
||||
folded: bool,
|
||||
head: &CardHead,
|
||||
) {
|
||||
if folded {
|
||||
return folded_status(ui, b, since_update, live);
|
||||
return folded_status(ui, b, since_update, live, head);
|
||||
}
|
||||
let p = pal(ui.ctx());
|
||||
Frame::new()
|
||||
@@ -1584,6 +1626,9 @@ fn live_status(ui: &mut Ui, b: &Books, since_update: f64, live: bool, folded: bo
|
||||
});
|
||||
}
|
||||
}
|
||||
// The footer is laid out bottom up, so what is added last is
|
||||
// the card's top: the heading, over what the card always said.
|
||||
head.row(ui).on_hover_text(&head.title);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1593,7 +1638,7 @@ fn live_status(ui: &mut Ui, b: &Books, since_update: f64, live: bool, folded: bo
|
||||
/// of [`summaries`] that fits the card, so it is never cut off: a failed
|
||||
/// check's name outranks the event and the word "Live" (review,
|
||||
/// 2026-10-22: cut to "⊘ Datab…" it hid what failed).
|
||||
fn folded_status(ui: &mut Ui, b: &Books, since_update: f64, live: bool) {
|
||||
fn folded_status(ui: &mut Ui, b: &Books, since_update: f64, live: bool, head: &CardHead) {
|
||||
let p = pal(ui.ctx());
|
||||
let checks = checks(b);
|
||||
let failed: Vec<&str> = checks
|
||||
@@ -1658,6 +1703,10 @@ fn folded_status(ui: &mut Ui, b: &Books, since_update: f64, live: bool) {
|
||||
.color(color),
|
||||
);
|
||||
});
|
||||
// Bottom up, so last is the top: the heading. Its hover is the
|
||||
// card's (below): the card is one target, whose tooltip begins
|
||||
// with the name.
|
||||
head.row(ui);
|
||||
});
|
||||
let resp = ui.interact(
|
||||
card.response.rect,
|
||||
@@ -1665,6 +1714,7 @@ fn folded_status(ui: &mut Ui, b: &Books, since_update: f64, live: bool) {
|
||||
Sense::click(),
|
||||
);
|
||||
resp.on_hover_ui(|ui| {
|
||||
ui.label(RichText::new(&head.title).font(theme::semibold(12.0)));
|
||||
if !(line.status && line.event) {
|
||||
ui.label(
|
||||
RichText::new(format!("{status} {event}"))
|
||||
|
||||
@@ -20,7 +20,7 @@ use rust_decimal::Decimal;
|
||||
pub fn show(ui: &mut Ui, b: &Books, shell: &mut Shell<'_>) {
|
||||
page(ui, "overview", |ui| {
|
||||
let k = &b.kpis;
|
||||
widgets::page_header(ui, b.company_name(), &headline(b));
|
||||
widgets::page_lead(ui, &headline(b));
|
||||
kpis(ui, b, shell);
|
||||
let _ = k;
|
||||
// What needs doing gets the page's full width, under the numbers:
|
||||
|
||||
@@ -8,8 +8,11 @@
|
||||
//! width.
|
||||
//!
|
||||
//! The bar spans the whole window, above the sidebar: a tab is the top
|
||||
//! level, and the sidebar (its company badge, its pages, its status) is
|
||||
//! the company in the tab's, which the layout shows. With no company open
|
||||
//! level, and the sidebar (its pages, its status card) is the company in
|
||||
//! the tab's, which the layout shows. The tab is the company's identity
|
||||
//! in the frame (badge and name); nothing else at the top of the window
|
||||
//! repeats it, and the status card at the foot of the sidebar names it
|
||||
//! again, in the same hue. With no company open
|
||||
//! it is the window's top all the same. The "+" follows the last tab, and
|
||||
//! stays at the right edge, whole, while the tabs scroll.
|
||||
//!
|
||||
@@ -22,8 +25,8 @@
|
||||
//! company is reachable exactly while it has a tab).
|
||||
//! INVARIANTS:
|
||||
//! 1. One tab per open company, in the order opened, showing the
|
||||
//! company's badge (as the sidebar's header draws it, small) and
|
||||
//! name (the name last known, else the id of its books, until it is
|
||||
//! company's badge (its hue, from the id of its books: theme.rs
|
||||
//! `hue_of`; the status card draws the same) and name (the name last known, else the id of its books, until it is
|
||||
//! read). The bar is there with one company open, and with none.
|
||||
//! 2. The tab shown is marked by more than colour: a heavier name, a
|
||||
//! bar in the accent colour along its top edge, and "selected" to
|
||||
@@ -86,6 +89,15 @@ pub struct Tab {
|
||||
pub title: String,
|
||||
/// More about it, on hover.
|
||||
pub detail: String,
|
||||
/// What its badge's hue is chosen from: the id of its books
|
||||
/// ([`hue_of`]).
|
||||
pub hue_key: String,
|
||||
}
|
||||
|
||||
/// The badge hue of the company whose books have id `book_id`, light or
|
||||
/// dark: the one its tab and its status card both draw (theme.rs).
|
||||
pub fn hue_of(book_id: &str, dark: bool) -> egui::Color32 {
|
||||
theme::hue_of(book_id, dark)
|
||||
}
|
||||
|
||||
/// A company of the data root that is not open, as "+" lists it.
|
||||
@@ -455,24 +467,24 @@ fn one_tab(
|
||||
} else if resp.hovered() || close.hovered() {
|
||||
painter.rect_filled(rect.shrink2(vec2(0.0, 2.0)), CornerRadius::same(8), p.hover);
|
||||
}
|
||||
// The badge, as the sidebar's header draws it.
|
||||
// The badge: the company's hue, as its status card draws it.
|
||||
let badge = egui::Rect::from_center_size(
|
||||
egui::pos2(rect.left() + PAD_L + BADGE / 2.0, rect.center().y + 1.0),
|
||||
vec2(BADGE, BADGE),
|
||||
);
|
||||
painter.rect_filled(badge, CornerRadius::same(5), p.accent);
|
||||
let initial = tab
|
||||
.title
|
||||
.chars()
|
||||
.next()
|
||||
.map(|c| c.to_uppercase().next().unwrap_or(c))
|
||||
.unwrap_or('W');
|
||||
painter.text(
|
||||
badge.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
theme::paint_badge(
|
||||
painter,
|
||||
badge,
|
||||
5,
|
||||
initial,
|
||||
theme::badge_hue(ui.ctx(), &tab.hue_key),
|
||||
theme::bold(11.0),
|
||||
crate::schemes::on(p.accent),
|
||||
);
|
||||
let font = if here {
|
||||
theme::semibold(13.0)
|
||||
|
||||
@@ -90,6 +90,106 @@ pub const DARK: Palette = Palette {
|
||||
],
|
||||
};
|
||||
|
||||
/// The company badges' hues, light and dark: one per company, chosen by
|
||||
/// [`hue_of`] from the id of its books. Each is dark enough (light) or
|
||||
/// bright enough (dark) that its letter (black or white, whichever reads
|
||||
/// better) has 4.5:1 on it and it has 3:1 on every surface a badge sits
|
||||
/// on, in the viewer's own two themes (the test below).
|
||||
pub const BADGE_HUES: [(Color32, Color32); 8] = [
|
||||
// indigo
|
||||
(
|
||||
Color32::from_rgb(0x4F, 0x46, 0xE5),
|
||||
Color32::from_rgb(0x8B, 0x93, 0xFA),
|
||||
),
|
||||
// teal
|
||||
(
|
||||
Color32::from_rgb(0x0F, 0x76, 0x6E),
|
||||
Color32::from_rgb(0x2D, 0xD4, 0xBF),
|
||||
),
|
||||
// orange
|
||||
(
|
||||
Color32::from_rgb(0xB4, 0x53, 0x09),
|
||||
Color32::from_rgb(0xFB, 0xBF, 0x24),
|
||||
),
|
||||
// rose
|
||||
(
|
||||
Color32::from_rgb(0xBE, 0x18, 0x5D),
|
||||
Color32::from_rgb(0xF4, 0x72, 0xB6),
|
||||
),
|
||||
// blue
|
||||
(
|
||||
Color32::from_rgb(0x1D, 0x4E, 0xD8),
|
||||
Color32::from_rgb(0x60, 0xA5, 0xFA),
|
||||
),
|
||||
// green
|
||||
(
|
||||
Color32::from_rgb(0x15, 0x80, 0x3D),
|
||||
Color32::from_rgb(0x4A, 0xDE, 0x80),
|
||||
),
|
||||
// violet
|
||||
(
|
||||
Color32::from_rgb(0x7E, 0x22, 0xCE),
|
||||
Color32::from_rgb(0xC0, 0x84, 0xFC),
|
||||
),
|
||||
// slate
|
||||
(
|
||||
Color32::from_rgb(0x47, 0x55, 0x69),
|
||||
Color32::from_rgb(0x94, 0xA3, 0xB8),
|
||||
),
|
||||
];
|
||||
|
||||
/// Which hue a company has: FNV-1a over the bytes of the id of its books,
|
||||
/// modulo the number of hues. A function of the id alone (no seed, no
|
||||
/// machine, no order of opening), so a company keeps its hue for ever and
|
||||
/// on every machine; it is never changed without a new decision.
|
||||
pub fn hue_index(book_id: &str) -> usize {
|
||||
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
for b in book_id.bytes() {
|
||||
h ^= u64::from(b);
|
||||
h = h.wrapping_mul(0x100_0000_01b3);
|
||||
}
|
||||
(h % BADGE_HUES.len() as u64) as usize
|
||||
}
|
||||
|
||||
/// The badge hue of the company whose books have id `book_id`, in the
|
||||
/// light or dark table.
|
||||
pub fn hue_of(book_id: &str, dark: bool) -> Color32 {
|
||||
let (light, night) = BADGE_HUES[hue_index(book_id)];
|
||||
if dark { night } else { light }
|
||||
}
|
||||
|
||||
/// Whether the palette in force is a dark one (its page is darker than
|
||||
/// its text).
|
||||
fn is_dark(p: &Palette) -> bool {
|
||||
crate::schemes::luminance(p.bg) < crate::schemes::luminance(p.text)
|
||||
}
|
||||
|
||||
/// The badge hue of a company, for the palette in force.
|
||||
pub fn badge_hue(ctx: &Context, book_id: &str) -> Color32 {
|
||||
hue_of(book_id, is_dark(&pal(ctx)))
|
||||
}
|
||||
|
||||
/// A company's badge: a rounded square in its hue with its initial in it
|
||||
/// (black or white, whichever reads), drawn by the tab and the status
|
||||
/// card alike.
|
||||
pub fn paint_badge(
|
||||
painter: &egui::Painter,
|
||||
rect: egui::Rect,
|
||||
radius: u8,
|
||||
initial: char,
|
||||
hue: Color32,
|
||||
font: FontId,
|
||||
) {
|
||||
painter.rect_filled(rect, CornerRadius::same(radius), hue);
|
||||
painter.text(
|
||||
rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
initial,
|
||||
font,
|
||||
crate::schemes::on(hue),
|
||||
);
|
||||
}
|
||||
|
||||
/// Where the palette in force is kept, in the context's memory.
|
||||
fn palette_id() -> egui::Id {
|
||||
egui::Id::new("wanderbooks-palette")
|
||||
@@ -317,6 +417,43 @@ pub fn apply_scheme(ctx: &Context, scheme: &crate::schemes::Scheme) {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// WCAG AA for each badge hue in both themes: its letter 4.5:1 on
|
||||
/// it, and 3:1 for the badge against every surface it is drawn on.
|
||||
#[test]
|
||||
fn every_badge_hue_reads_in_both_themes() {
|
||||
use crate::schemes::{contrast, on};
|
||||
for (name, p, pick) in [("light", &LIGHT, 0), ("dark", &DARK, 1)] {
|
||||
for (i, hues) in BADGE_HUES.iter().enumerate() {
|
||||
let hue = if pick == 0 { hues.0 } else { hues.1 };
|
||||
let letter = contrast(on(hue), hue);
|
||||
assert!(
|
||||
letter >= 4.5,
|
||||
"{name} hue {i} {hue:?}: letter {letter:.2}:1"
|
||||
);
|
||||
// The tab's (in front, behind, hovered) and the card's.
|
||||
for (what, ground) in [
|
||||
("surface", p.surface),
|
||||
("sidebar", p.sidebar),
|
||||
("page", p.bg),
|
||||
("hover", p.hover),
|
||||
] {
|
||||
let r = contrast(hue, ground);
|
||||
assert!(r >= 3.0, "{name} hue {i} {hue:?} on {what}: {r:.2}:1");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hue_is_a_function_of_the_book_id_alone() {
|
||||
// Pinned: a change here recolours every company.
|
||||
assert_eq!(hue_index("alpha"), hue_index("alpha"));
|
||||
assert_eq!(hue_index(""), 0xcbf2_9ce4_8422_2325_u64 as usize % 8);
|
||||
let all: std::collections::HashSet<usize> =
|
||||
(0..200).map(|n| hue_index(&format!("books-{n}"))).collect();
|
||||
assert_eq!(all.len(), BADGE_HUES.len(), "every hue is used");
|
||||
}
|
||||
|
||||
/// font_definitions: every family ends with the PDFs' Noto fallbacks,
|
||||
/// in their order, after its own face, the icons and the symbol fonts,
|
||||
/// each Noto font the very bytes ledger-import bundles (the same
|
||||
|
||||
@@ -61,6 +61,19 @@ pub fn page_header(ui: &mut Ui, title: &str, subtitle: &str) {
|
||||
ui.add_space(16.0);
|
||||
}
|
||||
|
||||
/// A page that opens with a sentence instead of a title (the Overview:
|
||||
/// the company's name is the tab's, and the status card's, not the
|
||||
/// page's): the sentence at the theme's heading size and weight, the
|
||||
/// first thing on the page.
|
||||
pub fn page_lead(ui: &mut Ui, sentence: &str) {
|
||||
let w = ui.available_width().min(860.0);
|
||||
ui.allocate_ui(vec2(w, 0.0), |ui| {
|
||||
ui.set_max_width(w);
|
||||
ui.label(RichText::new(sentence).font(theme::semibold(20.0)));
|
||||
});
|
||||
ui.add_space(16.0);
|
||||
}
|
||||
|
||||
/// A rounded tag.
|
||||
pub fn pill(ui: &mut Ui, text: &str, fg: Color32, bg: Color32) -> Response {
|
||||
Frame::new()
|
||||
|
||||
Reference in new issue
Block a user