Skip to content

Commit

Permalink
refactor: switch to cirrus for egui styling
Browse files Browse the repository at this point in the history
  • Loading branch information
THEGOLDENPRO committed Dec 31, 2024
1 parent f8e8ee2 commit 49fba8d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 45 deletions.
45 changes: 1 addition & 44 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use cirrus_theming::v1::{Colour, Theme};
use eframe::egui::{self, Align, Color32, Context, CursorIcon, Frame, Layout, Margin, Rect, Shadow, Stroke, Style, TextStyle, Vec2};
use eframe::egui::{self, Align, Color32, Context, CursorIcon, Frame, Layout, Margin, Rect, Stroke, Vec2};
use egui_notify::ToastLevel;

use crate::{config::config::Config, files, image::image::Image, image_loader::ImageLoader, windows::info::InfoWindow, magnification_panel::MagnificationPanel, notifier::NotifierAPI, window_scaling::WindowScaling, windows::about::AboutWindow, zoom_pan::ZoomPan};
Expand Down Expand Up @@ -53,47 +53,6 @@ impl<'a> Roseate<'a> {
}
}

fn set_app_style(&self, ctx: &Context) {
let mut custom_style = Style {
override_text_style: Some(TextStyle::Monospace),
..Default::default()
};

// TODO: override more default
// colours here with colours from our theme.

// Background colour styling.
custom_style.visuals.panel_fill = Color32::from_hex(
&self.theme.primary_colour.hex_code
).unwrap();

// Window styling.
custom_style.visuals.window_highlight_topmost = false;

custom_style.visuals.window_fill = Color32::from_hex(
&self.theme.secondary_colour.hex_code
).unwrap();
custom_style.visuals.window_stroke = Stroke::new(
1.0,
Color32::from_hex(&self.theme.third_colour.hex_code).unwrap()
);
custom_style.visuals.window_shadow = Shadow::NONE;

custom_style.visuals.widgets.inactive.bg_fill =
Color32::from_hex(
&self.theme.primary_colour.hex_code
).unwrap();

// Text styling.
custom_style.visuals.override_text_color = Some(
Color32::from_hex(
&self.theme.text_colour.hex_code
).unwrap()
);

ctx.set_style(custom_style);
}

fn draw_dotted_line(&self, ui: &egui::Painter, pos: &[egui::Pos2]) {
ui.add(
egui::Shape::dashed_line(
Expand All @@ -115,8 +74,6 @@ impl<'a> Roseate<'a> {
impl eframe::App for Roseate<'_> {

fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
self.set_app_style(ctx);

self.info_box.init(&self.image);
self.info_box.handle_input(ctx);

Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::{env, path::Path, time::Duration};

use cirrus_egui::v1::styling::Styling;
use config::config::Config;
use log::debug;
use eframe::egui;
Expand Down Expand Up @@ -138,6 +139,10 @@ fn main() -> eframe::Result {
options,
Box::new(|cc| {
egui_extras::install_image_loaders(&cc.egui_ctx);
Styling::new(&theme, None)
.set_all()
.apply(&cc.egui_ctx);

Ok(Box::new(Roseate::new(image, theme, notifier, config)))
}),
)
Expand Down

0 comments on commit 49fba8d

Please sign in to comment.