Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bircni committed Jun 7, 2024
1 parent 5089a60 commit 6a55445
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/ui/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Device {
self.toasts.show(ui.ctx());
}

/*
fn power(&mut self, ui: &mut Ui, ip: &str) {
fn handle_power_result(result: &anyhow::Result<()>, toasts: &mut Toasts, power: &str) {
match result {
Expand Down Expand Up @@ -92,6 +93,7 @@ impl Device {
.then_some(())
.context("Failed to set power")
}
*/

fn sleep(&mut self, ui: &mut Ui, ip: &str) {
ui.horizontal(|ui| {
Expand Down
17 changes: 9 additions & 8 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use eframe::CreationContext;
use egui::{
vec2, CentralPanel, Color32, ColorImage, Context, ImageData, ScrollArea, TextStyle,
TextureOptions,
vec2, CentralPanel, Color32, ColorImage, Context, ImageData, TextStyle, TextureOptions,
};
use egui_notify::Toasts;
use parking_lot::RwLock;
use status::Stat;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

use crate::config::Config;
Expand Down Expand Up @@ -75,8 +73,13 @@ impl App {
impl eframe::App for App {
fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
CentralPanel::default().show(ctx, |ui| {
self.statusbar
.show(ui, &mut self.current_tab, &mut self.config);
match self
.statusbar
.show(ui, &mut self.current_tab, &mut self.config)
{
Ok(()) => self.toasts.success("Config saved!"),
Err(e) => self.toasts.error(e.to_string()),
};
ui.vertical_centered(|ui| {
ui.separator();
});
Expand All @@ -95,9 +98,7 @@ impl eframe::App for App {
Tab::Settings => self.settings.show(ui, ip),
}
.unwrap_or_else(|e| {
self.toasts
.error(e.to_string())
.set_duration(Some(std::time::Duration::from_secs(5)));
self.toasts.error(e.to_string());
});
}
});
Expand Down
2 changes: 0 additions & 2 deletions src/ui/settings.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::time::Duration;

use anyhow::Context;
use egui::{Align, Button, Layout, ScrollArea, TextEdit, TextStyle, Ui};
use egui_extras::syntax_highlighting;
use egui_notify::Toasts;
use reqwest::blocking::{get, Client};

pub struct Settings {
Expand Down
63 changes: 33 additions & 30 deletions src/ui/statusbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,51 @@ use egui::{
include_image, special_emojis::GITHUB, vec2, Align, Align2, Button, Frame, Image, Layout,
TextEdit, Ui, Window,
};
use egui_notify::Toasts;

use super::Tab;

pub struct StatusBar {
show_about: bool,
toasts: Toasts,
}

impl StatusBar {
pub fn new() -> Self {
Self {
show_about: false,
toasts: Toasts::new().with_anchor(egui_notify::Anchor::BottomLeft),
}
Self { show_about: false }
}

pub fn show(&mut self, ui: &mut Ui, tab: &mut Tab, config: &mut Config) {
ui.horizontal(|ui| {
ui.add_enabled_ui(!config.ip.is_empty(), |ui| {
ui.selectable_value(tab, Tab::Screen, "Screen");
ui.selectable_value(tab, Tab::Status, "Status");
ui.selectable_value(tab, Tab::Settings, "Settings");
});

ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
ui.add(Button::new(" ? ").rounding(40.0))
.clicked()
.then(|| self.show_about = true);
ui.add(Button::new("Save")).clicked().then(|| {
config.write().unwrap();
});
ui.add(
TextEdit::singleline(&mut config.ip)
.hint_text("IP")
.desired_width(150.0),
);
ui.label("IP:");
});
});
pub fn show(&mut self, ui: &mut Ui, tab: &mut Tab, config: &mut Config) -> anyhow::Result<()> {
self.about_window(ui);
self.toasts.show(ui.ctx());
return ui
.horizontal(|ui| {
ui.add_enabled_ui(!config.ip.is_empty(), |ui| {
ui.selectable_value(tab, Tab::Screen, "Screen");
ui.selectable_value(tab, Tab::Status, "Status");
ui.selectable_value(tab, Tab::Settings, "Settings");
});

ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
ui.add(Button::new(" ? ").rounding(40.0))
.clicked()
.then(|| self.show_about = true);
let ret = ui
.add(Button::new("Save"))
.clicked()
.then(|| match config.write() {
Ok(()) => anyhow::Ok(()),
Err(e) => anyhow::bail!(e),
})
.unwrap_or(Ok(()));
ui.add(
TextEdit::singleline(&mut config.ip)
.hint_text("IP")
.desired_width(150.0),
);
ui.label("IP:");
ret
})
.inner
})
.inner;
}

fn about_window(&mut self, ui: &mut Ui) {
Expand Down

0 comments on commit 6a55445

Please sign in to comment.