Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
sor-ca committed Aug 23, 2024
1 parent 22f93bd commit 6c58bad
Showing 1 changed file with 0 additions and 71 deletions.
71 changes: 0 additions & 71 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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)]
#[serde(default)] // if we add new fields, give them default values when deserializing old state
pub struct TemplateApp {
time: Time,
hour_arrow_pos: Option<f32>,
//minute_arrow_pos: Option<Pos2>,
minute_arrow_pos: Option<f32>,
change_hour: Hour,
prev_raw_minute: Option<i32>,
Expand Down Expand Up @@ -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,
Expand All @@ -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)]
Expand All @@ -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();

Expand Down Expand Up @@ -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}")),
);

Expand All @@ -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}")),
);
});
Expand All @@ -211,24 +150,16 @@ 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);
// инициализированы переменные предыдущего значения времени
// и значение тянущейся переменной минут
if raw_minute.abs_diff(prev_raw_minute) < 30 {
// изменение времени за тик больше 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)");
}
}
}
Expand Down Expand Up @@ -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)");
}
}
}
Expand Down

0 comments on commit 6c58bad

Please sign in to comment.