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