1
+ use crate :: consts:: * ;
1
2
use crate :: conway;
2
3
use crate :: RunModes ;
3
4
use crate :: UserInterface ;
5
+ use crate :: Viewport ;
4
6
use conway:: conway_map;
5
7
use eframe:: egui;
6
8
use egui:: Id ;
9
+ use web_sys:: console;
10
+
11
+
12
+ #[ derive( Default ) ]
13
+ pub struct MouseState {
14
+ pub is_dragging : bool ,
15
+ pub last_pos : Option < egui:: Pos2 > ,
16
+ }
17
+
18
+
19
+
7
20
use egui:: LayerId ;
8
21
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
22
+
9
23
#[ derive( serde:: Deserialize , serde:: Serialize ) ]
10
24
#[ serde( default ) ] // if we add new fields, give them default values when deserializing old state
11
25
pub struct ConwaySim {
@@ -24,7 +38,10 @@ pub struct ConwaySim {
24
38
view_stats : bool ,
25
39
first_run : bool ,
26
40
mode : RunModes ,
41
+ #[ serde( skip) ] // This how you opt-out of serialization of a field
42
+ viewport : Viewport ,
27
43
}
44
+
28
45
// TODO: implement feature so that the user can click and drag on the main view window to move
29
46
// their view around instead of using sliders, cause sliders are janky as fuck
30
47
@@ -46,10 +63,12 @@ impl Default for ConwaySim {
46
63
reset : false ,
47
64
first_run : true ,
48
65
mode : RunModes :: default ( ) ,
66
+ viewport : Viewport :: default ( ) ,
49
67
}
50
68
}
51
69
}
52
70
71
+
53
72
impl ConwaySim {
54
73
/// Called once before the first frame.
55
74
pub fn new ( cc : & eframe:: CreationContext < ' _ > ) -> Self {
@@ -63,9 +82,20 @@ impl ConwaySim {
63
82
64
83
Default :: default ( )
65
84
}
85
+ fn handle_mouse_events ( & mut self , ctx : & egui:: Context ) {
86
+
87
+
88
+ }
89
+
90
+ fn handle_scroll ( & mut self , ctx : & egui:: Context , scroll_delta : egui:: Vec2 ) {
91
+
92
+ }
66
93
67
94
fn update_simulation ( & mut self , ctx : & egui:: Context ) {
68
95
egui:: CentralPanel :: default ( ) . show ( ctx, |ui| {
96
+ let viewport_rect = ui. available_rect_before_wrap ( ) ;
97
+ self . viewport . rect = viewport_rect;
98
+
69
99
let gridline_layer: egui:: LayerId =
70
100
LayerId :: new ( egui:: Order :: Foreground , Id :: from ( "gridlines" ) ) ;
71
101
let painter = egui:: Painter :: new (
@@ -79,8 +109,9 @@ impl ConwaySim {
79
109
ui. available_rect_before_wrap ( ) ,
80
110
) ;
81
111
ui. expand_to_include_rect ( painter. clip_rect ( ) ) ;
82
- ui. expand_to_include_rect ( line_painter. clip_rect ( ) ) ;
112
+ // ui.expand_to_include_rect(line_painter.clip_rect());
83
113
self . rect = Some ( painter. clip_rect ( ) ) ;
114
+ //Logic that actually draws the screen I think
84
115
let mut shapes: Vec < egui:: Shape > = if self . map . light_mode {
85
116
vec ! [ egui:: Shape :: rect_filled(
86
117
self . rect. unwrap( ) ,
@@ -105,6 +136,12 @@ impl ConwaySim {
105
136
line_painter. extend ( lines) ;
106
137
}
107
138
} ) ;
139
+ if ctx. input ( |i| i. pointer . secondary_clicked ( ) && i. pointer . is_decidedly_dragging ( ) ) {
140
+ println ! ( "Dragging and such" ) ;
141
+ use crate :: app:: console;
142
+ console:: log_1 ( & "erm, what the deuce" . into ( ) ) ;
143
+
144
+ }
108
145
109
146
if self . view_stats {
110
147
egui:: Window :: new ( "Stats" ) . show ( ctx, |ui| {
@@ -117,7 +154,7 @@ impl UserInterface for ConwaySim {
117
154
fn update_side_panel ( & mut self , ctx : & egui:: Context ) {
118
155
egui:: SidePanel :: left ( "Menu" ) . show ( ctx, |ui| {
119
156
ui. add (
120
- egui:: Slider :: new ( & mut self . map . cell_size , 0.1 ..= 50.0 )
157
+ egui:: Slider :: new ( & mut self . map . cell_size , CELL_MIN ..= CELL_MAX )
121
158
. step_by ( 0.1 )
122
159
. orientation ( egui:: SliderOrientation :: Horizontal )
123
160
. text ( "Cell Size" ) ,
@@ -139,18 +176,18 @@ impl UserInterface for ConwaySim {
139
176
// BUG: below sliders are bugged, if one of the viewports is updated, say, the x axis, the vertical
140
177
// lines will not move along with the horizontal ones, leading to a realy weird effect, and vice
141
178
// versa for the y axis, with the other lines not moving, while the vertical ones will move
142
- // ui.add(
143
- // egui::Slider::new(&mut self.map.x_axis, -1000..=1000)
144
- // .step_by(1.0)
145
- // .orientation(egui::SliderOrientation::Horizontal)
146
- // .text("X Axis"),
147
- // );
148
- // ui.add(
149
- // egui::Slider::new(&mut self.map.y_axis, -1000..=1000)
150
- // .step_by(1.0)
151
- // .orientation(egui::SliderOrientation::Horizontal)
152
- // .text("Y Axis"),
153
- // );
179
+ ui. add (
180
+ egui:: Slider :: new ( & mut self . map . x_axis , -1000 ..=1000 )
181
+ . step_by ( 1.0 )
182
+ . orientation ( egui:: SliderOrientation :: Horizontal )
183
+ . text ( "X Axis" ) ,
184
+ ) ;
185
+ ui. add (
186
+ egui:: Slider :: new ( & mut self . map . y_axis , -1000 ..=1000 )
187
+ . step_by ( 1.0 )
188
+ . orientation ( egui:: SliderOrientation :: Horizontal )
189
+ . text ( "Y Axis" ) ,
190
+ ) ;
154
191
ui. add (
155
192
egui:: Slider :: new ( & mut self . map . map_size , 10 ..=500 )
156
193
. step_by ( 1.0 )
0 commit comments