@@ -169,18 +169,31 @@ impl TriggerBuilder<()> {
169169 popups : Default :: default ( ) ,
170170 } ;
171171 }
172+
173+ pub fn add_all < Contents : PopupContentList > (
174+ self ,
175+ popups : Contents ,
176+ position : Pos2 ,
177+ ) -> TriggerBuilder < Contents :: AsPopupList > {
178+ return TriggerBuilder {
179+ id : self . id ,
180+ bounding_box : self . bounding_box ,
181+ popups : popups. position ( position) ,
182+ } ;
183+ }
172184}
173185
174186impl < L : PopupList > TriggerBuilder < L > {
175- pub fn add < K , F > ( self , position : Pos2 , add_contents : F ) -> TriggerBuilder < ( PrimedPopup < K , F > , L ) >
187+ pub fn add < C /*, K, F*/ > ( self , position : Pos2 , contents : C ) -> TriggerBuilder < ( PositionedPopup < C > , L ) >
176188 where
177- K : PopupKind + NotInPopupList < L > ,
178- F : FnOnce ( & mut egui:: Ui , & mut Frontend , & mut Backend ) -> <K as PopupKind >:: Response ,
189+ //K: PopupKind + NotInPopupList<L>,
190+ //F: FnOnce(&mut egui::Ui, &mut Frontend, &mut Backend) -> <K as PopupKind>::Response,
191+ C : PopupContents , //<Kind = K, Contents = F>,
179192 {
180193 return TriggerBuilder {
181194 id : self . id ,
182195 bounding_box : self . bounding_box ,
183- popups : self . popups . add ( PrimedPopup :: new ( position, add_contents ) ) ,
196+ popups : self . popups . add ( PositionedPopup :: new ( position, contents ) ) ,
184197 } ;
185198 }
186199
@@ -200,29 +213,81 @@ impl<L: PopupList> TriggerBuilder<L> {
200213 }
201214}
202215
203- pub struct PrimedPopup < K , F >
216+ pub trait PopupContentList : Sized + Clone {
217+ type AsPopupList : PopupList ;
218+ fn add < C : PopupContents > ( self , contents : C ) -> ( Self , C ) {
219+ return ( self , contents) ;
220+ }
221+
222+ fn position ( self , position : Pos2 ) -> Self :: AsPopupList ;
223+ }
224+ impl PopupContentList for ( ) {
225+ type AsPopupList = ( ) ;
226+ fn position ( self , _position : Pos2 ) -> Self :: AsPopupList { }
227+ }
228+ impl < H , T > PopupContentList for ( H , T )
229+ where
230+ H : PopupContents ,
231+ T : PopupContentList ,
232+ {
233+ type AsPopupList = ( PositionedPopup < H > , T :: AsPopupList ) ;
234+ fn position ( self , position : Pos2 ) -> Self :: AsPopupList {
235+ return ( PositionedPopup :: new ( position, self . 0 ) , self . 1 . position ( position) ) ;
236+ }
237+ }
238+
239+ pub trait PopupContents : Clone {
240+ type Kind : PopupKind ;
241+ type Contents : FnOnce ( & mut egui:: Ui , & mut Frontend , & mut Backend ) -> <Self :: Kind as PopupKind >:: Response ;
242+ fn contents ( self ) -> Self :: Contents ;
243+ }
244+
245+ impl < K , F > PopupContents for PopupContentData < K , F >
246+ where
247+ K : PopupKind ,
248+ F : FnOnce ( & mut egui:: Ui , & mut Frontend , & mut Backend ) -> <K as PopupKind >:: Response + Clone ,
249+ {
250+ type Kind = K ;
251+ type Contents = F ;
252+
253+ fn contents ( self ) -> Self :: Contents {
254+ return self . add_contents ;
255+ }
256+ }
257+
258+ #[ derive( Clone ) ]
259+ pub struct PopupContentData < K , F >
204260where
205261 K : PopupKind ,
206262 F : FnOnce ( & mut egui:: Ui , & mut Frontend , & mut Backend ) -> <K as PopupKind >:: Response ,
207263{
208264 popup_kind : PhantomData < K > ,
209- position : Pos2 ,
210265 add_contents : F ,
211266}
212- impl < K , F > PrimedPopup < K , F >
267+
268+ impl < K , F > PopupContentData < K , F >
213269where
214270 K : PopupKind ,
215271 F : FnOnce ( & mut egui:: Ui , & mut Frontend , & mut Backend ) -> <K as PopupKind >:: Response ,
216272{
217- pub fn new ( position : Pos2 , add_contents : F ) -> Self {
273+ pub fn new ( add_contents : F ) -> Self {
218274 Self {
219- position,
220275 add_contents,
221276 popup_kind : PhantomData ,
222277 }
223278 }
224279}
225280
281+ pub struct PositionedPopup < Contents : PopupContents > {
282+ position : Pos2 ,
283+ contents : Contents ,
284+ }
285+ impl < Contents : PopupContents > PositionedPopup < Contents > {
286+ pub fn new ( position : Pos2 , contents : Contents ) -> Self {
287+ Self { position, contents }
288+ }
289+ }
290+
226291pub trait PopupResponse : Sized {
227292 fn union ( self , other : egui:: Response ) -> Self ;
228293}
@@ -252,23 +317,19 @@ pub trait DisplayablePopup {
252317 fn position ( & self ) -> & Pos2 ;
253318 fn show ( self , ui : & mut Ui , frontend : & mut Frontend , backend : & mut Backend ) -> <Self :: Kind as PopupKind >:: Response ;
254319}
255- impl < K , F > DisplayablePopup for PrimedPopup < K , F >
256- where
257- K : PopupKind ,
258- F : FnOnce ( & mut egui:: Ui , & mut Frontend , & mut Backend ) -> <K as PopupKind >:: Response ,
259- {
260- type Kind = K ;
320+ impl < Contents : PopupContents > DisplayablePopup for PositionedPopup < Contents > {
321+ type Kind = Contents :: Kind ;
261322
262323 fn position ( & self ) -> & Pos2 {
263324 return & self . position ;
264325 }
265326
266- fn show ( self , ui : & mut Ui , frontend : & mut Frontend , backend : & mut Backend ) -> <K as PopupKind >:: Response {
267- return ( self . add_contents ) ( ui, frontend, backend) ;
327+ fn show ( self , ui : & mut Ui , frontend : & mut Frontend , backend : & mut Backend ) -> <Self :: Kind as PopupKind >:: Response {
328+ return ( self . contents . contents ( ) ) ( ui, frontend, backend) ;
268329 }
269330}
270331
271- pub trait PopupKind : Sized {
332+ pub trait PopupKind : Sized + Clone {
272333 type Response : PopupResponse ;
273334 fn id ( trigger_id : & egui:: Id ) -> egui:: Id ;
274335 fn close_condition ( ) -> PopupCloseCondition ;
@@ -281,7 +342,7 @@ pub trait PopupKind: Sized {
281342 P : DisplayablePopup < Kind = Self > ;
282343}
283344
284- #[ derive( Default ) ]
345+ #[ derive( Default , Clone ) ]
285346pub struct Tooltip { }
286347impl PopupKind for Tooltip {
287348 type Response = egui:: Response ;
@@ -306,6 +367,7 @@ impl PopupKind for Tooltip {
306367 }
307368}
308369
370+ #[ derive( Clone ) ]
309371pub struct ContextMenu { }
310372impl PopupKind for ContextMenu {
311373 type Response = egui:: Response ;
@@ -329,6 +391,8 @@ impl PopupKind for ContextMenu {
329391 PopupManager :: add_context_menu ( trigger, ui, frontend, backend) ;
330392 }
331393}
394+
395+ #[ derive( Clone ) ]
332396pub struct DropdownMenu { }
333397impl PopupKind for DropdownMenu {
334398 type Response = egui:: Response ;
@@ -353,6 +417,7 @@ impl PopupKind for DropdownMenu {
353417 }
354418}
355419
420+ #[ derive( Clone ) ]
356421pub struct ModalDialog { }
357422impl PopupKind for ModalDialog {
358423 type Response = egui:: InnerResponse < bool > ;
0 commit comments