app_creation.rs (1838B)
1 use crate::app_style::{ 2 create_custom_style, dark_mode, desktop_font_size, light_mode, mobile_font_size, 3 }; 4 use crate::fonts::setup_fonts; 5 use eframe::NativeOptions; 6 7 //pub const UI_SCALE_FACTOR: f32 = 0.2; 8 9 pub fn generate_native_options() -> NativeOptions { 10 generate_native_options_with_builder_modifiers(|builder| { 11 builder 12 .with_fullsize_content_view(true) 13 .with_titlebar_shown(false) 14 .with_title_shown(false) 15 }) 16 } 17 18 fn generate_native_options_with_builder_modifiers( 19 apply_builder_modifiers: fn(egui::ViewportBuilder) -> egui::ViewportBuilder, 20 ) -> NativeOptions { 21 let window_builder = 22 Box::new(move |builder: egui::ViewportBuilder| apply_builder_modifiers(builder)); 23 24 eframe::NativeOptions { 25 window_builder: Some(window_builder), 26 ..Default::default() 27 } 28 } 29 30 pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions { 31 generate_native_options_with_builder_modifiers(|builder| { 32 builder 33 .with_fullsize_content_view(true) 34 .with_titlebar_shown(false) 35 .with_title_shown(false) 36 .with_inner_size([405.0, 915.0]) 37 }) 38 } 39 40 pub fn setup_cc(cc: &eframe::CreationContext<'_>, is_mobile: bool, light: bool) { 41 let ctx = &cc.egui_ctx; 42 setup_fonts(ctx); 43 44 //ctx.set_pixels_per_point(ctx.pixels_per_point() + UI_SCALE_FACTOR); 45 //ctx.set_pixels_per_point(1.0); 46 // 47 // 48 //ctx.tessellation_options_mut(|to| to.feathering = false); 49 50 egui_extras::install_image_loaders(ctx); 51 52 if light { 53 ctx.set_visuals(light_mode()) 54 } else { 55 ctx.set_visuals(dark_mode(is_mobile)); 56 } 57 58 ctx.set_style(if is_mobile { 59 create_custom_style(ctx, mobile_font_size) 60 } else { 61 create_custom_style(ctx, desktop_font_size) 62 }); 63 }