setup.rs (3504B)
1 use crate::{fonts, theme}; 2 3 use eframe::NativeOptions; 4 use egui::ThemePreference; 5 use notedeck::{AppSizeHandler, DataPath}; 6 use tracing::info; 7 8 pub fn setup_chrome(ctx: &egui::Context, args: ¬edeck::Args, theme: ThemePreference) { 9 let is_mobile = args 10 .is_mobile 11 .unwrap_or(notedeck::ui::is_compiled_as_mobile()); 12 13 let is_oled = notedeck::ui::is_oled(); 14 15 // Some people have been running notedeck in debug, let's catch that! 16 if !args.tests && cfg!(debug_assertions) && !args.debug { 17 println!("--- WELCOME TO DAMUS NOTEDECK! ---"); 18 println!("It looks like are running notedeck in debug mode, unless you are a developer, this is not likely what you want."); 19 println!("If you are a developer, run `cargo run -- --debug` to skip this message."); 20 println!("For everyone else, try again with `cargo run --release`. Enjoy!"); 21 println!("---------------------------------"); 22 panic!(); 23 } 24 25 ctx.options_mut(|o| { 26 info!("Loaded theme {:?} from disk", theme); 27 o.theme_preference = theme; 28 }); 29 ctx.set_visuals_of(egui::Theme::Dark, theme::dark_mode(is_oled)); 30 ctx.set_visuals_of(egui::Theme::Light, theme::light_mode()); 31 setup_cc(ctx, is_mobile); 32 } 33 34 pub fn setup_cc(ctx: &egui::Context, is_mobile: bool) { 35 fonts::setup_fonts(ctx); 36 37 //ctx.set_pixels_per_point(ctx.pixels_per_point() + UI_SCALE_FACTOR); 38 //ctx.set_pixels_per_point(1.0); 39 // 40 // 41 //ctx.tessellation_options_mut(|to| to.feathering = false); 42 43 egui_extras::install_image_loaders(ctx); 44 45 ctx.all_styles_mut(|style| theme::add_custom_style(is_mobile, style)); 46 } 47 48 //pub const UI_SCALE_FACTOR: f32 = 0.2; 49 50 pub fn generate_native_options(paths: DataPath) -> NativeOptions { 51 let window_builder = Box::new(move |builder: egui::ViewportBuilder| { 52 let builder = builder 53 .with_fullsize_content_view(true) 54 .with_titlebar_shown(false) 55 .with_title_shown(false) 56 .with_icon(std::sync::Arc::new( 57 eframe::icon_data::from_png_bytes(app_icon()).expect("icon"), 58 )); 59 60 if let Some(window_size) = AppSizeHandler::new(&paths).get_app_size() { 61 builder.with_inner_size(window_size) 62 } else { 63 builder 64 } 65 }); 66 67 eframe::NativeOptions { 68 window_builder: Some(window_builder), 69 viewport: egui::ViewportBuilder::default().with_icon(std::sync::Arc::new( 70 eframe::icon_data::from_png_bytes(app_icon()).expect("icon"), 71 )), 72 ..Default::default() 73 } 74 } 75 76 fn generate_native_options_with_builder_modifiers( 77 apply_builder_modifiers: fn(egui::ViewportBuilder) -> egui::ViewportBuilder, 78 ) -> NativeOptions { 79 let window_builder = 80 Box::new(move |builder: egui::ViewportBuilder| apply_builder_modifiers(builder)); 81 82 eframe::NativeOptions { 83 window_builder: Some(window_builder), 84 ..Default::default() 85 } 86 } 87 88 pub fn app_icon() -> &'static [u8; 271986] { 89 std::include_bytes!("../../../assets/damus-app-icon.png") 90 } 91 92 pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions { 93 generate_native_options_with_builder_modifiers(|builder| { 94 builder 95 .with_fullsize_content_view(true) 96 .with_titlebar_shown(false) 97 .with_title_shown(false) 98 .with_inner_size([405.0, 915.0]) 99 .with_icon(eframe::icon_data::from_png_bytes(app_icon()).expect("icon")) 100 }) 101 }