Skip to content

Lightweight native Discord client for Windows, Linux and macOS, written in Rust. No Electron, no browser engine.

Fallback icons off Windows (title bar buttons and others) (#17)

Miguel García0241cbc5e1dc
diff --git a/apps/rustcord/fonts/discord-icons-fallback.ttf b/apps/rustcord/fonts/discord-icons-fallback.ttf
index 302734b..8e5db39 100644
Binary files a/apps/rustcord/fonts/discord-icons-fallback.ttf and b/apps/rustcord/fonts/discord-icons-fallback.ttf differ
diff --git a/apps/rustcord/fonts/discord-icons-src/build_icon_font.py b/apps/rustcord/fonts/discord-icons-src/build_icon_font.py
index aa6c7ae..d8be498 100644
--- a/apps/rustcord/fonts/discord-icons-src/build_icon_font.py
+++ b/apps/rustcord/fonts/discord-icons-src/build_icon_font.py
@@ -60,6 +60,8 @@ FALLBACK = {
0xE8A7: 'window_launch', 0xEA86: 'puzzle_piece', 0xE8BD: 'chat', 0xE8D6: 'music',
0xE8B7: 'folder', 0xE7FC: 'game_controller', 0xE77B: 'user_circle', 0xE768: 'play',
0xE769: 'pause', 0xE74F: 'speaker_x',
+ 0xE707: 'pin', 0xE71D: 'apps', 0xE734: 'star', 0xE76B: ('chevron_down', 90),
+ 0xE7B3: 'eye',
}
diff --git a/apps/rustcord/src/style.rs b/apps/rustcord/src/style.rs
index b4552f5..3b76809 100644
--- a/apps/rustcord/src/style.rs
+++ b/apps/rustcord/src/style.rs
@@ -1173,10 +1173,6 @@ pub mod icon {
pub const SETTINGS: &str = "\u{E713}";
pub const CHECK: &str = "\u{E73E}";
pub const CLOSE: &str = "\u{E711}";
- pub const CHROME_MINIMIZE: &str = "\u{E921}";
- pub const CHROME_MAXIMIZE: &str = "\u{E922}";
- pub const CHROME_RESTORE: &str = "\u{E923}";
- pub const CHROME_CLOSE: &str = "\u{E8BB}";
pub const MAIL: &str = "\u{F1006}";
pub const SHIELD: &str = "\u{EA18}";
pub const BACK: &str = "\u{E72B}";
diff --git a/apps/rustcord/src/ui/mod.rs b/apps/rustcord/src/ui/mod.rs
index 7fa0800..bd12a1f 100644
--- a/apps/rustcord/src/ui/mod.rs
+++ b/apps/rustcord/src/ui/mod.rs
@@ -119,14 +119,7 @@ impl RustCord {
// at the left end instead.
let mut x = bar.right();
let own_buttons = if cfg!(target_os = "macos") { 0 } else { 3 };
- for (glyph, tip, cmd) in [
- (icon::CHROME_CLOSE, "Close", 0),
- (if maximized { icon::CHROME_RESTORE } else { icon::CHROME_MAXIMIZE }, if maximized { "Restore" } else { "Maximize" }, 1),
- (icon::CHROME_MINIMIZE, "Minimize", 2),
- ]
- .into_iter()
- .take(own_buttons)
- {
+ for (tip, cmd) in [("Close", 0), (if maximized { "Restore" } else { "Maximize" }, 1), ("Minimize", 2)].into_iter().take(own_buttons) {
let r = Rect::from_min_max(pos2(x - 46.0, bar.top()), pos2(x, bar.bottom()));
x -= 46.0;
let b = ui.interact(r, egui::Id::new(("window_btn", cmd)), Sense::click());
@@ -134,17 +127,7 @@ impl RustCord {
ui.painter().rect_filled(r, 0.0, if cmd == 0 { Color32::from_rgb(0xda, 0x37, 0x3c) } else { t.bg_hover });
}
let c = if b.hovered() && cmd == 0 { Color32::WHITE } else { t.interactive_normal };
- if cmd == 0 {
- // The close cross is drawn, not typed: its Segoe code
- // point is a boxed X in one of the fallback fonts.
- // Windows' own: a 10 px cross, one pixel thick.
- let (m, h) = (ui.painter().round_pos_to_pixels(r.center()), 5.0);
- let stroke = Stroke::new(1.0_f32, c);
- ui.painter().line_segment([m + vec2(-h, -h), m + vec2(h, h)], stroke);
- ui.painter().line_segment([m + vec2(-h, h), m + vec2(h, -h)], stroke);
- } else {
- ui.painter().text(r.center(), Align2::CENTER_CENTER, glyph, icon_font(10.0), c);
- }
+ paint_caption_glyph(ui.painter(), ui.painter().round_pos_to_pixels(r.center()), cmd, maximized, c);
if b.on_hover_text(tip).clicked() {
ctx.send_viewport_cmd(match cmd {
0 => ViewportCommand::Close,
@@ -612,6 +595,46 @@ impl RustCord {
}
}
+/// A title bar button's glyph (`cmd` 0 close, 1 maximize or restore, 2
+/// minimize), centred on `m`. Painted rather than typed on every platform:
+/// Segoe's caption glyphs exist only on Windows. The shapes are Segoe Fluent
+/// Icons' at 10 px: a 10 px box, lines one pixel thick, slightly rounded
+/// corners, minimize one row above the middle.
+fn paint_caption_glyph(p: &egui::Painter, m: egui::Pos2, cmd: u8, maximized: bool, c: Color32) {
+ let stroke = Stroke::new(1.0_f32, c);
+ // (A path, not `rect_stroke`: that rounds the corners to whole pixels,
+ // which puts a one pixel line across two.)
+ let window = |rect: Rect| {
+ let mut points = Vec::new();
+ egui::epaint::tessellator::path::rounded_rectangle(&mut points, rect, egui::Rounding::same(1.0));
+ egui::Shape::closed_line(points, stroke)
+ };
+ match cmd {
+ 0 => {
+ p.line_segment([m + vec2(-5.0, -5.0), m + vec2(5.0, 5.0)], stroke);
+ p.line_segment([m + vec2(-5.0, 5.0), m + vec2(5.0, -5.0)], stroke);
+ }
+ 1 if maximized => {
+ // The window in front, lower left...
+ p.add(window(Rect::from_min_max(m + vec2(-4.5, -2.5), m + vec2(2.5, 4.5))));
+ // ...and the top and right edges of the one behind it.
+ let corner = m + vec2(3.0, -3.0);
+ let arc = (0..=4).map(|i| {
+ let a = i as f32 * std::f32::consts::FRAC_PI_8;
+ corner + 1.5 * vec2(a.sin(), -a.cos())
+ });
+ let points = std::iter::once(m + vec2(-2.5, -4.5)).chain(arc).chain([m + vec2(4.5, 2.5)]).collect();
+ p.add(egui::Shape::line(points, stroke));
+ }
+ 1 => {
+ p.add(window(Rect::from_center_size(m, vec2(9.0, 9.0))));
+ }
+ _ => {
+ p.rect_filled(Rect::from_min_max(m + vec2(-5.0, -1.0), m + vec2(5.0, 0.0)), 0.0, c);
+ }
+ }
+}
+
/// Whether GIFs / animated emoji play right now (only while RustCord is the
/// focused window, like Discord's default; a playing GIF redraws the window
/// many times a second).