add --light lightmode flag to previews and notedeck

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin 2024-06-14 11:12:16 -07:00
parent d064987e45
commit 577aa76ac7
5 changed files with 32 additions and 13 deletions

View File

@ -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 -- "$@"

View File

@ -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,

View File

@ -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);
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)

View File

@ -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));
}
}

View File

@ -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,