From 6c58bad87acc165fee85f3b8f353e469f4596774 Mon Sep 17 00:00:00 2001 From: sor-ca Date: Fri, 23 Aug 2024 16:24:30 +0300 Subject: [PATCH] cosmetics --- src/app.rs | 71 ------------------------------------------------------ 1 file changed, 71 deletions(-) diff --git a/src/app.rs b/src/app.rs index 69ae140..f44b1a1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,5 @@ use egui::{vec2, Color32, Painter, Pos2, Sense, Stroke, Vec2}; use std::f32::consts::TAU; -use std::ops::RangeInclusive; use time::{OffsetDateTime, Time}; #[derive(serde::Deserialize, serde::Serialize)] @@ -8,7 +7,6 @@ use time::{OffsetDateTime, Time}; pub struct TemplateApp { time: Time, hour_arrow_pos: Option, - //minute_arrow_pos: Option, minute_arrow_pos: Option, change_hour: Hour, prev_raw_minute: Option, @@ -45,11 +43,9 @@ impl TemplateApp { for n in 0..60 { let r_end = c + r * Vec2::angled(TAU * n as f32 / 60.0); let r_start = if n % 5 == 0 { - // TODO: так тоже не надо делать - эти вычисления не касаются иниуциализации переменной r_start let h_text_pos = c + r * 1.1 * Vec2::angled(TAU * n as f32 / 60.0); let h = (n / 5 + 2) % 12 + 1; - // TODO: вот вообще плохо так делать - ты рисуешь текст в блоке присвоения значения переменной painter.text( h_text_pos, egui::Align2::CENTER_CENTER, @@ -75,57 +71,6 @@ impl TemplateApp { ); } } - - /*fn draw_minute_arrow( - &mut self, - ui: &mut Ui, - painter: &Painter, - c: Pos2, - r: f32, - mut minute: i8) -> (Hour, i8) { - - let mut m_angle = TAU * minute as f32 / 60.0 - TAU / 4.; - let m_rect = egui::Rect::from_center_size( c + r * 0.8 * Vec2::angled(m_angle), vec2(10., 10.)); - let mut change_hour = Hour::Same; - - if let Some(angle) = self.minute_arrow_pos { - m_angle = angle; - let mut new_minute = ((m_angle + TAU / 4.) * 60. / TAU).floor() as i8; - dbg!(new_minute); - if new_minute == 60 { - new_minute = 0; - } - if new_minute == 0 { - if minute <= 59 && minute >= 55 { - change_hour = Hour::Next; - } else if minute >= 1 && minute <= 5 { - change_hour = Hour::Previous; - } - } - minute = new_minute as i8; - } - - let m_arrow_stroke = Stroke::new(5., Color32::BLACK); - painter.line_segment([c, c + r * 0.8 * Vec2::angled(m_angle)], m_arrow_stroke); - - let m_arrow_resp = ui.allocate_rect(m_rect, Sense::drag()); - - if m_arrow_resp.hovered() { - painter.rect_stroke(m_rect, 0., Stroke::new(5., Color32::BLUE)); - } - - if m_arrow_resp.dragged() { - let pos = m_rect.center() + m_arrow_resp.drag_delta(); - let mut angle = (pos - c).angle(); - if angle < - TAU / 4. { - angle = TAU + angle; - } - self.minute_arrow_pos = Some(angle); - } else { - self.minute_arrow_pos = None; - } - (change_hour, minute) - }*/ } #[derive(Debug, serde::Deserialize, serde::Serialize)] @@ -136,15 +81,11 @@ enum Hour { } impl eframe::App for TemplateApp { - /// Called by the frame work to save state before shutdown. fn save(&mut self, storage: &mut dyn eframe::Storage) { eframe::set_value(storage, eframe::APP_KEY, self); } - /// Called each time the UI needs repainting, which may be many times per second. - /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - //let Self { time, hour_arrow_pos, minute_arrow_pos } = self; let width = ctx.screen_rect().width(); let height = ctx.screen_rect().height(); @@ -177,7 +118,6 @@ impl eframe::App for TemplateApp { size, egui::DragValue::new(&mut raw_hour) .speed(0.1) - //.clamp_range(0..=24) .custom_formatter(|h, _| format!("{h:02}")), ); @@ -187,7 +127,6 @@ impl eframe::App for TemplateApp { size, egui::DragValue::new(&mut raw_minute) .speed(0.1) - //.clamp_range(-1..=60) .custom_formatter(|m, _| format!("{m:02}")), ); }); @@ -211,12 +150,6 @@ impl eframe::App for TemplateApp { let mut prev_norm_minute = prev_raw_minute.rem_euclid(60); if prev_norm_minute != norm_minute { - //dbg!(prev_norm_minute != norm_minute); - //dbg!(prev_norm_minute); - //dbg!(norm_minute); - // dbg!(prev_raw_minute); - // dbg!(raw_minute); - // dbg!(prev_raw_minute - raw_minute); self.prev_raw_minute = Some(raw_minute); // инициализированы переменные предыдущего значения времени // и значение тянущейся переменной минут @@ -224,11 +157,9 @@ impl eframe::App for TemplateApp { // изменение времени за тик больше 30 секунд if raw_minute < prev_raw_minute && norm_minute > prev_norm_minute { norm_hour = (norm_hour - 1).rem_euclid(24); - //dbg!("inc hour (slider)"); } if raw_minute > prev_raw_minute && norm_minute < prev_norm_minute { norm_hour = (norm_hour + 1).rem_euclid(24); - //dbg!("dec hour (slider)"); } } } @@ -302,11 +233,9 @@ impl eframe::App for TemplateApp { // изменение времени за тик больше 30 секунд if norm_minute > prev_norm_minute { norm_hour = (norm_hour - 1).rem_euclid(24); - //dbg!("dec hour (dragged)"); } if norm_minute < prev_norm_minute { norm_hour = (norm_hour + 1).rem_euclid(24); - //dbg!("inc hour (dragged)"); } } }