[lab3] Visualization panel stub
This commit is contained in:
parent
c0f03fd71a
commit
f7d95b6e98
@ -55,6 +55,7 @@ impl<T> _PreserveIndexVec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item=&T>{
|
||||
return self.buffer.iter().filter_map(|c| {
|
||||
match c {
|
||||
@ -64,6 +65,15 @@ impl<T> _PreserveIndexVec<T> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item=&mut T>{
|
||||
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<Item=(usize, &T)>{
|
||||
return self.buffer.iter().enumerate().filter_map(|(i, c)| {
|
||||
match c {
|
||||
|
||||
@ -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<Item=&Edge>{
|
||||
return self.data.iter()
|
||||
}
|
||||
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item=&mut Edge>{
|
||||
return self.data.iter_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<usize> for EdgesVec {
|
||||
|
||||
@ -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<T: Numeric>(
|
||||
|
||||
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) {
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user