-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
135 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.