generated from luke-else/egui-template
Moved UI elements back onto the main window. Made panels return Networking error types
This commit is contained in:
parent
2170c7872e
commit
027173da15
@ -3,7 +3,8 @@ mod ui;
|
||||
/// Stuct to store the state of the running application
|
||||
pub struct App {
|
||||
name: String,
|
||||
ip: String
|
||||
ip: String,
|
||||
cidr: String
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
@ -11,7 +12,8 @@ impl Default for App {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: String::from("Hello, World!"),
|
||||
ip: String::from("127.0.0.1")
|
||||
ip: String::from("127.0.0.1"),
|
||||
cidr: String::from("24")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use std::str::FromStr;
|
||||
use crate::app::App;
|
||||
use crate::theme::onedark::ONE_DARK;
|
||||
|
||||
use subnet_calculator::{Network, ip::IpAddr};
|
||||
use subnet_calculator::{Network, ip::IpAddr, NetworkingErr};
|
||||
|
||||
impl eframe::App for App {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
@ -11,23 +11,24 @@ impl eframe::App for App {
|
||||
|
||||
egui::CentralPanel::default()
|
||||
.frame(background_frame)
|
||||
.show(ctx, |ui| {
|
||||
.show(ctx, |_| {
|
||||
egui::SidePanel::left("my_panel").show(ctx, |ui| {
|
||||
ui.heading(&self.name);
|
||||
});
|
||||
|
||||
egui::Window::new("test window")
|
||||
.collapsible(false)
|
||||
.auto_sized()
|
||||
.show(ctx, |ui| {
|
||||
egui::CentralPanel::default().show(ctx, |ui| -> Result<(), NetworkingErr>{
|
||||
ui.heading(&self.name);
|
||||
|
||||
ui.text_edit_singleline(&mut self.ip);
|
||||
Network::create_subnet(&IpAddr::from_str(self.ip.as_str()).unwrap(), 24).unwrap();
|
||||
ui.text_edit_singleline(&mut self.cidr);
|
||||
|
||||
for _ in 0..10 {
|
||||
ui.add(egui::Button::new(&self.name));
|
||||
}
|
||||
}
|
||||
);
|
||||
if ui.button(String::from("Calculate Subnet")).clicked() {
|
||||
let ip_addr: IpAddr = IpAddr::from_str(self.ip.as_str())?;
|
||||
let cidr: u8 = u8::from_str(self.cidr.as_str()).unwrap_or(24);
|
||||
println!("{:?}", Network::create_subnet(&ip_addr, cidr)?);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user