notedeck

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

setup.rs (2500B)


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