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 29, 2023
1 parent ad562d8 commit 1079ea7
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 135 deletions.
122 changes: 10 additions & 112 deletions app/Cargo.lock

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

7 changes: 1 addition & 6 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,22 @@ 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 = "0.6.0"
env_logger = "0.8.4"
futures = "0.3"
geocoding = "0.2.0"
human-repr = "1.1.0"
image = "0.24.7"
itertools = "0.11.0"
lazy_static = "1.4.0"
log = "0.4.14"
maplit = "1.0.2"
png = "0.17.10"
pollster = "0.3.0"
rust-embed = "5.5.1"
serde = { version = "1.0.110", features = ["derive"] }
serde_json = "1.0.104"
simplelog = "0.12.1"
sunrise-sunset-calculator = "1.0.1"
tempfile = "3.7.0"
thiserror = "1.0"
toml = "0.5"
tray-icon = "0.8.3"
tray-icon = "0.9.0"
validator = { version = "0.16.1", features = ["derive"] }
wildmatch = "2.1.1"

Expand Down
5 changes: 0 additions & 5 deletions app/src/assets.rs

This file was deleted.

2 changes: 2 additions & 0 deletions app/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub enum UserEvent {
OpenWindow,
// When the tray exit button is clicked - the application should exit
Exit,
// Hide the window if it is open
CloseWindow,
RequestRepaint {
when: Instant,
/// What the frame number was when the repaint was _requested_.
Expand Down
94 changes: 92 additions & 2 deletions app/src/gui/app.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,109 @@
use crate::common::UserEvent;
use egui::{Align, Color32, Layout, ScrollArea};
use egui_winit::winit::event_loop::EventLoopProxy;

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

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

enum OverlayWindow {
ExitModal,
}

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

pub fn update(&mut self, ctx: &egui::Context) {
self.render_overlay(ctx);

egui::SidePanel::left("Menu")
.resizable(false)
.show(ctx, |ui| {
ui.set_enabled(self.overlay.is_none());
self.render_menu_panel(ui);
});
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));
});
}

fn render_overlay(&mut self, ctx: &egui::Context) {
match &self.overlay {
Some(OverlayWindow::ExitModal) => {
egui::Window::new("Are you sure?")
.collapsible(false)
.resizable(true)
.show(ctx, |ui| {
ui.label("Exiting the application will stop the brightness being automatically updated");
ui.with_layout(Layout::left_to_right(Align::LEFT), |ui| {
if ui.button("Exit").clicked() {
self.main_loop.send_event(UserEvent::Exit).unwrap();
}
if ui.button("Cancel").clicked() {
self.overlay = None;
};
});
});
}
None => {}
}
}

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");

ui.separator();

if ui
.add(egui::Button::new("Close Window").fill(Color32::TRANSPARENT))
.clicked()
{
self.main_loop.send_event(UserEvent::CloseWindow).unwrap();
}

if ui
.add(egui::Button::new("Exit Application").fill(Color32::TRANSPARENT))
.clicked()
{
self.overlay = Some(OverlayWindow::ExitModal);
}
});
});
}
}
Loading

0 comments on commit 1079ea7

Please sign in to comment.