hai/src/gui.rs

64 lines
1.8 KiB
Rust
Raw Normal View History

2025-02-19 00:08:36 +01:00
/*
* SPDX-FileCopyrightText: 2025 April Faye John <april.john@denic.de> & Contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
use egui::{TextureOptions, Vec2};
pub fn gui_main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([600.0, 540.0]),
..Default::default()
};
eframe::run_native(
"Hai VPN",
options,
Box::new(|cc| {
// This gives us image support:
egui_extras::install_image_loaders(&cc.egui_ctx);
Ok(Box::<MyApp>::default())
}),
)
}
struct MyApp {
name: String,
age: u32,
}
impl Default for MyApp {
fn default() -> Self {
Self {
name: "Arthur".to_owned(),
age: 42,
}
}
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("Hai VPN Test");
ui.horizontal(|ui| {
let name_label = ui.label("Your name: ");
ui.text_edit_singleline(&mut self.name)
.labelled_by(name_label.id);
});
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Increment").clicked() {
self.age += 1;
}
ui.label(format!("Hello '{}', age {}", self.name, self.age));
ui.add(
egui::Image::new(egui::include_image!("../rosenpass-darkogo.svg"))
.max_size(Vec2::new(1000., 1000.))
.maintain_aspect_ratio(true)
.texture_options(TextureOptions::NEAREST)
.corner_radius(4.0)
.fit_to_fraction(Vec2::new(0.5, 0.5)),
);
});
}
}