Moved UI elements back onto the main window. Made panels return Networking error types

This commit is contained in:
Luke Else 2023-07-06 22:17:25 +01:00
parent 2170c7872e
commit 027173da15
2 changed files with 21 additions and 18 deletions

View File

@ -3,7 +3,8 @@ mod ui;
/// Stuct to store the state of the running application /// Stuct to store the state of the running application
pub struct App { pub struct App {
name: String, name: String,
ip: String ip: String,
cidr: String
} }
impl Default for App { impl Default for App {
@ -11,7 +12,8 @@ impl Default for App {
fn default() -> Self { fn default() -> Self {
Self { Self {
name: String::from("Hello, World!"), name: String::from("Hello, World!"),
ip: String::from("127.0.0.1") ip: String::from("127.0.0.1"),
cidr: String::from("24")
} }
} }
} }

View File

@ -3,7 +3,7 @@ use std::str::FromStr;
use crate::app::App; use crate::app::App;
use crate::theme::onedark::ONE_DARK; use crate::theme::onedark::ONE_DARK;
use subnet_calculator::{Network, ip::IpAddr}; use subnet_calculator::{Network, ip::IpAddr, NetworkingErr};
impl eframe::App for App { impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
@ -11,23 +11,24 @@ impl eframe::App for App {
egui::CentralPanel::default() egui::CentralPanel::default()
.frame(background_frame) .frame(background_frame)
.show(ctx, |ui| { .show(ctx, |_| {
ui.heading(&self.name); egui::SidePanel::left("my_panel").show(ctx, |ui| {
});
egui::Window::new("test window")
.collapsible(false)
.auto_sized()
.show(ctx, |ui| {
ui.heading(&self.name); ui.heading(&self.name);
});
ui.text_edit_singleline(&mut self.ip);
Network::create_subnet(&IpAddr::from_str(self.ip.as_str()).unwrap(), 24).unwrap();
for _ in 0..10 { egui::CentralPanel::default().show(ctx, |ui| -> Result<(), NetworkingErr>{
ui.add(egui::Button::new(&self.name)); ui.heading(&self.name);
ui.text_edit_singleline(&mut self.ip);
ui.text_edit_singleline(&mut self.cidr);
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(())
});
});
} }
} }