commit 3b9cd3f3c4f7953328b6b20e203253b58c9ecf31
parent 0a9e7698c14d589508a0121b3c4eb70d7999ddfe
Author: William Casarin <jb55@jb55.com>
Date: Fri, 12 Apr 2024 21:14:56 -0700
mobile: black panel bg color
for battery life
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
4 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/src/app.rs b/src/app.rs
@@ -1,5 +1,4 @@
use crate::app_creation::setup_cc;
-use crate::colors;
use crate::app_style::user_requested_visuals_change;
use crate::error::Error;
use crate::frame_history::FrameHistory;
@@ -618,7 +617,7 @@ fn render_panel<'a>(ctx: &egui::Context, app: &'a mut Damus, timeline_ind: usize
ui.visuals_mut().button_frame = false;
if let Some(new_visuals) =
- user_requested_visuals_change(ctx.style().visuals.dark_mode, ui)
+ user_requested_visuals_change(is_mobile(ctx), ctx.style().visuals.dark_mode, ui)
{
ctx.set_visuals(new_visuals)
}
diff --git a/src/app_creation.rs b/src/app_creation.rs
@@ -18,11 +18,11 @@ pub fn generate_native_options() -> NativeOptions {
})
}
-fn generate_native_options_with_builder_modifiers(apply_builder_modifiers: fn(egui::ViewportBuilder) -> egui::ViewportBuilder) -> NativeOptions {
+fn generate_native_options_with_builder_modifiers(
+ apply_builder_modifiers: fn(egui::ViewportBuilder) -> egui::ViewportBuilder,
+) -> NativeOptions {
let window_builder =
- Box::new(
- move |builder: egui::ViewportBuilder| apply_builder_modifiers(builder)
- );
+ Box::new(move |builder: egui::ViewportBuilder| apply_builder_modifiers(builder));
eframe::NativeOptions {
window_builder: Some(window_builder),
@@ -48,7 +48,7 @@ pub fn setup_cc(cc: &eframe::CreationContext<'_>) {
egui_extras::install_image_loaders(ctx);
- ctx.set_visuals(dark_mode());
+ ctx.set_visuals(dark_mode(is_mobile(ctx)));
ctx.set_style(if is_mobile(ctx) {
create_text_styles(ctx, mobile_font_size)
diff --git a/src/app_style.rs b/src/app_style.rs
@@ -1,4 +1,4 @@
-use crate::colors::{dark_color_theme, light_color_theme, ColorTheme, DarkTheme, LightTheme};
+use crate::colors::{dark_color_theme, light_color_theme, ColorTheme};
use egui::{
epaint::Shadow,
style::{WidgetVisuals, Widgets},
@@ -13,11 +13,15 @@ pub fn light_mode() -> Visuals {
create_themed_visuals(light_color_theme(), Visuals::light())
}
-pub fn dark_mode() -> Visuals {
- create_themed_visuals(dark_color_theme(), Visuals::dark())
+pub fn dark_mode(mobile: bool) -> Visuals {
+ create_themed_visuals(dark_color_theme(mobile), Visuals::dark())
}
-pub fn user_requested_visuals_change(cur_darkmode: bool, ui: &mut Ui) -> Option<Visuals> {
+pub fn user_requested_visuals_change(
+ mobile: bool,
+ cur_darkmode: bool,
+ ui: &mut Ui,
+) -> Option<Visuals> {
if cur_darkmode {
if ui
.add(Button::new("☀").frame(false))
@@ -31,7 +35,7 @@ pub fn user_requested_visuals_change(cur_darkmode: bool, ui: &mut Ui) -> Option<
.on_hover_text("Switch to dark mode")
.clicked()
{
- return Some(dark_mode());
+ return Some(dark_mode(mobile));
}
None
}
@@ -40,9 +44,14 @@ pub fn user_requested_visuals_change(cur_darkmode: bool, ui: &mut Ui) -> Option<
pub fn create_text_styles(ctx: &Context, font_size: fn(NotedeckTextStyle) -> f32) -> Style {
let mut style = (*ctx.style()).clone();
- style.text_styles = NotedeckTextStyle::iter().map(|text_style| {
- (text_style.text_style(), FontId::new(font_size(text_style), egui::FontFamily::Proportional))
- }).collect();
+ style.text_styles = NotedeckTextStyle::iter()
+ .map(|text_style| {
+ (
+ text_style.text_style(),
+ FontId::new(font_size(text_style), egui::FontFamily::Proportional),
+ )
+ })
+ .collect();
style
}
diff --git a/src/colors.rs b/src/colors.rs
@@ -3,7 +3,6 @@ use egui::Color32;
pub const PURPLE: Color32 = Color32::from_rgb(0xCC, 0x43, 0xC5);
//pub const DARK_BG: Color32 = egui::Color32::from_rgb(40, 44, 52);
const GRAY_SECONDARY: Color32 = Color32::from_rgb(0x8A, 0x8A, 0x8A);
-const WHITE: Color32 = Color32::from_rgb(0xFF, 0xFF, 0xFF);
const BLACK: Color32 = Color32::from_rgb(0x00, 0x00, 0x00);
const RED_700: Color32 = Color32::from_rgb(0xC7, 0x37, 0x5A);
@@ -43,15 +42,12 @@ pub struct ColorTheme {
pub inactive_weak_bg_fill: Color32,
}
-pub struct DarkTheme;
-pub struct LightTheme;
-
-pub fn dark_color_theme() -> ColorTheme {
+pub fn dark_color_theme(mobile: bool) -> ColorTheme {
ColorTheme {
// VISUALS
- panel_fill: DARKER_BG,
+ panel_fill: if mobile { Color32::BLACK } else { DARKER_BG },
extreme_bg_color: SEMI_DARKER_BG,
- text_color: WHITE,
+ text_color: Color32::WHITE,
err_fg_color: RED_700,
hyperlink_color: PURPLE,
@@ -75,7 +71,7 @@ pub fn dark_color_theme() -> ColorTheme {
pub fn light_color_theme() -> ColorTheme {
ColorTheme {
// VISUALS
- panel_fill: LIGHT_GRAY,
+ panel_fill: Color32::WHITE,
extreme_bg_color: EVEN_DARKER_GRAY,
text_color: BLACK,
err_fg_color: RED_700,