notedeck

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

setup.rs (3462B)


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