@@ -61,7 +61,7 @@ impl ViewportState {
61
61
} ) )
62
62
}
63
63
64
- pub fn show ( vp_state : Arc < RwLock < Self > > , ctx : & egui:: Context ) {
64
+ pub fn show ( vp_state : Arc < RwLock < Self > > , ctx : & egui:: Context , close_button : bool ) {
65
65
if !vp_state. read ( ) . visible {
66
66
return ;
67
67
}
@@ -71,6 +71,7 @@ impl ViewportState {
71
71
72
72
let viewport = ViewportBuilder :: default ( )
73
73
. with_title ( & title)
74
+ . with_close_button ( close_button)
74
75
. with_inner_size ( [ 500.0 , 500.0 ] ) ;
75
76
76
77
if immediate {
@@ -80,7 +81,7 @@ impl ViewportState {
80
81
vp_state. visible = false ;
81
82
}
82
83
show_as_popup ( ctx, class, & title, vp_id. into ( ) , |ui : & mut egui:: Ui | {
83
- generic_child_ui ( ui, & mut vp_state) ;
84
+ generic_child_ui ( ui, & mut vp_state, close_button ) ;
84
85
} ) ;
85
86
} ) ;
86
87
} else {
@@ -101,7 +102,7 @@ impl ViewportState {
101
102
ui. label ( format ! ( "Callback has been reused {current_count} times" ) ) ;
102
103
* count. write ( ) += 1 ;
103
104
104
- generic_child_ui ( ui, & mut vp_state) ;
105
+ generic_child_ui ( ui, & mut vp_state, close_button ) ;
105
106
} ,
106
107
) ;
107
108
} ) ;
@@ -118,6 +119,7 @@ impl ViewportState {
118
119
119
120
pub struct App {
120
121
top : Vec < Arc < RwLock < ViewportState > > > ,
122
+ close_button : bool ,
121
123
}
122
124
123
125
impl Default for App {
@@ -151,6 +153,7 @@ impl Default for App {
151
153
] ,
152
154
) ,
153
155
] ,
156
+ close_button : true ,
154
157
}
155
158
}
156
159
}
@@ -169,8 +172,8 @@ impl eframe::App for App {
169
172
}
170
173
ctx. set_embed_viewports ( embed_viewports) ;
171
174
}
172
-
173
- generic_ui ( ui, & self . top ) ;
175
+ ui . checkbox ( & mut self . close_button , "with close button" ) ;
176
+ generic_ui ( ui, & self . top , self . close_button ) ;
174
177
} ) ;
175
178
}
176
179
}
@@ -191,7 +194,7 @@ fn show_as_popup(
191
194
}
192
195
}
193
196
194
- fn generic_child_ui ( ui : & mut egui:: Ui , vp_state : & mut ViewportState ) {
197
+ fn generic_child_ui ( ui : & mut egui:: Ui , vp_state : & mut ViewportState , close_button : bool ) {
195
198
ui. horizontal ( |ui| {
196
199
ui. label ( "Title:" ) ;
197
200
if ui. text_edit_singleline ( & mut vp_state. title ) . changed ( ) {
@@ -203,10 +206,10 @@ fn generic_child_ui(ui: &mut egui::Ui, vp_state: &mut ViewportState) {
203
206
}
204
207
} ) ;
205
208
206
- generic_ui ( ui, & vp_state. children ) ;
209
+ generic_ui ( ui, & vp_state. children , close_button ) ;
207
210
}
208
211
209
- fn generic_ui ( ui : & mut egui:: Ui , children : & [ Arc < RwLock < ViewportState > > ] ) {
212
+ fn generic_ui ( ui : & mut egui:: Ui , children : & [ Arc < RwLock < ViewportState > > ] , close_button : bool ) {
210
213
let container_id = ui. id ( ) ;
211
214
212
215
let ctx = ui. ctx ( ) . clone ( ) ;
@@ -290,7 +293,7 @@ fn generic_ui(ui: &mut egui::Ui, children: &[Arc<RwLock<ViewportState>>]) {
290
293
* visible
291
294
} ;
292
295
if visible {
293
- ViewportState :: show ( child. clone ( ) , & ctx) ;
296
+ ViewportState :: show ( child. clone ( ) , & ctx, close_button ) ;
294
297
}
295
298
}
296
299
}
0 commit comments