app_creation.rs (2548B)
1 use crate::{ 2 app_size_handler::AppSizeHandler, 3 app_style::{add_custom_style, dark_mode, light_mode}, 4 fonts::setup_fonts, 5 storage::DataPath, 6 }; 7 8 use eframe::NativeOptions; 9 10 //pub const UI_SCALE_FACTOR: f32 = 0.2; 11 12 pub fn generate_native_options(paths: DataPath) -> NativeOptions { 13 let window_builder = Box::new(move |builder: egui::ViewportBuilder| { 14 let builder = builder 15 .with_fullsize_content_view(true) 16 .with_titlebar_shown(false) 17 .with_title_shown(false) 18 .with_icon(std::sync::Arc::new( 19 eframe::icon_data::from_png_bytes(app_icon()).expect("icon"), 20 )); 21 22 if let Some(window_size) = AppSizeHandler::new(&paths).get_app_size() { 23 builder.with_inner_size(window_size) 24 } else { 25 builder 26 } 27 }); 28 29 eframe::NativeOptions { 30 window_builder: Some(window_builder), 31 viewport: egui::ViewportBuilder::default().with_icon(std::sync::Arc::new( 32 eframe::icon_data::from_png_bytes(app_icon()).expect("icon"), 33 )), 34 ..Default::default() 35 } 36 } 37 38 fn generate_native_options_with_builder_modifiers( 39 apply_builder_modifiers: fn(egui::ViewportBuilder) -> egui::ViewportBuilder, 40 ) -> NativeOptions { 41 let window_builder = 42 Box::new(move |builder: egui::ViewportBuilder| apply_builder_modifiers(builder)); 43 44 eframe::NativeOptions { 45 window_builder: Some(window_builder), 46 ..Default::default() 47 } 48 } 49 50 pub fn app_icon() -> &'static [u8; 271986] { 51 std::include_bytes!("../assets/damus-app-icon.png") 52 } 53 54 pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions { 55 generate_native_options_with_builder_modifiers(|builder| { 56 builder 57 .with_fullsize_content_view(true) 58 .with_titlebar_shown(false) 59 .with_title_shown(false) 60 .with_inner_size([405.0, 915.0]) 61 .with_icon(eframe::icon_data::from_png_bytes(app_icon()).expect("icon")) 62 }) 63 } 64 65 pub fn setup_cc(ctx: &egui::Context, is_mobile: bool, light: bool) { 66 setup_fonts(ctx); 67 68 //ctx.set_pixels_per_point(ctx.pixels_per_point() + UI_SCALE_FACTOR); 69 //ctx.set_pixels_per_point(1.0); 70 // 71 // 72 //ctx.tessellation_options_mut(|to| to.feathering = false); 73 74 egui_extras::install_image_loaders(ctx); 75 76 if light { 77 ctx.set_visuals(light_mode()) 78 } else { 79 ctx.set_visuals(dark_mode(is_mobile)); 80 } 81 82 ctx.all_styles_mut(|style| add_custom_style(is_mobile, style)); 83 }