Newer
Older
use crate::Slide;
use eframe::egui::text_edit::{CCursorRange, TextEditState};
use eframe::egui::{Align2, Frame, TextEdit, Vec2, Widget};
pub struct Complexity {
state: ComplexityState,
last_time: f64,
}
/// What state we are in, with respect to the action of selecting "Complex" and replacing it
/// with "Simple."
// Width was determined anecdotally. Height is arbitrary.
let time = ui.input().time;
let time_delta = (time - self.last_time).min(1.0);
let made_progress = time_delta > 0.1;
if made_progress {
self.last_time = time;
}
ui.vertical_centered_justified(|ui| {
let mut state = TextEditState::default();
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
let text;
match &mut self.state {
ComplexityState::Before => {
text = String::from("Complex Rules ➡ Complex Results?");
}
ComplexityState::Selecting(progress) => {
text = String::from("Complex Rules ➡ Complex Results?");
state.set_ccursor_range(Some(CCursorRange::two(
CCursor::new(0),
CCursor::new(*progress),
)));
if made_progress {
if *progress == "Complex".len() {
self.state = ComplexityState::Typing(0);
} else {
*progress += 1;
}
}
}
ComplexityState::Typing(progress) => {
text = format!(" {} Rules ➡ Complex Results?", &"Simple"[0..*progress]);
if made_progress {
if *progress == "Simple".len() {
self.state = ComplexityState::After;
} else {
*progress += 1;
}
}
}
ComplexityState::After => {
text = String::from(" Simple Rules ➡ Complex Results!");
}
}
let text_edit = TextEdit::singleline(&mut text.as_str())
.desired_width(f32::INFINITY)
.ui(ui);
TextEdit::store_state(ui.ctx(), text_edit.id, state);