Skip to content
This repository was archived by the owner on Nov 10, 2024. It is now read-only.

Commit 02a0abb

Browse files
committed
changes
- simulation now not only classic_simulation but also can be other simulations - ui code moved to having a original data for ui - next step is making simulation interaction or object collision.
1 parent 2148073 commit 02a0abb

File tree

15 files changed

+736
-593
lines changed

15 files changed

+736
-593
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ehttp = "0.2.0"
2525
# language
2626
tracing = "0.1.37"
2727
anyhow = "1.0.69"
28+
paste = "1.0.12"
2829

2930
# math
3031
nalgebra = "0.32.1"

src/app.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ use egui::plot::{GridInput, GridMark, Legend, Plot};
22
use egui::{ScrollArea, Slider, Widget};
33
use nalgebra::Vector2;
44

5-
6-
7-
85
use crate::app::audio::player::MusicPlayer;
96
use crate::app::graphics::image::ImageManager;
107
use crate::app::manager::SimulationManager;
11-
use crate::app::simulations::classic_simulation::state::update_simulation_state;
128
use crate::app::simulations::classic_simulation::template::get_sim_list;
139
use crate::app::util::FrameHistory;
1410

11+
1512
mod audio;
1613
mod graphics;
1714
mod io;
@@ -201,29 +198,6 @@ impl eframe::App for State {
201198
});
202199
});
203200

204-
ui.separator();
205-
ui.collapsing("Drawing Filter", |ui| {
206-
ui.checkbox(&mut self.simulation_manager.settings_mut().text, "text");
207-
ui.checkbox(
208-
&mut self.simulation_manager.settings_mut().acceleration,
209-
"acceleration",
210-
);
211-
ui.checkbox(
212-
&mut self.simulation_manager.settings_mut().velocity,
213-
"velocity",
214-
);
215-
ui.checkbox(
216-
&mut self.simulation_manager.settings_mut().sigma_force,
217-
"sigma_force",
218-
);
219-
ui.checkbox(&mut self.simulation_manager.settings_mut().trace, "trace");
220-
ui.checkbox(
221-
&mut self.simulation_manager.settings_mut().equation,
222-
"equation",
223-
);
224-
ui.checkbox(&mut self.simulation_manager.settings_mut().stamp, "stamp");
225-
});
226-
227201
ui.separator();
228202

229203
ui.label(format!("fps : {:.0?}", self.frame_history.fps()));
@@ -369,7 +343,7 @@ impl eframe::App for State {
369343
}
370344

371345
let response = plot.show(ui, |plot_ui| {
372-
update_simulation_state(state, plot_ui);
346+
state.update_simulation_state(plot_ui);
373347
simulation_plot.draw(simulation, plot_ui, state);
374348

375349
plot_ui.pointer_coordinate()

src/app/graphics/define.rs

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::fmt::{Debug, Formatter};
1+
use std::fmt::{Debug};
22

33
use eframe::epaint::Color32;
4-
use egui::plot::{Arrows, Line, PlotImage, PlotUi, Polygon, Text};
4+
use egui::plot::{Arrows, Line, PlotImage, PlotUi, Points, Polygon, Text};
55

66
pub mod items;
77

@@ -55,48 +55,82 @@ impl PlotTextSize {
5555
}
5656
}
5757

58-
pub enum PlotDrawItem {
59-
Polygon(Polygon),
60-
Arrows(Arrows), // Arrows with debug text
61-
Line(Line),
62-
Text(Text),
63-
Image(PlotImage),
58+
pub type BoxedPlotDraw = Box<dyn PlotDraw>;
59+
60+
pub trait PlotDraw {
61+
fn draw(self: Box<Self>, plot_ui: &mut PlotUi);
6462
}
6563

66-
unsafe impl Send for PlotDrawItem {}
64+
impl PlotDraw for Points {
65+
fn draw(self: Box<Self>, plot_ui: &mut PlotUi) {
66+
plot_ui.points(*self);
67+
}
68+
}
6769

68-
unsafe impl Sync for PlotDrawItem {}
70+
impl PlotDraw for Polygon {
71+
fn draw(self: Box<Self>, plot_ui: &mut PlotUi) {
72+
plot_ui.polygon(*self);
73+
}
74+
}
6975

70-
impl Debug for PlotDrawItem {
71-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
72-
f.write_str(match self {
73-
PlotDrawItem::Polygon(_) => "DrawShape",
74-
PlotDrawItem::Arrows(_) => "Arrow",
75-
PlotDrawItem::Text(_) => "Text",
76-
PlotDrawItem::Line(_) => "Line",
77-
PlotDrawItem::Image(_) => "Image",
78-
})
76+
impl PlotDraw for Arrows {
77+
fn draw(self: Box<Self>, plot_ui: &mut PlotUi) {
78+
plot_ui.arrows(*self);
7979
}
8080
}
8181

82-
impl PlotDrawItem {
83-
pub(crate) fn draw(self, plot_ui: &mut PlotUi) {
84-
match self {
85-
PlotDrawItem::Polygon(polygon) => {
86-
plot_ui.polygon(polygon);
87-
}
88-
PlotDrawItem::Arrows(arrows) => {
89-
plot_ui.arrows(arrows);
90-
}
91-
PlotDrawItem::Text(text) => {
92-
plot_ui.text(text);
93-
}
94-
PlotDrawItem::Line(line) => {
95-
plot_ui.line(line);
96-
}
97-
PlotDrawItem::Image(image) => {
98-
plot_ui.image(image);
99-
}
100-
}
82+
impl PlotDraw for Line {
83+
fn draw(self: Box<Self>, plot_ui: &mut PlotUi) {
84+
plot_ui.line(*self);
85+
}
86+
}
87+
88+
impl PlotDraw for Text {
89+
fn draw(self: Box<Self>, plot_ui: &mut PlotUi) {
90+
plot_ui.text(*self);
91+
}
92+
}
93+
impl PlotDraw for PlotImage {
94+
fn draw(self: Box<Self>, plot_ui: &mut PlotUi) {
95+
plot_ui.image(*self);
96+
}
97+
}
98+
99+
pub trait PlotDrawHelper {
100+
fn draw(self, plot_ui: &mut PlotUi);
101+
}
102+
103+
impl PlotDrawHelper for Points {
104+
fn draw(self, plot_ui: &mut PlotUi) {
105+
plot_ui.points(self);
106+
}
107+
}
108+
109+
impl PlotDrawHelper for Polygon {
110+
fn draw(self, plot_ui: &mut PlotUi) {
111+
plot_ui.polygon(self);
112+
}
113+
}
114+
115+
impl PlotDrawHelper for Arrows {
116+
fn draw(self, plot_ui: &mut PlotUi) {
117+
plot_ui.arrows(self);
118+
}
119+
}
120+
121+
impl PlotDrawHelper for Line {
122+
fn draw(self, plot_ui: &mut PlotUi) {
123+
plot_ui.line(self);
124+
}
125+
}
126+
127+
impl PlotDrawHelper for Text {
128+
fn draw(self, plot_ui: &mut PlotUi) {
129+
plot_ui.text(self);
130+
}
131+
}
132+
impl PlotDrawHelper for PlotImage {
133+
fn draw(self, plot_ui: &mut PlotUi) {
134+
plot_ui.image(self);
101135
}
102136
}

0 commit comments

Comments
 (0)