notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

app_creation.rs (2183B)


      1 use crate::{
      2     app_size_handler::AppSizeHandler,
      3     app_style::{create_custom_style, dark_mode, desktop_font_size, light_mode, mobile_font_size},
      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 
     19         if let Some(window_size) = AppSizeHandler::new(&paths).get_app_size() {
     20             builder.with_inner_size(window_size)
     21         } else {
     22             builder
     23         }
     24     });
     25 
     26     eframe::NativeOptions {
     27         window_builder: Some(window_builder),
     28         ..Default::default()
     29     }
     30 }
     31 
     32 fn generate_native_options_with_builder_modifiers(
     33     apply_builder_modifiers: fn(egui::ViewportBuilder) -> egui::ViewportBuilder,
     34 ) -> NativeOptions {
     35     let window_builder =
     36         Box::new(move |builder: egui::ViewportBuilder| apply_builder_modifiers(builder));
     37 
     38     eframe::NativeOptions {
     39         window_builder: Some(window_builder),
     40         ..Default::default()
     41     }
     42 }
     43 
     44 pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions {
     45     generate_native_options_with_builder_modifiers(|builder| {
     46         builder
     47             .with_fullsize_content_view(true)
     48             .with_titlebar_shown(false)
     49             .with_title_shown(false)
     50             .with_inner_size([405.0, 915.0])
     51     })
     52 }
     53 
     54 pub fn setup_cc(ctx: &egui::Context, is_mobile: bool, light: bool) {
     55     setup_fonts(ctx);
     56 
     57     //ctx.set_pixels_per_point(ctx.pixels_per_point() + UI_SCALE_FACTOR);
     58     //ctx.set_pixels_per_point(1.0);
     59     //
     60     //
     61     //ctx.tessellation_options_mut(|to| to.feathering = false);
     62 
     63     egui_extras::install_image_loaders(ctx);
     64 
     65     if light {
     66         ctx.set_visuals(light_mode())
     67     } else {
     68         ctx.set_visuals(dark_mode(is_mobile));
     69     }
     70 
     71     ctx.set_style(if is_mobile {
     72         create_custom_style(ctx, mobile_font_size)
     73     } else {
     74         create_custom_style(ctx, desktop_font_size)
     75     });
     76 }