mirror of
https://github.com/narrrl/proton-stream.git
synced 2026-11-04 08:56:59 +01:00
feat(app): bundled Inter and Phosphor icons, window icon
Headings are set in Inter SemiBold, everything else in Inter Regular, so a
title sets the same on every desktop. Media and navigation glyphs (⏭, 🔊, ⛶,
★) come from the Phosphor icon font instead of whichever fallback font had
them. The CJK fallback still loads on its own thread and now joins the
bundled fonts instead of replacing them. The window carries the app icon
on X11 and Windows.
This commit is contained in:
1 parent
6518aef5ee
commit
558446b9e4
17 files changed
+256
-45
No files matched your search
@@ -479,7 +479,7 @@ impl App {
|
||||
// before switching is a window that flashes on every launch.
|
||||
let window = crate::window::WindowMemory::new(dirs.window_file());
|
||||
let (engine, events) = Engine::new(runtime, dirs, cc.egui_ctx.clone())?;
|
||||
theme::install_font_fallbacks(&cc.egui_ctx);
|
||||
theme::install_fonts(&cc.egui_ctx);
|
||||
theme::apply(&cc.egui_ctx, engine.appearance());
|
||||
|
||||
// Paint from the catalog immediately; the network catches up. A library
|
||||
@@ -1493,7 +1493,10 @@ impl App {
|
||||
ui.add(egui::Spinner::new().size(16.0));
|
||||
ui.label(ui::muted("connecting"));
|
||||
} else if ui
|
||||
.button("Refresh")
|
||||
.button(format!(
|
||||
"{} Refresh",
|
||||
egui_phosphor::regular::ARROW_CLOCKWISE
|
||||
))
|
||||
.on_hover_text("Re-crawl every share")
|
||||
.clicked()
|
||||
{
|
||||
|
||||
@@ -32,8 +32,15 @@ fn main() -> anyhow::Result<()> {
|
||||
let dirs = AppDirs::ensure().context("resolve app directories")?;
|
||||
|
||||
let window = pstr_app::window::WindowState::load(&dirs.window_file());
|
||||
let mut viewport = egui::ViewportBuilder::default();
|
||||
// X11 and Windows take the icon from the window. Wayland ignores this and
|
||||
// looks the app id up in the installed desktop entry instead.
|
||||
match eframe::icon_data::from_png_bytes(include_bytes!("../assets/icon-256.png")) {
|
||||
Ok(icon) => viewport = viewport.with_icon(icon),
|
||||
Err(error) => tracing::debug!("window icon: {error}"),
|
||||
}
|
||||
let mut options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
viewport: viewport
|
||||
.with_title("proton-stream")
|
||||
.with_inner_size(window.map_or([1180.0, 780.0], |state| [state.width, state.height]))
|
||||
.with_maximized(window.is_some_and(|state| state.maximized))
|
||||
|
||||
@@ -84,26 +84,90 @@ impl Role {
|
||||
}
|
||||
}
|
||||
|
||||
/// Headings are set in the semibold cut; everything below them in the
|
||||
/// regular one.
|
||||
pub fn family(self) -> egui::FontFamily {
|
||||
match self {
|
||||
Self::Display | Self::Title | Self::Heading | Self::Section => semibold(),
|
||||
_ => egui::FontFamily::Proportional,
|
||||
}
|
||||
}
|
||||
|
||||
/// For the hand-painted parts, which lay text out through a `Painter` and
|
||||
/// never see a `RichText`.
|
||||
pub fn font(self) -> egui::FontId {
|
||||
egui::FontId::proportional(self.size())
|
||||
egui::FontId::new(self.size(), self.family())
|
||||
}
|
||||
|
||||
/// For the parts that go through egui's widgets.
|
||||
pub fn rich(self, text: impl Into<String>) -> egui::RichText {
|
||||
egui::RichText::new(text).size(self.size())
|
||||
egui::RichText::new(text)
|
||||
.size(self.size())
|
||||
.family(self.family())
|
||||
}
|
||||
}
|
||||
|
||||
/// Install a real CJK fallback before the default egui fonts. egui ships a
|
||||
/// compact Latin font, but it intentionally does not bundle the multi-megabyte
|
||||
/// CJK families. Native desktops already provide one, so use it when present.
|
||||
/// The UI typeface, bundled rather than taken from the system so a title
|
||||
/// sets the same on every desktop. Inter, under the OFL — the licence is
|
||||
/// beside the files.
|
||||
const INTER: &[u8] = include_bytes!("../assets/fonts/Inter-Regular.ttf");
|
||||
const INTER_SEMIBOLD: &[u8] = include_bytes!("../assets/fonts/Inter-SemiBold.ttf");
|
||||
|
||||
/// The family the headings are set in. egui has no notion of weight, so the
|
||||
/// semibold cut is a family of its own.
|
||||
pub fn semibold() -> egui::FontFamily {
|
||||
egui::FontFamily::Name("semibold".into())
|
||||
}
|
||||
|
||||
/// Inter, the icon font, and egui's own fonts behind them for the emoji and
|
||||
/// symbols Inter does not carry. `cjk` goes last, when there is one.
|
||||
fn font_definitions(cjk: Option<egui::FontData>) -> egui::FontDefinitions {
|
||||
use egui::FontFamily::{Monospace, Proportional};
|
||||
|
||||
let mut fonts = egui::FontDefinitions::default();
|
||||
fonts
|
||||
.font_data
|
||||
.insert("inter".into(), Arc::new(egui::FontData::from_static(INTER)));
|
||||
fonts.font_data.insert(
|
||||
"inter-semibold".into(),
|
||||
Arc::new(egui::FontData::from_static(INTER_SEMIBOLD)),
|
||||
);
|
||||
fonts
|
||||
.families
|
||||
.entry(Proportional)
|
||||
.or_default()
|
||||
.insert(0, "inter".into());
|
||||
// Right behind Inter. The icons are in the private use area, so nothing
|
||||
// Inter has is shadowed by them.
|
||||
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
|
||||
if let Some(cjk) = cjk {
|
||||
let name = "system-cjk-fallback".to_owned();
|
||||
fonts.font_data.insert(name.clone(), Arc::new(cjk));
|
||||
for family in [Proportional, Monospace] {
|
||||
fonts.families.entry(family).or_default().push(name.clone());
|
||||
}
|
||||
}
|
||||
let fallbacks = fonts.families[&Proportional]
|
||||
.iter()
|
||||
.filter(|name| *name != "inter")
|
||||
.cloned();
|
||||
let semibold_chain = std::iter::once("inter-semibold".to_owned())
|
||||
.chain(fallbacks)
|
||||
.collect();
|
||||
fonts.families.insert(semibold(), semibold_chain);
|
||||
fonts
|
||||
}
|
||||
|
||||
/// Install the bundled fonts now, and a CJK fallback when the system has one.
|
||||
///
|
||||
/// On a thread of its own: `fc-match` and reading a font file of tens of
|
||||
/// megabytes held the first frame back by a visible moment, and every name
|
||||
/// that needs the fallback is still loading from the catalog by then anyway.
|
||||
pub fn install_font_fallbacks(ctx: &egui::Context) {
|
||||
/// The bundled ones are compiled in and cost nothing to hand over. The CJK
|
||||
/// fallback is on a thread of its own: `fc-match` and reading a font file of
|
||||
/// tens of megabytes held the first frame back by a visible moment, and every
|
||||
/// name that needs the fallback is still loading from the catalog by then
|
||||
/// anyway. egui deliberately does not bundle the multi-megabyte CJK families,
|
||||
/// and native desktops already provide one.
|
||||
pub fn install_fonts(ctx: &egui::Context) {
|
||||
ctx.set_fonts(font_definitions(None));
|
||||
let ctx = ctx.clone();
|
||||
let spawned = std::thread::Builder::new()
|
||||
.name("fonts".into())
|
||||
@@ -120,16 +184,9 @@ fn install_cjk_fallback(ctx: &egui::Context) {
|
||||
let Ok(bytes) = std::fs::read(path) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mut fonts = egui::FontDefinitions::default();
|
||||
let mut data = egui::FontData::from_owned(bytes);
|
||||
data.index = index;
|
||||
let name = "system-cjk-fallback".to_owned();
|
||||
fonts.font_data.insert(name.clone(), Arc::new(data));
|
||||
for family in [egui::FontFamily::Proportional, egui::FontFamily::Monospace] {
|
||||
fonts.families.entry(family).or_default().push(name.clone());
|
||||
}
|
||||
ctx.set_fonts(fonts);
|
||||
ctx.set_fonts(font_definitions(Some(data)));
|
||||
ctx.request_repaint();
|
||||
}
|
||||
|
||||
|
||||
@@ -211,9 +211,11 @@ fn hero(ui: &mut egui::Ui, art: &mut Art<'_>, title: &Title, actions: &mut Vec<A
|
||||
ui.horizontal(|ui| {
|
||||
if let Some(episode) = title.next_up() {
|
||||
let label = match (title.resume(), episode.numbering()) {
|
||||
(Some(_), Some(numbering)) => format!("▶ Resume {numbering}"),
|
||||
(Some(_), None) => "▶ Resume".to_owned(),
|
||||
(None, _) => "▶ Play".to_owned(),
|
||||
(Some(_), Some(numbering)) => {
|
||||
format!("{} Resume {numbering}", egui_phosphor::regular::PLAY)
|
||||
}
|
||||
(Some(_), None) => format!("{} Resume", egui_phosphor::regular::PLAY),
|
||||
(None, _) => format!("{} Play", egui_phosphor::regular::PLAY),
|
||||
};
|
||||
if ui::accent_button(ui, &label).clicked() {
|
||||
actions.push(Action::Play(PlaybackTarget::new(title, episode)));
|
||||
@@ -239,7 +241,7 @@ fn hero(ui: &mut egui::Ui, art: &mut Art<'_>, title: &Title, actions: &mut Vec<A
|
||||
let mut facts = vec![subtitle(title)];
|
||||
if let Some(found) = &found {
|
||||
if let Some(rating) = found.rating {
|
||||
facts.push(format!("★ {rating:.1}"));
|
||||
facts.push(format!("{} {rating:.1}", egui_phosphor::regular::STAR));
|
||||
}
|
||||
facts.extend(found.genres.iter().take(3).cloned());
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ fn facts(found: &TitleMetadata) -> String {
|
||||
parts.push(ui::library::plural(episodes as usize, "episode"));
|
||||
}
|
||||
if let Some(rating) = found.rating {
|
||||
parts.push(format!("★ {rating:.1}"));
|
||||
parts.push(format!("{} {rating:.1}", egui_phosphor::regular::STAR));
|
||||
}
|
||||
parts.join(" · ")
|
||||
}
|
||||
@@ -657,14 +657,23 @@ fn chrome(
|
||||
});
|
||||
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let fullscreen = ui.input(|input| input.viewport().fullscreen.unwrap_or(false));
|
||||
if ui
|
||||
.add(
|
||||
egui::Button::new(theme::Role::Subhead.rich("⛶"))
|
||||
.fill(Color32::from_black_alpha(160))
|
||||
.corner_radius(CornerRadius::same(8))
|
||||
.min_size(Vec2::new(38.0, 32.0)),
|
||||
egui::Button::new(theme::Role::Subhead.rich(if fullscreen {
|
||||
egui_phosphor::regular::CORNERS_IN
|
||||
} else {
|
||||
egui_phosphor::regular::CORNERS_OUT
|
||||
}))
|
||||
.fill(Color32::from_black_alpha(160))
|
||||
.corner_radius(CornerRadius::same(8))
|
||||
.min_size(Vec2::new(38.0, 32.0)),
|
||||
)
|
||||
.on_hover_text("Fullscreen (F)")
|
||||
.on_hover_text(if fullscreen {
|
||||
"Leave fullscreen (F)"
|
||||
} else {
|
||||
"Fullscreen (F)"
|
||||
})
|
||||
.clicked()
|
||||
{
|
||||
actions.push(Action::ToggleFullscreen);
|
||||
|
||||
@@ -128,7 +128,7 @@ fn poster(ui: &mut egui::Ui, texture: &egui::TextureHandle, progress: Option<f64
|
||||
/// "← Library", as a link rather than a button: it is navigation, and a
|
||||
/// filled button beside the page's real actions competed with them.
|
||||
fn back_link(ui: &mut egui::Ui) -> egui::Response {
|
||||
let text = theme::Role::Label.rich("← Library");
|
||||
let text = theme::Role::Label.rich(format!("{} Library", egui_phosphor::regular::ARROW_LEFT));
|
||||
let response = ui.add(egui::Label::new(text.color(theme::muted())).sense(egui::Sense::click()));
|
||||
if response.hovered() {
|
||||
ui.painter().hline(
|
||||
@@ -532,7 +532,7 @@ fn meta_line(title: &Title, found: Option<&TitleMetadata>) -> String {
|
||||
|
||||
if let Some(found) = found {
|
||||
if let Some(rating) = found.rating {
|
||||
parts.push(format!("★ {rating:.1}"));
|
||||
parts.push(format!("{} {rating:.1}", egui_phosphor::regular::STAR));
|
||||
}
|
||||
// Only when it disagrees with what is on disk: "25 episodes · 25
|
||||
// episodes" tells nobody anything, but "12 episodes · 25 on AniList"
|
||||
|
||||
@@ -65,7 +65,7 @@ pub fn full(
|
||||
// hand reaches for it.
|
||||
step_button(
|
||||
ui,
|
||||
"⏮",
|
||||
egui_phosphor::regular::SKIP_BACK,
|
||||
"Previous (P)",
|
||||
neighbours.previous,
|
||||
actions,
|
||||
@@ -76,9 +76,16 @@ pub fn full(
|
||||
skip_button(ui, "−10s", "Back ten seconds (←)", -10.0, actions);
|
||||
play_pause(ui, playback, actions, 44.0);
|
||||
skip_button(ui, "+30s", "Forward thirty seconds (→)", 30.0, actions);
|
||||
step_button(ui, "⏭", "Next (N)", neighbours.next, actions, |a| {
|
||||
a.push(Action::PlayAdjacent(Adjacent::Next));
|
||||
});
|
||||
step_button(
|
||||
ui,
|
||||
egui_phosphor::regular::SKIP_FORWARD,
|
||||
"Next (N)",
|
||||
neighbours.next,
|
||||
actions,
|
||||
|a| {
|
||||
a.push(Action::PlayAdjacent(Adjacent::Next));
|
||||
},
|
||||
);
|
||||
|
||||
ui.add_space(12.0);
|
||||
if playback.seeking || playback.buffering || !playback.loaded {
|
||||
@@ -202,13 +209,20 @@ pub fn mini(
|
||||
actions.push(Action::Player(Command::Stop));
|
||||
}
|
||||
ui.add_space(6.0);
|
||||
step_button(ui, "⏭", "Next (N)", neighbours.next, actions, |a| {
|
||||
a.push(Action::PlayAdjacent(Adjacent::Next));
|
||||
});
|
||||
step_button(
|
||||
ui,
|
||||
egui_phosphor::regular::SKIP_FORWARD,
|
||||
"Next (N)",
|
||||
neighbours.next,
|
||||
actions,
|
||||
|a| {
|
||||
a.push(Action::PlayAdjacent(Adjacent::Next));
|
||||
},
|
||||
);
|
||||
play_pause(ui, playback, actions, 34.0);
|
||||
step_button(
|
||||
ui,
|
||||
"⏮",
|
||||
egui_phosphor::regular::SKIP_BACK,
|
||||
"Previous (P)",
|
||||
neighbours.previous,
|
||||
actions,
|
||||
@@ -414,12 +428,14 @@ fn volume(ui: &mut egui::Ui, playback: &Playback, actions: &mut Vec<Action>) {
|
||||
}
|
||||
|
||||
let icon = if playback.muted || playback.volume <= 0.0 {
|
||||
"🔇"
|
||||
egui_phosphor::regular::SPEAKER_SLASH
|
||||
} else if playback.volume < 50.0 {
|
||||
egui_phosphor::regular::SPEAKER_LOW
|
||||
} else {
|
||||
"🔊"
|
||||
egui_phosphor::regular::SPEAKER_HIGH
|
||||
};
|
||||
if ui
|
||||
.button(icon)
|
||||
.button(theme::Role::Subhead.rich(icon))
|
||||
.on_hover_text(format!("Mute (M) — {:.0}%", playback.volume))
|
||||
.clicked()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user