Use custom style in app

Signed-off-by: kernelkind <kernelkind@gmail.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
kernelkind
2024-04-12 13:02:27 -04:00
committed by William Casarin
parent cf07427204
commit f0d56da4f5
2 changed files with 22 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
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;
use crate::imgcache::ImageCache;
@@ -429,9 +430,6 @@ fn process_message(damus: &mut Damus, relay: &str, msg: &RelayMessage) {
}
fn render_damus(damus: &mut Damus, ctx: &Context) {
//ctx.style_mut(|s| set_app_style(s, is_mobile(ctx)));
ctx.style_mut(|s| set_app_style(s, true));
if is_mobile(ctx) {
render_damus_mobile(ctx, damus);
} else {
@@ -618,7 +616,13 @@ fn render_panel<'a>(ctx: &egui::Context, app: &'a mut Damus, timeline_ind: usize
top_panel(ctx).show(ctx, |ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
ui.visuals_mut().button_frame = false;
egui::widgets::global_dark_light_mode_switch(ui);
if let Some(new_visuals) =
user_requested_visuals_change(ctx.style().visuals.dark_mode, ui)
{
ctx.set_visuals(new_visuals)
}
if ui
.add(egui::Button::new("A").frame(false))
.on_hover_text("Text mode")
@@ -663,24 +667,6 @@ fn render_panel<'a>(ctx: &egui::Context, app: &'a mut Damus, timeline_ind: usize
});
}
fn set_app_style(style: &mut Style, is_mobile: bool) {
let visuals = &mut style.visuals;
visuals.hyperlink_color = colors::PURPLE;
if visuals.dark_mode {
visuals.override_text_color = Some(egui::Color32::from_rgb(250, 250, 250));
//visuals.panel_fill = egui::Color32::from_rgb(31, 31, 31);
if is_mobile {
visuals.panel_fill = egui::Color32::from_rgb(0, 0, 0);
} else {
visuals.panel_fill = egui::Color32::from_rgb(31, 31, 31);
}
//visuals.override_text_color = Some(egui::Color32::from_rgb(170, 177, 190));
//visuals.panel_fill = egui::Color32::from_rgb(40, 44, 52);
} else {
visuals.override_text_color = Some(egui::Color32::BLACK);
};
}
fn render_damus_mobile(ctx: &egui::Context, app: &mut Damus) {
render_panel(ctx, app, 0);

View File

@@ -1,3 +1,5 @@
use crate::app::is_mobile;
use crate::app_style::{create_text_styles, dark_mode, desktop_font_size, mobile_font_size};
use crate::fonts::setup_fonts;
use eframe::NativeOptions;
@@ -39,10 +41,18 @@ pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions {
}
pub fn setup_cc(cc: &eframe::CreationContext<'_>) {
setup_fonts(&cc.egui_ctx);
let ctx = &cc.egui_ctx;
setup_fonts(ctx);
cc.egui_ctx
.set_pixels_per_point(cc.egui_ctx.pixels_per_point() + UI_SCALE_FACTOR);
ctx.set_pixels_per_point(ctx.pixels_per_point() + UI_SCALE_FACTOR);
egui_extras::install_image_loaders(&cc.egui_ctx);
egui_extras::install_image_loaders(ctx);
ctx.set_visuals(dark_mode());
ctx.set_style(if is_mobile(ctx) {
create_text_styles(ctx, mobile_font_size)
} else {
create_text_styles(ctx, desktop_font_size)
});
}