mobile: black panel bg color

for battery life

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-04-12 21:14:56 -07:00
parent 0a9e7698c1
commit 3b9cd3f3c4
4 changed files with 27 additions and 23 deletions

View File

@@ -1,5 +1,4 @@
use crate::app_creation::setup_cc; use crate::app_creation::setup_cc;
use crate::colors;
use crate::app_style::user_requested_visuals_change; use crate::app_style::user_requested_visuals_change;
use crate::error::Error; use crate::error::Error;
use crate::frame_history::FrameHistory; 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; ui.visuals_mut().button_frame = false;
if let Some(new_visuals) = 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) ctx.set_visuals(new_visuals)
} }

View File

@@ -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 = let window_builder =
Box::new( Box::new(move |builder: egui::ViewportBuilder| apply_builder_modifiers(builder));
move |builder: egui::ViewportBuilder| apply_builder_modifiers(builder)
);
eframe::NativeOptions { eframe::NativeOptions {
window_builder: Some(window_builder), window_builder: Some(window_builder),
@@ -48,7 +48,7 @@ pub fn setup_cc(cc: &eframe::CreationContext<'_>) {
egui_extras::install_image_loaders(ctx); 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) { ctx.set_style(if is_mobile(ctx) {
create_text_styles(ctx, mobile_font_size) create_text_styles(ctx, mobile_font_size)

View File

@@ -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::{ use egui::{
epaint::Shadow, epaint::Shadow,
style::{WidgetVisuals, Widgets}, style::{WidgetVisuals, Widgets},
@@ -13,11 +13,15 @@ pub fn light_mode() -> Visuals {
create_themed_visuals(light_color_theme(), Visuals::light()) create_themed_visuals(light_color_theme(), Visuals::light())
} }
pub fn dark_mode() -> Visuals { pub fn dark_mode(mobile: bool) -> Visuals {
create_themed_visuals(dark_color_theme(), Visuals::dark()) 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 cur_darkmode {
if ui if ui
.add(Button::new("").frame(false)) .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") .on_hover_text("Switch to dark mode")
.clicked() .clicked()
{ {
return Some(dark_mode()); return Some(dark_mode(mobile));
} }
None 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 { pub fn create_text_styles(ctx: &Context, font_size: fn(NotedeckTextStyle) -> f32) -> Style {
let mut style = (*ctx.style()).clone(); let mut style = (*ctx.style()).clone();
style.text_styles = NotedeckTextStyle::iter().map(|text_style| { style.text_styles = NotedeckTextStyle::iter()
(text_style.text_style(), FontId::new(font_size(text_style), egui::FontFamily::Proportional)) .map(|text_style| {
}).collect(); (
text_style.text_style(),
FontId::new(font_size(text_style), egui::FontFamily::Proportional),
)
})
.collect();
style style
} }

View File

@@ -3,7 +3,6 @@ use egui::Color32;
pub const PURPLE: Color32 = Color32::from_rgb(0xCC, 0x43, 0xC5); pub const PURPLE: Color32 = Color32::from_rgb(0xCC, 0x43, 0xC5);
//pub const DARK_BG: Color32 = egui::Color32::from_rgb(40, 44, 52); //pub const DARK_BG: Color32 = egui::Color32::from_rgb(40, 44, 52);
const GRAY_SECONDARY: Color32 = Color32::from_rgb(0x8A, 0x8A, 0x8A); 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 BLACK: Color32 = Color32::from_rgb(0x00, 0x00, 0x00);
const RED_700: Color32 = Color32::from_rgb(0xC7, 0x37, 0x5A); const RED_700: Color32 = Color32::from_rgb(0xC7, 0x37, 0x5A);
@@ -43,15 +42,12 @@ pub struct ColorTheme {
pub inactive_weak_bg_fill: Color32, pub inactive_weak_bg_fill: Color32,
} }
pub struct DarkTheme; pub fn dark_color_theme(mobile: bool) -> ColorTheme {
pub struct LightTheme;
pub fn dark_color_theme() -> ColorTheme {
ColorTheme { ColorTheme {
// VISUALS // VISUALS
panel_fill: DARKER_BG, panel_fill: if mobile { Color32::BLACK } else { DARKER_BG },
extreme_bg_color: SEMI_DARKER_BG, extreme_bg_color: SEMI_DARKER_BG,
text_color: WHITE, text_color: Color32::WHITE,
err_fg_color: RED_700, err_fg_color: RED_700,
hyperlink_color: PURPLE, hyperlink_color: PURPLE,
@@ -75,7 +71,7 @@ pub fn dark_color_theme() -> ColorTheme {
pub fn light_color_theme() -> ColorTheme { pub fn light_color_theme() -> ColorTheme {
ColorTheme { ColorTheme {
// VISUALS // VISUALS
panel_fill: LIGHT_GRAY, panel_fill: Color32::WHITE,
extreme_bg_color: EVEN_DARKER_GRAY, extreme_bg_color: EVEN_DARKER_GRAY,
text_color: BLACK, text_color: BLACK,
err_fg_color: RED_700, err_fg_color: RED_700,