Skip to content

Commit

Permalink
add dark mode, make progress bars colored, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisheib committed Apr 13, 2023
1 parent 2fc0ef3 commit f0bb167
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ststat"
version = "0.1.4"
version = "0.1.6"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
14 changes: 14 additions & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ pub fn auto_color(index: i32) -> Color32 {
_ => todo!("auto_color({index}) not implemented yet, please report!"),
}
}

pub fn auto_color_dark(index: i32) -> Color32 {
let c = auto_color(index);
Color32::from_rgba_premultiplied(
(c.r() as f32 * 0.5) as u8,
(c.g() as f32 * 0.5) as u8,
(c.b() as f32 * 0.5) as u8,
c.a(),
)
}

pub fn get_base_background() -> Color32 {
Color32::from_rgba_premultiplied(30, 32, 36, 255)
}
7 changes: 5 additions & 2 deletions src/components/edgy_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ impl Widget for EdgyProgressBar {
);
let inner_rect = Rect::from_min_size(
outer_rect.min,
vec2(outer_rect.width() * progress, outer_rect.height()),
vec2(
(outer_rect.width() * progress).max(2.0),
outer_rect.height(),
),
);

let (dark, bright) = (0.7, 1.0);
Expand All @@ -130,7 +133,7 @@ impl Widget for EdgyProgressBar {
inner_rect,
Rounding::none(),
Color32::from(
Rgba::from(fill.unwrap_or(visuals.selection.bg_fill)) * color_factor as f32,
Rgba::from(fill.unwrap_or(Color32::from_rgb(0, 83, 116))) * color_factor as f32,
),
Stroke::NONE,
);
Expand Down
17 changes: 12 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ fn main() -> Result<(), eframe::Error> {
s.current_settings.location.x as f32,
s.current_settings.location.y as f32,
);
let use_plain_background = s.current_settings.use_plain_dark_background;
drop(s);

let options = eframe::NativeOptions {
Expand All @@ -152,10 +153,10 @@ fn main() -> Result<(), eframe::Error> {
eframe::run_native(
INTERNAL_WINDOW_TITLE, // title used for identifying window to grab handle
options,
Box::new(|cc| {
Box::new(move |cc| {
let mut v = Visuals::dark();
v.override_text_color = Some(Color32::from_gray(250));
v.window_fill = get_windows_glass_color();
v.window_fill = get_windows_glass_color(use_plain_background);
cc.egui_ctx.set_visuals(v);
Box::new(appstate)
}),
Expand Down Expand Up @@ -356,10 +357,15 @@ impl eframe::App for MyApp {
drop(s);
println!("Setup sidebar done");
}
let use_plain_background = self
.settings
.lock()
.current_settings
.use_plain_dark_background;

custom_window_frame(ctx, frame, "STStat", |ui| {
custom_window_frame(use_plain_background, ctx, frame, "STStat", |ui| {
if update {
refresh_color(ui);
refresh_color(self, ui);
}
ui.columns(2, |ui| {
ui[0].add(Label::new(
Expand Down Expand Up @@ -411,6 +417,7 @@ impl eframe::App for MyApp {
}

fn custom_window_frame(
use_plain_background: bool,
ctx: &egui::Context,
frame: &mut eframe::Frame,
title: &str,
Expand All @@ -419,7 +426,7 @@ fn custom_window_frame(
use egui::*;

let panel_frame = egui::Frame {
fill: { get_windows_glass_color() },
fill: { get_windows_glass_color(use_plain_background) },
// rounding: 10.0.into(),
stroke: Stroke {
width: 0.0,
Expand Down
6 changes: 6 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct InnerSettings {
pub location: Location,
pub track_timings: bool,
pub max_cpu_power: f64,
pub use_plain_dark_background: bool,
}

#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone)]
Expand Down Expand Up @@ -92,6 +93,11 @@ pub fn show_settings(appdata: &mut MyApp, ui: &mut Ui) {
"Display on right side:",
);
ui.separator();
ui.checkbox(
&mut settings.current_settings.use_plain_dark_background,
"Use plain dark background color",
);
ui.separator();
ui.checkbox(&mut settings.current_settings.track_timings, "trace perf");
if ui.button("save trace").clicked() {
use std::io::prelude::*;
Expand Down
69 changes: 27 additions & 42 deletions src/system_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
bytes_format::format_bytes,
circlevec::CircleVec,
color::auto_color,
color::{auto_color_dark, get_base_background},
components::edgy_progress::EdgyProgressBar,
process::{add_english_counter, get_pdh_process_data, init_process_metrics, Process},
sidebar::STATIC_HWND,
Expand Down Expand Up @@ -46,7 +46,7 @@ pub fn set_system_info_components(appdata: &mut MyApp, ui: &mut Ui) {
}

fn show_network(appdata: &mut MyApp, ui: &mut Ui) {
ui.vertical_centered(|ui| ui.label("Net"));
ui.vertical_centered(|ui| ui.label("Networks"));

for (interface_name, data) in filter_networks(appdata) {
ui.push_id(format!("network graph {interface_name}"), |ui| {
Expand Down Expand Up @@ -428,13 +428,13 @@ fn show_cpu(appdata: &mut MyApp, ui: &mut Ui) {
.strong(),
)
.desired_width(SIZE.x / 2.0 - 5.0)
.colored_dot(Some(auto_color(0))),
.fill(auto_color_dark(0)),
);
ui.add(
EdgyProgressBar::new(max_temp / 100.0)
.text(RichText::new(format!("{max_temp:.0} °C")).small().strong())
.desired_width(SIZE.x / 2.0 - 5.0)
.colored_dot(Some(auto_color(3))),
.fill(auto_color_dark(3)),
);
});

Expand All @@ -449,7 +449,7 @@ fn show_cpu(appdata: &mut MyApp, ui: &mut Ui) {
.small()
.strong(),
)
.colored_dot(Some(auto_color(1))),
.fill(auto_color_dark(1)),
);
let power = appdata.cpu_power_buffer.read();
let current_power = power.last().copied().unwrap_or_default();
Expand All @@ -462,7 +462,7 @@ fn show_cpu(appdata: &mut MyApp, ui: &mut Ui) {
.small()
.strong(),
)
.colored_dot(Some(auto_color(2))),
.fill(auto_color_dark(2)),
);

Grid::new("cpu_grid_cores")
Expand Down Expand Up @@ -545,7 +545,7 @@ fn show_gpu(appdata: &MyApp, ui: &mut Ui) {
.strong(),
)
.desired_width(SIZE.x / 2.0 - 5.0)
.colored_dot(Some(auto_color(0))),
.fill(auto_color_dark(0)),
);
ui.add(
EdgyProgressBar::new(appdata.gpu.as_ref().unwrap().temperature / 100.0)
Expand All @@ -558,7 +558,7 @@ fn show_gpu(appdata: &MyApp, ui: &mut Ui) {
.strong(),
)
.desired_width(SIZE.x / 2.0 - 5.0)
.colored_dot(Some(auto_color(3))),
.fill(auto_color_dark(3)),
);
});

Expand All @@ -576,7 +576,7 @@ fn show_gpu(appdata: &MyApp, ui: &mut Ui) {
.small()
.strong(),
)
.colored_dot(Some(auto_color(1))),
.fill(auto_color_dark(1)),
);

ui.add(
Expand All @@ -593,7 +593,7 @@ fn show_gpu(appdata: &MyApp, ui: &mut Ui) {
.small()
.strong(),
)
.colored_dot(Some(auto_color(2))),
.fill(auto_color_dark(2)),
);
ui.add(
EdgyProgressBar::new(
Expand All @@ -611,28 +611,6 @@ fn show_gpu(appdata: &MyApp, ui: &mut Ui) {
),
);

ui.push_id("gpu table", |ui| {
let table = TableBuilder::new(ui)
.striped(true)
.columns(Column::exact((SIZE.x * 0.5) - 9.5), 2);

table.body(|mut body| {
body.row(12.0, |mut row| {
// Clock
row.col(|ui| {
ui.label(
RichText::new(format!(
"{:.0} MHz",
appdata.gpu.as_ref().unwrap().clock_mhz
))
.small()
.strong(),
);
});
});
});
});

let gpu_buf = appdata.gpu_buffer.read();
let gpu_line = Line::new(
(0..appdata.gpu_buffer.capacity())
Expand Down Expand Up @@ -886,7 +864,7 @@ fn show_drives(appdata: &MyApp, ui: &mut Ui) {
(d.total_space() - d.available_space()) as f32 / d.total_space() as f32,
)
.desired_width(
appdata.settings.lock().current_settings.location.width as f32 * 0.5,
appdata.settings.lock().current_settings.location.width as f32 * 0.55,
)
.text(
RichText::new(format!(
Expand All @@ -895,11 +873,9 @@ fn show_drives(appdata: &MyApp, ui: &mut Ui) {
))
.small()
.strong(),
),
)
.fill(auto_color_dark(i as i32)),
);
ui.add(Label::new(
RichText::new("⏺").size(8.0).color(auto_color(i as i32)),
));
});
ui.end_row();
}
Expand Down Expand Up @@ -965,7 +941,10 @@ pub fn init_system(appdata: &mut MyApp) {
unsafe { PdhCollectQueryData(appdata.windows_performance_query_handle) };
}

pub fn get_windows_glass_color() -> Color32 {
pub fn get_windows_glass_color(use_plain_blackground: bool) -> Color32 {
if use_plain_blackground {
return get_base_background();
}
let mut col: u32 = 0;
let mut opaque: BOOL = BOOL(0);
unsafe {
Expand Down Expand Up @@ -1045,10 +1024,16 @@ fn refresh_processes(appdata: &mut MyApp) {
appdata.processes = get_pdh_process_data(&appdata.process_metric_handles);
}

pub fn refresh_color(ui: &mut Ui) {
pub fn refresh_color(appdata: &mut MyApp, ui: &mut Ui) {
let v = ui.visuals_mut();
v.override_text_color = Some(Color32::from_gray(250));
v.window_fill = get_windows_glass_color();
v.window_fill = get_windows_glass_color(
appdata
.settings
.lock()
.current_settings
.use_plain_dark_background,
);
}

pub struct MyNetworkData {
Expand Down Expand Up @@ -1098,7 +1083,7 @@ fn refresh_system_memory(appdata: &mut MyApp) {
.unwrap()
.replace(',', ".")
.parse::<f32>()
.unwrap()
.unwrap_or_default()
* 1024.0
* 1024.0
* 1024.0;
Expand All @@ -1114,7 +1099,7 @@ fn refresh_system_memory(appdata: &mut MyApp) {
.unwrap()
.replace(',', ".")
.parse::<f32>()
.unwrap()
.unwrap_or_default()
* 1024.0
* 1024.0
* 1024.0;
Expand Down

0 comments on commit f0bb167

Please sign in to comment.