1- use egui:: Context ;
1+ use egui:: Ui ;
22use egui_glium:: EguiGlium ;
33use egui_glium:: egui_winit:: egui:: ViewportId ;
44use glium:: glutin:: surface:: WindowSurface ;
@@ -24,15 +24,17 @@ pub struct LSystemConfig {
2424 pub production_rules : Vec < ( char , String ) > ,
2525 pub n_iterations : u32 ,
2626 pub angle : f32 ,
27+ pub fractal_height : f32 , // TODO move elsewhere, now leaving here for convenience with App update logic
2728}
2829
2930impl Default for LSystemConfig {
3031 fn default ( ) -> Self {
3132 Self {
3233 axiom : "F" . to_string ( ) ,
33- production_rules : vec ! [ ( 'F' , "F[+F]F[- F]F" . to_string( ) ) ] ,
34+ production_rules : vec ! [ ( 'F' , "F[+F][&F][ \\ F]F[-F][^F][/ F]F" . to_string( ) ) ] ,
3435 n_iterations : 3 ,
3536 angle : 25.0 ,
37+ fractal_height : 3.0 ,
3638 }
3739 }
3840}
@@ -148,101 +150,97 @@ impl GuiController {
148150 fn ui_control_panel (
149151 model_selection : & mut ModelSelection ,
150152 shading_mode : & mut ShadingMode ,
151- ctx : & Context ,
153+ ui : & mut Ui ,
152154 ) {
153- egui:: Window :: new ( "Control panel" ) . show ( ctx, |ui| {
154- egui:: ComboBox :: from_label ( "Selected Model" )
155- . selected_text ( format ! ( "{model_selection:?}" ) )
156- . show_ui ( ui, |ui| {
157- ui. selectable_value ( model_selection, ModelSelection :: Monkey , "Monkey" ) ;
158- ui. selectable_value ( model_selection, ModelSelection :: Cylinder , "Cylinder" ) ;
159- } ) ;
155+ egui:: ComboBox :: from_label ( "Selected Model" )
156+ . selected_text ( format ! ( "{model_selection:?}" ) )
157+ . show_ui ( ui, |ui| {
158+ ui. selectable_value ( model_selection, ModelSelection :: Monkey , "Monkey" ) ;
159+ ui. selectable_value ( model_selection, ModelSelection :: Cylinder , "Cylinder" ) ;
160+ } ) ;
160161
161- ui. separator ( ) ;
162- ui. label ( "Shading Mode:" ) ;
163- ui. radio_value ( shading_mode, ShadingMode :: Flat , "Flat" ) ;
164- ui. radio_value ( shading_mode, ShadingMode :: Gouraud , "Gouraud" ) ;
165- ui. radio_value ( shading_mode, ShadingMode :: Phong , "Phong" ) ;
166- ui. separator ( ) ;
167- } ) ;
162+ ui. label ( "Shading Mode:" ) ;
163+ ui. radio_value ( shading_mode, ShadingMode :: Flat , "Flat" ) ;
164+ ui. radio_value ( shading_mode, ShadingMode :: Gouraud , "Gouraud" ) ;
165+ ui. radio_value ( shading_mode, ShadingMode :: Phong , "Phong" ) ;
166+ }
167+
168+ fn ui_fractal_height ( fractal_height : & mut f32 , ui : & mut Ui ) {
169+ ui. label ( "Fractal Height:" ) ;
170+ ui. add ( egui:: Slider :: new ( fractal_height, 0.1 ..=5.0 ) . text ( "Fractal Height" ) ) ;
168171 }
169172
170173 fn ui_tree_generation_config (
171174 tree_generation_config : & mut TreeGenerationConfig ,
172175 requires_redraw : & mut bool ,
173- ctx : & Context ,
176+ ui : & mut Ui ,
174177 ) {
175- egui:: Window :: new ( "Tree Generation" ) . show ( ctx, |ui| {
176- ui. label ( "Number of trees" ) ;
177- ui. add ( egui:: Slider :: new (
178- & mut tree_generation_config. num_trees ,
179- 1 ..=128 ,
180- ) ) ;
181- ui. label ( "X Bounds:" ) ;
182- ui. add (
183- egui:: Slider :: new (
184- & mut tree_generation_config. xmin ,
185- -50 ..=tree_generation_config. xmax - 1 ,
186- )
187- . text ( "X Min" ) ,
188- ) ;
189- ui. add (
190- egui:: Slider :: new (
191- & mut tree_generation_config. xmax ,
192- ( tree_generation_config. xmin + 1 ) ..=50 ,
193- )
194- . text ( "X Max" ) ,
195- ) ;
196- ui. label ( "Z Bounds:" ) ;
197- ui. add (
198- egui:: Slider :: new (
199- & mut tree_generation_config. zmin ,
200- -50 ..=tree_generation_config. zmax - 1 ,
201- )
202- . text ( "Z Min" ) ,
203- ) ;
204- ui. add (
205- egui:: Slider :: new (
206- & mut tree_generation_config. zmax ,
207- ( tree_generation_config. zmin + 1 ) ..=50 ,
208- )
209- . text ( "Z Max" ) ,
210- ) ;
211- if ui. add ( egui:: Button :: new ( "Regenerate trees" ) ) . clicked ( ) {
212- * requires_redraw = true ;
213- }
214- } ) ;
178+ ui. label ( "Number of trees" ) ;
179+ ui. add ( egui:: Slider :: new (
180+ & mut tree_generation_config. num_trees ,
181+ 1 ..=128 ,
182+ ) ) ;
183+ ui. label ( "X Bounds:" ) ;
184+ ui. add (
185+ egui:: Slider :: new (
186+ & mut tree_generation_config. xmin ,
187+ -50 ..=tree_generation_config. xmax - 1 ,
188+ )
189+ . text ( "X Min" ) ,
190+ ) ;
191+ ui. add (
192+ egui:: Slider :: new (
193+ & mut tree_generation_config. xmax ,
194+ ( tree_generation_config. xmin + 1 ) ..=50 ,
195+ )
196+ . text ( "X Max" ) ,
197+ ) ;
198+ ui. label ( "Z Bounds:" ) ;
199+ ui. add (
200+ egui:: Slider :: new (
201+ & mut tree_generation_config. zmin ,
202+ -50 ..=tree_generation_config. zmax - 1 ,
203+ )
204+ . text ( "Z Min" ) ,
205+ ) ;
206+ ui. add (
207+ egui:: Slider :: new (
208+ & mut tree_generation_config. zmax ,
209+ ( tree_generation_config. zmin + 1 ) ..=50 ,
210+ )
211+ . text ( "Z Max" ) ,
212+ ) ;
213+ if ui. add ( egui:: Button :: new ( "Regenerate trees" ) ) . clicked ( ) {
214+ * requires_redraw = true ;
215+ }
215216 }
216217
217218 // TODO make editable
218- fn ui_lsystem_config ( lsystem_config : & mut LSystemConfig , ctx : & Context ) {
219- egui:: Window :: new ( "LSystem Configuration" ) . show ( ctx, |ui| {
220- ui. add (
221- egui:: Slider :: new ( & mut lsystem_config. n_iterations , 0 ..=6 )
222- . text ( "Number of Iterations" ) ,
223- ) ;
224- ui. add ( egui:: Slider :: new ( & mut lsystem_config. angle , 0.0 ..=45.0 ) . text ( "Angle" ) ) ;
225- ui. label ( format ! ( "{:?}" , lsystem_config. axiom) ) ;
226- ui. label ( "Production Rules:" ) ;
227- for ( i, ( symbol, replacement) ) in lsystem_config. production_rules . iter ( ) . enumerate ( ) {
228- ui. horizontal ( |ui| {
229- ui. label ( format ! ( "{i}: {symbol} -> {replacement}" ) ) ;
230- } ) ;
231- }
232- } ) ;
219+ fn ui_lsystem_config ( lsystem_config : & mut LSystemConfig , ui : & mut Ui ) {
220+ ui. label ( "LSystem Config:" ) ;
221+ ui. add (
222+ egui:: Slider :: new ( & mut lsystem_config. n_iterations , 0 ..=6 ) . text ( "Number of Iterations" ) ,
223+ ) ;
224+ ui. add ( egui:: Slider :: new ( & mut lsystem_config. angle , 0.0 ..=45.0 ) . text ( "Angle" ) ) ;
225+ ui. label ( format ! ( "{:?}" , lsystem_config. axiom) ) ;
226+ ui. label ( "Production Rules:" ) ;
227+ for ( i, ( symbol, replacement) ) in lsystem_config. production_rules . iter ( ) . enumerate ( ) {
228+ ui. horizontal ( |ui| {
229+ ui. label ( format ! ( "{i}: {symbol} -> {replacement}" ) ) ;
230+ } ) ;
231+ }
233232 }
234233
235234 fn ui_color_panel (
236235 interpolation_color_low : & mut [ f32 ; 3 ] ,
237236 interpolation_color_high : & mut [ f32 ; 3 ] ,
238- ctx : & Context ,
237+ ui : & mut Ui ,
239238 ) {
240- egui:: Window :: new ( "Color Configuration" ) . show ( ctx, |ui| {
241- ui. label ( "Color - low" ) ;
242- ui. color_edit_button_rgb ( interpolation_color_low) ;
243- ui. label ( "Color - high" ) ;
244- ui. color_edit_button_rgb ( interpolation_color_high) ;
245- } ) ;
239+ ui. label ( "Color Interpolation:" ) ;
240+ ui. label ( "Color - low" ) ;
241+ ui. color_edit_button_rgb ( interpolation_color_low) ;
242+ ui. label ( "Color - high" ) ;
243+ ui. color_edit_button_rgb ( interpolation_color_high) ;
246244 }
247245
248246 pub fn draw ( & mut self , window : & Window , display : & Display < WindowSurface > , frame : & mut Frame ) {
@@ -253,14 +251,20 @@ impl GuiController {
253251 let color_high = & mut self . interpolation_color_high ;
254252
255253 self . egui_glium . run ( window, |ctx| {
256- GuiController :: ui_control_panel ( model_selection, shading_mode, ctx) ;
257- GuiController :: ui_lsystem_config ( lsystem_config, ctx) ;
258- GuiController :: ui_color_panel ( color_low, color_high, ctx) ;
259- GuiController :: ui_tree_generation_config (
260- & mut self . tree_generation_config ,
261- & mut self . requires_tree_regeneration ,
262- ctx,
263- ) ;
254+ egui:: Window :: new ( "Control panel" ) . show ( ctx, |ui| {
255+ GuiController :: ui_control_panel ( model_selection, shading_mode, ui) ;
256+ GuiController :: ui_fractal_height ( & mut lsystem_config. fractal_height , ui) ;
257+ ui. separator ( ) ;
258+ GuiController :: ui_lsystem_config ( lsystem_config, ui) ;
259+ ui. separator ( ) ;
260+ GuiController :: ui_color_panel ( color_low, color_high, ui) ;
261+ ui. separator ( ) ;
262+ GuiController :: ui_tree_generation_config (
263+ & mut self . tree_generation_config ,
264+ & mut self . requires_tree_regeneration ,
265+ ui,
266+ ) ;
267+ } ) ;
264268 } ) ;
265269 self . egui_glium . paint ( display, frame) ;
266270 }
0 commit comments