use eframe::egui;
use egui_widget_ext::toggle_switch;
struct ToggleSwitchApp {
is_on: bool,
}
impl ToggleSwitchApp {
fn new(_cc: &eframe::CreationContext<'_>) -> Self {
Self { is_on: false }
}
}
impl eframe::App for ToggleSwitchApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.horizontal(|ui| {
ui.add(toggle_switch(&mut self.is_on));
let label = if self.is_on {
"The switch is ON"
} else {
"The switch is OFF"
};
ui.label(label);
});
});
}
}
fn main() -> eframe::Result<()> {
let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_maximized(true),
..Default::default()
};
eframe::run_native(
"Toggle Switch Demo",
native_options,
Box::new(|cc| Ok(Box::new(ToggleSwitchApp::new(cc)))),
)
}