diff --git a/lab3/src/algo/_preserve_index_vec.rs b/lab3/src/algo/_preserve_index_vec.rs index 41631eb..b17401b 100644 --- a/lab3/src/algo/_preserve_index_vec.rs +++ b/lab3/src/algo/_preserve_index_vec.rs @@ -55,6 +55,7 @@ impl _PreserveIndexVec { } } + pub fn iter(&self) -> impl Iterator{ return self.buffer.iter().filter_map(|c| { match c { @@ -64,6 +65,15 @@ impl _PreserveIndexVec { }) } + pub fn iter_mut(&mut self) -> impl Iterator{ + return self.buffer.iter_mut().filter_map(|c| { + match c { + Cell::Free { .. } => return None, + Cell::Value { value } => return Some(value) + } + }) + } + pub fn iter_indexed(&self) -> impl Iterator{ return self.buffer.iter().enumerate().filter_map(|(i, c)| { match c { diff --git a/lab3/src/algo/edges.rs b/lab3/src/algo/edges.rs index 3039d53..108b606 100644 --- a/lab3/src/algo/edges.rs +++ b/lab3/src/algo/edges.rs @@ -44,6 +44,13 @@ impl EdgesVec { pub fn remove(&mut self, edge_index: usize) { self.data.remove(edge_index) } + pub fn iter(&self) -> impl Iterator{ + return self.data.iter() + } + + pub fn iter_mut(&mut self) -> impl Iterator{ + return self.data.iter_mut() + } } impl Index for EdgesVec { diff --git a/lab3/src/main.rs b/lab3/src/main.rs index 60af373..c15b77e 100644 --- a/lab3/src/main.rs +++ b/lab3/src/main.rs @@ -4,14 +4,12 @@ mod algo; use crate::algo::{AntsSimulationConfig, EdgesVec, VerticesVec}; use eframe::egui; -use eframe::egui::scroll_area::ScrollBarVisibility; -use eframe::egui::{ScrollArea, Ui}; +use eframe::egui::{Frame, ScrollArea, Ui}; use eframe::emath::Numeric; use egui_extras::{Column, TableBuilder}; -use std::collections::{HashMap, HashSet}; +use std::collections::HashSet; use std::ops::RangeInclusive; -use std::ptr; -use std::ptr::{NonNull, fn_addr_eq}; +use std::ptr::NonNull; fn main() -> eframe::Result { let options = eframe::NativeOptions { @@ -89,9 +87,9 @@ fn _slider( impl eframe::App for MyApp { fn update(&mut self, ui: &eframe::egui::Context, _frame: &mut eframe::Frame) { - egui::CentralPanel::default().show(ui, |ui| { - match self.state { - GlobalState::Edit {} => match self.vertex_update { + egui::CentralPanel::default().show(ui, |ui| match self.state { + GlobalState::Edit {} => { + match self.vertex_update { UpdatePending::NoChange => {} UpdatePending::Add => { let new_vi = self.vertices.add(HashSet::new()); @@ -119,10 +117,24 @@ impl eframe::App for MyApp { self.vertices.remove(vi); self.vertex_update = UpdatePending::NoChange; } - }, - GlobalState::Running { .. } => {} + } + edit_panel(self, ui) + } + GlobalState::Running { .. } => { + ui.add_enabled_ui(false, |ui| edit_panel(self, ui)); + ui.ctx().show_viewport_immediate( + egui::ViewportId::from_hash_of("Visualisation"), + egui::ViewportBuilder::default() + .with_title("Visualisation") + .with_inner_size([640.0, 480.0]) + .with_resizable(false), + |ui, _| { + egui::CentralPanel::default() + .frame(Frame::default().inner_margin(0.0)) + .show(ui, |ui| visualization_panel(self, ui)); + }, + ); } - edit_panel(self, ui) }); } } @@ -225,3 +237,17 @@ fn edit_panel(data: &mut MyApp, ui: &mut Ui) { }); }); } + +fn visualization_panel(data: &mut MyApp, ui: &mut Ui) { + ui.horizontal(|ui| { + if ui.button("Exit").clicked() {} + + if ui.button("Pause").clicked() {} + ui.label(""); + _slider(ui, "Ant speed", &mut data.speed, 1..=10, 1.0); + }); + +} + +fn draw_ants(data: &mut MyApp, ui: &mut Ui) { +}