53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
|
use custom_consumption::app_config::AppConfig;
|
||
|
|
||
|
fn main() {
|
||
|
env_logger::init();
|
||
|
|
||
|
let options = eframe::NativeOptions {
|
||
|
viewport: egui::ViewportBuilder::default().with_inner_size([220.0, 60.0]),
|
||
|
..Default::default()
|
||
|
};
|
||
|
eframe::run_native(
|
||
|
"Custom consumption",
|
||
|
options,
|
||
|
Box::new(|_cc| Box::<MyApp>::default()),
|
||
|
)
|
||
|
.unwrap()
|
||
|
}
|
||
|
|
||
|
struct MyApp {
|
||
|
consumption: i64,
|
||
|
}
|
||
|
|
||
|
impl Default for MyApp {
|
||
|
fn default() -> Self {
|
||
|
let mut prev_consumption = 42;
|
||
|
|
||
|
if AppConfig::get().file_path().is_file() {
|
||
|
prev_consumption = std::fs::read_to_string(AppConfig::get().file_path())
|
||
|
.unwrap_or("43".to_string())
|
||
|
.parse()
|
||
|
.unwrap_or(44)
|
||
|
}
|
||
|
|
||
|
Self {
|
||
|
consumption: prev_consumption,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl eframe::App for MyApp {
|
||
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||
|
ui.heading("Custom consumption");
|
||
|
ui.add(
|
||
|
egui::Slider::new(
|
||
|
&mut self.consumption,
|
||
|
AppConfig::get().min..=AppConfig::get().max,
|
||
|
)
|
||
|
.text("W"),
|
||
|
);
|
||
|
});
|
||
|
}
|
||
|
}
|