mirror of https://github.com/terhechte/postsack
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
3.2 KiB
Rust
98 lines
3.2 KiB
Rust
3 years ago
|
#![cfg(target_os = "macos")]
|
||
3 years ago
|
//! Initially, I wanted to laod the mac system fonts from
|
||
|
//! `/System/Library/Fonts/SFNS.ttf` but while loading these
|
||
|
//! worked, no actual characters were displayed.
|
||
|
|
||
|
const SYSTEM_FONT: &[u8] = include_bytes!("../fonts/mac_regular.otf");
|
||
|
const SYSTEM_MONO_FONT: &[u8] = include_bytes!("../fonts/mac_mono.ttc");
|
||
3 years ago
|
|
||
|
use cocoa;
|
||
3 years ago
|
use eframe::egui::{self, Color32, FontDefinitions, FontFamily, Stroke};
|
||
3 years ago
|
use eyre::{bail, Result};
|
||
3 years ago
|
|
||
3 years ago
|
use objc::runtime::{Object, YES};
|
||
3 years ago
|
use objc::*;
|
||
3 years ago
|
|
||
3 years ago
|
use super::{PlatformColors, Theme};
|
||
3 years ago
|
|
||
3 years ago
|
pub fn platform_colors(theme: Theme) -> PlatformColors {
|
||
3 years ago
|
match theme {
|
||
|
Theme::Light => PlatformColors {
|
||
3 years ago
|
is_light: true,
|
||
|
animation_background: Color32::from_rgb(248, 246, 249),
|
||
3 years ago
|
window_background: Color32::from_rgb(238, 236, 242),
|
||
|
content_background: Color32::from_rgb(236, 234, 238),
|
||
3 years ago
|
text_primary: Color32::from_gray(0),
|
||
|
text_secondary: Color32::from_gray(30),
|
||
|
line1: Color32::from_gray(0),
|
||
|
line2: Color32::from_gray(30),
|
||
|
line3: Color32::from_gray(60),
|
||
|
line4: Color32::from_gray(90),
|
||
3 years ago
|
},
|
||
|
Theme::Dark => PlatformColors {
|
||
3 years ago
|
is_light: false,
|
||
|
animation_background: Color32::from_rgb(0, 0, 0),
|
||
3 years ago
|
window_background: Color32::from_rgb(36, 30, 42),
|
||
|
content_background: Color32::from_rgb(20, 14, 26),
|
||
3 years ago
|
text_primary: Color32::from_gray(255),
|
||
|
text_secondary: Color32::from_gray(200),
|
||
|
line1: Color32::from_gray(255),
|
||
|
line2: Color32::from_gray(190),
|
||
|
line3: Color32::from_gray(150),
|
||
|
line4: Color32::from_gray(70),
|
||
3 years ago
|
},
|
||
3 years ago
|
}
|
||
|
}
|
||
|
|
||
|
/// This is called from `App::setup`
|
||
3 years ago
|
pub fn setup(ctx: &egui::CtxRef) {
|
||
|
install_fonts(ctx)
|
||
|
}
|
||
3 years ago
|
|
||
|
/// This is called once from `App::update` on the first run.
|
||
|
pub fn initial_update(_ctx: &egui::CtxRef) -> Result<()> {
|
||
|
unsafe {
|
||
|
let app = cocoa::appkit::NSApp();
|
||
|
if app.is_null() {
|
||
|
bail!("Could not retrieve NSApp");
|
||
|
}
|
||
|
let main_window: *mut Object = msg_send![app, mainWindow];
|
||
|
|
||
|
let _: () = msg_send![main_window, setTitlebarAppearsTransparent: YES];
|
||
|
}
|
||
|
Ok(())
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
/// Return a primary button intended for the top navigation in the
|
||
|
/// platform style.
|
||
|
/// FIXME: Dark / Light Mode distinction!
|
||
|
pub fn navigation_button(title: &str) -> egui::Button {
|
||
|
// Finder info panel bottom button.
|
||
|
let fill = Color32::from_rgb(87, 84, 92);
|
||
|
// let stroke = Color32::from_rgb(97, 94, 102);
|
||
|
let text = Color32::WHITE;
|
||
|
egui::Button::new(title)
|
||
|
.text_color(text)
|
||
|
.stroke(Stroke::new(1.0, fill))
|
||
|
.fill(fill)
|
||
|
}
|
||
|
|
||
3 years ago
|
fn install_fonts(egui_ctx: &egui::CtxRef) {
|
||
|
let mut fonts = FontDefinitions::default();
|
||
|
for (data, family, key) in [
|
||
|
(SYSTEM_FONT, FontFamily::Proportional, "Regular"),
|
||
|
(SYSTEM_MONO_FONT, FontFamily::Monospace, "Mono"),
|
||
|
] {
|
||
|
fonts
|
||
|
.font_data
|
||
3 years ago
|
.insert(key.to_owned(), std::borrow::Cow::Borrowed(data));
|
||
3 years ago
|
fonts
|
||
|
.fonts_for_family
|
||
|
.get_mut(&family)
|
||
|
.unwrap()
|
||
|
.insert(0, key.to_owned());
|
||
|
}
|
||
|
|
||
|
egui_ctx.set_fonts(fonts);
|
||
|
}
|