Skip to content

Commit

Permalink
ui progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-pro committed Dec 30, 2023
1 parent 1079ea7 commit beab98b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 31 deletions.
21 changes: 21 additions & 0 deletions app/Cargo.lock

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

1 change: 1 addition & 0 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dirs = "5.0.1"
egui = { version = "0.22.0" }
egui-wgpu = { version = "0.22.0", features = ["winit"] }
egui-winit = { version = "0.22.0" }
enum-iterator = "1.4.1"
geocoding = "0.2.0"
human-repr = "1.1.0"
image = "0.24.7"
Expand Down
7 changes: 1 addition & 6 deletions app/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ pub enum Message {
Enable,
Disable,
Refresh,
RegisterListener(mpsc::Sender<()>),
}

pub struct BrightnessController {
pub sender: mpsc::Sender<Message>,
last_result: Arc<RwLock<Option<ApplyResults>>>,
pub last_result: Arc<RwLock<Option<ApplyResults>>>,
join_handle: Option<JoinHandle<()>>,
}

Expand Down Expand Up @@ -53,7 +52,6 @@ fn run(
) {
log::info!("Starting BrightnessController");
let mut enabled = true;
let mut listeners = Vec::new();

loop {
// Apply brightness using latest config
Expand Down Expand Up @@ -98,9 +96,6 @@ fn run(
Ok(Message::Refresh) => {
log::info!("Refreshing due to signal");
}
Ok(Message::RegisterListener(listener)) => {
listeners.push(listener);
}
Err(RecvTimeoutError::Timeout) => {
log::debug!("Refreshing due to timeout")
}
Expand Down
62 changes: 41 additions & 21 deletions app/src/gui/app.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
use std::sync::{Arc, RwLock};
use crate::common::UserEvent;
use egui::{Align, Color32, Layout, ScrollArea};
use egui_winit::winit::event_loop::EventLoopProxy;
use enum_iterator::Sequence;
use crate::apply::ApplyResults;

pub struct SsbEguiApp {
main_loop: EventLoopProxy<UserEvent>,
age: u32,
selected_page: Page,
overlay: Option<OverlayWindow>,
results: Arc<RwLock<Option<ApplyResults>>>,
}

#[derive(Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Sequence)]
enum Page {
Status,
BrightnessSettings,
LocationSettings,
Monitors,
}

impl Page {

fn title(self) -> &'static str {
match self {
Page::Status => "Status",
Page::BrightnessSettings => "Brightness Settings",
Page::LocationSettings => "Location Settings",
Page::Monitors => "Monitors"
}
}
}

enum OverlayWindow {
ExitModal,
}

impl SsbEguiApp {
pub fn new(main_loop: EventLoopProxy<UserEvent>) -> Self {
pub fn new(main_loop: EventLoopProxy<UserEvent>, results: Arc<RwLock<Option<ApplyResults>>>) -> Self {
SsbEguiApp {
main_loop,
age: 0,
selected_page: Page::Status,
overlay: None,
results,
}
}

Expand All @@ -42,11 +57,7 @@ impl SsbEguiApp {
});
egui::CentralPanel::default().show(ctx, |ui| {
ui.set_enabled(self.overlay.is_none());
ui.heading("Hello World!");
if ui.button("Click each year").clicked() {
self.age += 1;
}
ui.label(format!("age {}", self.age));
self.render_main(ui);
});
}

Expand All @@ -72,21 +83,30 @@ impl SsbEguiApp {
}
}

fn render_main(&mut self, ui: &mut egui::Ui) {
ui.heading(self.selected_page.title());
match self.selected_page {
Page::Status => {
let results = self.results.read().unwrap();

if let Some(results) = results.as_ref() {
ui.label(format!("{} monitors", results.monitors.len()));
}

}
Page::BrightnessSettings => {}
Page::LocationSettings => {}
Page::Monitors => {}
}
}

fn render_menu_panel(&mut self, ui: &mut egui::Ui) {
ScrollArea::vertical().show(ui, |ui| {
ui.with_layout(egui::Layout::top_down_justified(egui::Align::LEFT), |ui| {
ui.selectable_value(&mut self.selected_page, Page::Status, "Status");
ui.selectable_value(
&mut self.selected_page,
Page::BrightnessSettings,
"Brightness Settings",
);
ui.selectable_value(
&mut self.selected_page,
Page::LocationSettings,
"Location Settings",
);
ui.selectable_value(&mut self.selected_page, Page::Monitors, "Monitors");

enum_iterator::all::<Page>().for_each(|page| {
ui.selectable_value(&mut self.selected_page, page, page.title());
});

ui.separator();

Expand Down
10 changes: 7 additions & 3 deletions app/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use egui_winit::winit;
use egui_winit::winit::event::{Event, WindowEvent};
use egui_winit::winit::event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget};
use egui_winit::winit::window::Icon;
use std::sync::{Arc, Mutex};
use std::sync::{Arc, Mutex, RwLock};
use std::time::Instant;
use crate::apply::ApplyResults;
use crate::controller::BrightnessController;

#[derive(Debug)]
pub enum NextPaint {
Expand Down Expand Up @@ -44,16 +46,18 @@ pub struct WgpuWinitApp {
repaint_proxy: EventLoopProxy<UserEvent>,
running: Option<WgpuWinitRunning>,
icon: Icon,
results: Arc<RwLock<Option<ApplyResults>>>
}

impl WgpuWinitApp {
pub fn new(event_loop: &EventLoop<UserEvent>) -> Self {
pub fn new(event_loop: &EventLoop<UserEvent>, controller: &BrightnessController) -> Self {
let (buf, info) = read_icon();
let icon = Icon::from_rgba(buf, info.width, info.height).unwrap();
Self {
repaint_proxy: event_loop.create_proxy(),
running: None,
icon,
results: controller.last_result.clone(),
}
}

Expand Down Expand Up @@ -110,7 +114,7 @@ impl WgpuWinitApp {

self.running = Some(WgpuWinitRunning {
painter,
app: SsbEguiApp::new(self.repaint_proxy.clone()),
app: SsbEguiApp::new(self.repaint_proxy.clone(), self.results.clone()),
window,
follow_system_theme: system_theme.is_some(),
egui_ctx,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn run() -> anyhow::Result<()> {
let _event_watcher = EventWatcher::start(&controller, Some(&event_loop));
let _tray = tray::create(&event_loop)?;

let mut framework = WgpuWinitApp::new(&event_loop);
let mut framework = WgpuWinitApp::new(&event_loop, &controller);

let mut returned_result = Ok(());
let mut next_repaint_time = Some(Instant::now());
Expand Down

0 comments on commit beab98b

Please sign in to comment.