71 lines
1.6 KiB
Rust
71 lines
1.6 KiB
Rust
use cheapsdo_protocol::Multisynth;
|
|
use eframe::egui::{self, RichText};
|
|
|
|
use crate::formatters;
|
|
|
|
pub fn frequency_input(
|
|
id: egui::Id,
|
|
freq: &mut u32,
|
|
ctx: &egui::Context,
|
|
ui: &mut egui::Ui,
|
|
) -> egui::Response {
|
|
let has_focus = ctx.memory(|m| m.has_focus(id));
|
|
|
|
let mut tmp = if has_focus {
|
|
freq.to_string()
|
|
} else {
|
|
formatters::format_frequency(*freq as f64)
|
|
};
|
|
let resp = ui.add_sized(
|
|
[100.0, 20.0],
|
|
egui::TextEdit::singleline(&mut tmp)
|
|
.id(id)
|
|
.horizontal_align(egui::Align::Max),
|
|
);
|
|
if has_focus {
|
|
if let Ok(val) = tmp.parse::<u32>() {
|
|
*freq = val;
|
|
}
|
|
}
|
|
|
|
resp
|
|
}
|
|
|
|
pub fn multisynth_selector(
|
|
selected_source: &mut Multisynth,
|
|
ui: &mut egui::Ui,
|
|
) -> egui::InnerResponse<()> {
|
|
ui.horizontal(|ui| {
|
|
ui.selectable_value(selected_source, Multisynth::MS1, "MS1");
|
|
ui.selectable_value(selected_source, Multisynth::MS2, "MS2");
|
|
})
|
|
}
|
|
|
|
pub fn on_off_toggle(toggle: &mut bool, ui: &mut egui::Ui) -> egui::InnerResponse<()> {
|
|
let on_text = if *toggle {
|
|
RichText::new("On").color(egui::Color32::GREEN)
|
|
} else {
|
|
RichText::new("On")
|
|
};
|
|
let off_text = if *toggle {
|
|
RichText::new("Off")
|
|
} else {
|
|
RichText::new("Off").color(egui::Color32::RED)
|
|
};
|
|
|
|
ui.horizontal(|ui| {
|
|
if ui
|
|
.add_enabled(!*toggle, egui::Button::new(on_text))
|
|
.clicked()
|
|
{
|
|
*toggle = true;
|
|
}
|
|
if ui
|
|
.add_enabled(*toggle, egui::Button::new(off_text))
|
|
.clicked()
|
|
{
|
|
*toggle = false;
|
|
}
|
|
})
|
|
}
|