notedeck

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

commit 577aa76ac79788e164cb825da0fed906efb07005
parent d064987e458c246b2baf22313cba72afd6eafcad
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 14 Jun 2024 11:12:16 -0700

add --light lightmode flag to previews and notedeck

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mpreview | 2+-
Msrc/app.rs | 8+++++++-
Msrc/app_creation.rs | 12+++++++++---
Msrc/ui/preview.rs | 4+---
Msrc/ui_preview/main.rs | 19++++++++++++++-----
5 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/preview b/preview @@ -1,4 +1,4 @@ #!/usr/bin/env bash # pass --mobile for mobile previews -cargo run --bin ui_preview --release -- "$@" +RUST_LOG=info cargo run --bin ui_preview --release -- "$@" diff --git a/src/app.rs b/src/app.rs @@ -644,11 +644,16 @@ impl Damus { let mut timelines: Vec<Timeline> = vec![]; let mut is_mobile: Option<bool> = None; let mut i = 0; + let mut light: bool = false; if args.len() > 1 { for arg in &args[1..] { if arg == "--mobile" { is_mobile = Some(true); + } else if arg == "--light" { + light = true; + } else if arg == "--dark" { + light = false; } else if arg == "--filter" { let next_args = &args[1 + i + 1..]; if next_args.is_empty() { @@ -691,13 +696,14 @@ impl Damus { let is_mobile = is_mobile.unwrap_or(ui::is_compiled_as_mobile()); - setup_cc(cc, is_mobile); + setup_cc(cc, is_mobile, light); let imgcache_dir = data_path.as_ref().join(ImageCache::rel_datadir()); let _ = std::fs::create_dir_all(imgcache_dir.clone()); let mut config = Config::new(); config.set_ingester_threads(2); + Self { is_mobile, state: DamusState::Initializing, diff --git a/src/app_creation.rs b/src/app_creation.rs @@ -1,4 +1,6 @@ -use crate::app_style::{create_custom_style, dark_mode, desktop_font_size, mobile_font_size}; +use crate::app_style::{ + create_custom_style, dark_mode, desktop_font_size, light_mode, mobile_font_size, +}; use crate::fonts::setup_fonts; use eframe::NativeOptions; @@ -35,7 +37,7 @@ pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions { }) } -pub fn setup_cc(cc: &eframe::CreationContext<'_>, is_mobile: bool) { +pub fn setup_cc(cc: &eframe::CreationContext<'_>, is_mobile: bool, light: bool) { let ctx = &cc.egui_ctx; setup_fonts(ctx); @@ -47,7 +49,11 @@ pub fn setup_cc(cc: &eframe::CreationContext<'_>, is_mobile: bool) { egui_extras::install_image_loaders(ctx); - ctx.set_visuals(dark_mode(is_mobile)); + if light { + ctx.set_visuals(light_mode()) + } else { + ctx.set_visuals(dark_mode(is_mobile)); + } ctx.set_style(if is_mobile { create_custom_style(ctx, mobile_font_size) diff --git a/src/ui/preview.rs b/src/ui/preview.rs @@ -32,8 +32,6 @@ impl PreviewApp { impl eframe::App for PreviewApp { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - egui::CentralPanel::default() - .frame(egui::Frame::none()) - .show(ctx, |ui| self.view.ui(ui)); + egui::CentralPanel::default().show(ctx, |ui| self.view.ui(ui)); } } diff --git a/src/ui_preview/main.rs b/src/ui_preview/main.rs @@ -7,14 +7,16 @@ use notedeck::ui::{ PreviewConfig, ProfilePic, ProfilePreview, RelayView, }; use std::env; +use tracing::info; struct PreviewRunner { force_mobile: bool, + light_mode: bool, } impl PreviewRunner { - fn new(force_mobile: bool) -> Self { - PreviewRunner { force_mobile } + fn new(force_mobile: bool, light_mode: bool) -> Self { + PreviewRunner { force_mobile, light_mode } } async fn run<P>(self, preview: P) @@ -30,12 +32,15 @@ impl PreviewRunner { }; let is_mobile = self.force_mobile; + let light_mode = self.light_mode; + let _ = eframe::run_native( "UI Preview Runner", native_options, Box::new(move |cc| { - setup_cc(cc, is_mobile); - Box::new(Into::<PreviewApp>::into(preview)) + let app = Into::<PreviewApp>::into(preview); + setup_cc(cc, is_mobile, light_mode); + Box::new(app) }), ); } @@ -59,10 +64,13 @@ macro_rules! previews { async fn main() { let mut name: Option<String> = None; let mut is_mobile: Option<bool> = None; + let mut light_mode: bool = false; for arg in env::args() { if arg == "--mobile" { is_mobile = Some(true); + } else if arg == "--light" { + light_mode = true; } else { name = Some(arg); } @@ -75,8 +83,9 @@ async fn main() { return; }; + println!("light mode previews: {}", if light_mode { "enabled" } else { "disabled" }); let is_mobile = is_mobile.unwrap_or(notedeck::ui::is_compiled_as_mobile()); - let runner = PreviewRunner::new(is_mobile); + let runner = PreviewRunner::new(is_mobile, light_mode); previews!( runner,