diff --git a/src/ctx/queue.rs b/src/ctx/queue.rs index 6b74fd92..39d7e9de 100644 --- a/src/ctx/queue.rs +++ b/src/ctx/queue.rs @@ -13,12 +13,16 @@ pub trait Queue { //TODO probably remove mandatory StdEnqueueable bound pub enum StdEnqueueable where E: Env { Render{force: bool}, Event{event: EEvent, ts: u64}, - MutateWidget{path: E::WidgetPath, f: fn(WidgetRefMut,&mut E::Context,E::WidgetPath)}, - MutateWidgetClosure{path: E::WidgetPath, f: Box,&mut E::Context,E::WidgetPath)+'static>}, + MutateWidget{path: E::WidgetPath, f: fn(Result,GuionError>,&mut E::Context,E::WidgetPath)}, + MutateWidgetClosure{path: E::WidgetPath, f: Box,GuionError>,&mut E::Context,E::WidgetPath)+'static>}, + MutateWidgetTry{path: E::WidgetPath, f: fn(WidgetRefMut,&mut E::Context,E::WidgetPath)}, + MutateWidgetClosureTry{path: E::WidgetPath, f: Box,&mut E::Context,E::WidgetPath)+'static>}, MutateRoot{f: fn(&mut E::Storage,&mut E::Context)}, MutateRootClosure{f: Box}, - AccessWidget{path: E::WidgetPath, f: fn(WidgetRef,&mut E::Context)}, - AccessWidgetClosure{path: E::WidgetPath, f: Box,&mut E::Context)+'static>}, + AccessWidget{path: E::WidgetPath, f: fn(Result,GuionError>,&mut E::Context)}, + AccessWidgetClosure{path: E::WidgetPath, f: Box,GuionError>,&mut E::Context)+'static>}, + AccessWidgetTry{path: E::WidgetPath, f: fn(WidgetRef,&mut E::Context)}, + AccessWidgetClosureTry{path: E::WidgetPath, f: Box,&mut E::Context)+'static>}, AccessRoot{f: fn(&E::Storage,&mut E::Context)}, AccessRootClosure{f: Box}, MutMessage{path: E::WidgetPath, msg: E::Message}, diff --git a/src/widget/link/mod.rs b/src/widget/link/mod.rs index 8dc6b742..8648a2d6 100644 --- a/src/widget/link/mod.rs +++ b/src/widget/link/mod.rs @@ -16,22 +16,40 @@ pub struct Link<'c,E> where E: Env { impl<'c,E> Link<'c,E> where E: Env { /// Enqueue mutable access to this widget #[inline] - pub fn mutate(&mut self, f: fn(WidgetRefMut,&mut E::Context,E::WidgetPath)) { + pub fn mutate(&mut self, f: fn(Result,GuionError>,&mut E::Context,E::WidgetPath)) { self.mutate_at(f,StdOrder::PostCurrent,0) } #[inline] - pub fn mutate_at(&mut self, f: fn(WidgetRefMut,&mut E::Context,E::WidgetPath), o: O, p: i64) where ECQueue: Queue,O> { + pub fn mutate_at(&mut self, f: fn(Result,GuionError>,&mut E::Context,E::WidgetPath), o: O, p: i64) where ECQueue: Queue,O> { self.enqueue(StdEnqueueable::MutateWidget{path: self.widget.direct_path.refc(),f},o,p) } /// Enqueue mutable access to this widget #[inline] - pub fn mutate_closure(&mut self, f: Box,&mut E::Context,E::WidgetPath)+'static>) { + pub fn mutate_closure(&mut self, f: Box,GuionError>,&mut E::Context,E::WidgetPath)+'static>) { self.mutate_closure_at(f,StdOrder::PostCurrent,0) } #[inline] - pub fn mutate_closure_at(&mut self, f: Box,&mut E::Context,E::WidgetPath)+'static>, o: O, p: i64) where ECQueue: Queue,O> { + pub fn mutate_closure_at(&mut self, f: Box,GuionError>,&mut E::Context,E::WidgetPath)+'static>, o: O, p: i64) where ECQueue: Queue,O> { self.enqueue(StdEnqueueable::MutateWidgetClosure{path: self.widget.direct_path.refc(),f},o,p) } + /// Enqueue mutable access to this widget + #[inline] + pub fn mutate_try(&mut self, f: fn(WidgetRefMut,&mut E::Context,E::WidgetPath)) { + self.mutate_at_try(f,StdOrder::PostCurrent,0) + } + #[inline] + pub fn mutate_at_try(&mut self, f: fn(WidgetRefMut,&mut E::Context,E::WidgetPath), o: O, p: i64) where ECQueue: Queue,O> { + self.enqueue(StdEnqueueable::MutateWidgetTry{path: self.widget.direct_path.refc(),f},o,p) + } + /// Enqueue mutable access to this widget + #[inline] + pub fn mutate_closure_try(&mut self, f: Box,&mut E::Context,E::WidgetPath)+'static>) { + self.mutate_closure_at_try(f,StdOrder::PostCurrent,0) + } + #[inline] + pub fn mutate_closure_at_try(&mut self, f: Box,&mut E::Context,E::WidgetPath)+'static>, o: O, p: i64) where ECQueue: Queue,O> { + self.enqueue(StdEnqueueable::MutateWidgetClosureTry{path: self.widget.direct_path.refc(),f},o,p) + } /// Enqueue message-style invoking of [WidgetMut::message] #[inline] pub fn message_mut(&mut self, m: E::Message) { @@ -44,22 +62,40 @@ impl<'c,E> Link<'c,E> where E: Env { } /// Enqueue immutable access to this widget #[inline] - pub fn later(&mut self, f: fn(WidgetRef,&mut E::Context)) { + pub fn later(&mut self, f: fn(Result,GuionError>,&mut E::Context)) { self.later_at(f,StdOrder::PostCurrent,0) } #[inline] - pub fn later_at(&mut self, f: fn(WidgetRef,&mut E::Context), o: O, p: i64) where ECQueue: Queue,O> { + pub fn later_at(&mut self, f: fn(Result,GuionError>,&mut E::Context), o: O, p: i64) where ECQueue: Queue,O> { self.enqueue(StdEnqueueable::AccessWidget{path: self.widget.direct_path.refc(),f},o,p) } /// Enqueue immutable access to this widget #[inline] - pub fn later_closure(&mut self, f: Box,&mut E::Context)+Sync>) { + pub fn later_closure(&mut self, f: Box,GuionError>,&mut E::Context)+Sync>) { self.later_closure_at(f,StdOrder::PostCurrent,0) } #[inline] - pub fn later_closure_at(&mut self, f: Box,&mut E::Context)+Sync>, o: O, p: i64) where ECQueue: Queue,O> { + pub fn later_closure_at(&mut self, f: Box,GuionError>,&mut E::Context)+Sync>, o: O, p: i64) where ECQueue: Queue,O> { self.enqueue(StdEnqueueable::AccessWidgetClosure{path: self.widget.direct_path.refc(),f},o,p) } + /// Enqueue immutable access to this widget + #[inline] + pub fn later_try(&mut self, f: fn(WidgetRef,&mut E::Context)) { + self.later_at_try(f,StdOrder::PostCurrent,0) + } + #[inline] + pub fn later_at_try(&mut self, f: fn(WidgetRef,&mut E::Context), o: O, p: i64) where ECQueue: Queue,O> { + self.enqueue(StdEnqueueable::AccessWidgetTry{path: self.widget.direct_path.refc(),f},o,p) + } + /// Enqueue immutable access to this widget + #[inline] + pub fn later_closure_try(&mut self, f: Box,&mut E::Context)+Sync>) { + self.later_closure_at_try(f,StdOrder::PostCurrent,0) + } + #[inline] + pub fn later_closure_at_try(&mut self, f: Box,&mut E::Context)+Sync>, o: O, p: i64) where ECQueue: Queue,O> { + self.enqueue(StdEnqueueable::AccessWidgetClosureTry{path: self.widget.direct_path.refc(),f},o,p) + } #[inline] pub fn enqueue_invalidate(&mut self) { self.enqueue(StdEnqueueable::InvalidateWidget{path: self.widget.direct_path.refc()},StdOrder::PreRender,0) diff --git a/src/widgets/area/widget.rs b/src/widgets/area/widget.rs index d2d1929a..1fa21955 100644 --- a/src/widgets/area/widget.rs +++ b/src/widgets/area/widget.rs @@ -65,7 +65,7 @@ impl<'w,E,W,Scroll> Widget for Area<'w,E,W,Scroll> where ee.key == EEKey::::UP || ee.key == EEKey::::DOWN || ee.key == EEKey::::LEFT || ee.key == EEKey::::RIGHT { - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let w = w.traitcast_mut::>().unwrap(); let mut v = w.get(ctx); if ee.key == EEKey::::UP { diff --git a/src/widgets/checkbox/widget.rs b/src/widgets/checkbox/widget.rs index 717f8ecb..5111702e 100644 --- a/src/widgets/checkbox/widget.rs +++ b/src/widgets/checkbox/widget.rs @@ -166,7 +166,7 @@ impl<'w,E,State,Text> CheckBox<'w,E,State,Text> where Text: AsWidget, { pub fn set(mut l: Link, v: bool) { - l.mutate_closure(Box::new(move |mut w,c,_|{ + l.mutate_closure_try(Box::new(move |mut w,c,_|{ //w.traitcast_mut::>().unwrap().set(v,c); let w = w.traitcast_mut::>().unwrap(); w.state_mut().set(v,c); diff --git a/src/widgets/label/widget.rs b/src/widgets/label/widget.rs index a83138a5..9706dc19 100644 --- a/src/widgets/label/widget.rs +++ b/src/widgets/label/widget.rs @@ -107,7 +107,7 @@ impl<'w,E,Text,GlyphCache> Label<'w,E,Text,GlyphCache> where let glyphs = Arc::new(ESGlyphs::::generate(text.as_ref(),(20.0,20.0),l.ctx)); let g = glyphs.refc(); - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let vali = w.traitcast_mut::>().unwrap(); let key = vali.validate(); let cache = w.traitcast_mut::>>().unwrap(); diff --git a/src/widgets/splitpane/widget.rs b/src/widgets/splitpane/widget.rs index 97e3de24..f4a74e6a 100644 --- a/src/widgets/splitpane/widget.rs +++ b/src/widgets/splitpane/widget.rs @@ -88,7 +88,7 @@ impl<'w,E,L,R,V> Widget for SplitPane<'w,E,L,R,V> where cx = cx - wx0; let fcx = (cx as f32)/(ww as f32); - l.mutate_closure(Box::new(move |mut w,c,_|{ + l.mutate_closure_try(Box::new(move |mut w,c,_|{ let w = w.traitcast_mut::>().unwrap(); w.set(fcx,c); })); diff --git a/src/widgets/textbox/imp.rs b/src/widgets/textbox/imp.rs index 14f86330..61dea4c7 100644 --- a/src/widgets/textbox/imp.rs +++ b/src/widgets/textbox/imp.rs @@ -170,7 +170,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> TextBox<'w,E,Text,Scroll,Cur let glyphs = Arc::new(ESGlyphs::::generate(text.as_ref(),(20.0,20.0),l.ctx)); let g = glyphs.refc(); - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let vali = w.traitcast_mut::>().unwrap(); let key = vali.validate(); let cache = w.traitcast_mut::>>().unwrap(); diff --git a/src/widgets/textbox/widget.rs b/src/widgets/textbox/widget.rs index c005e984..76f200b7 100644 --- a/src/widgets/textbox/widget.rs +++ b/src/widgets/textbox/widget.rs @@ -70,7 +70,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget for TextBox<'w,E,T if let Some(ee) = e.event.is_text_input() { let s = ee.text; - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let w = w.traitcast_mut::>().unwrap(); w.insert_text(&s,ctx); w.scroll_to_cursor(ctx,&b); @@ -83,7 +83,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget for TextBox<'w,E,T { let ctrl = l.state().is_pressed(&[EEKey::::CTRL]).is_some(); - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let w = w.traitcast_mut::>().unwrap(); if ee.key == EEKey::::BACKSPACE { w.remove_selection_or_n(1,ctx); @@ -101,7 +101,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget for TextBox<'w,E,T })); passed = true; }else if ee.key == EEKey::::A && l.state().is_pressed(&[EEKey::::CTRL]).is_some() { - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let wc = w.traitcast_mut::>().unwrap(); cursor.select = 0; cursor.caret = wc.len() as u32; @@ -132,7 +132,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget for TextBox<'w,E,T l.clipboard_set_text(text); if ee.key == EEKey::::X { - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let w = w.traitcast_mut::>().unwrap(); w.remove_selection(ctx); w.scroll_to_cursor(ctx,&b); @@ -142,7 +142,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget for TextBox<'w,E,T passed = true; }else if ee.key == EEKey::::UP || ee.key == EEKey::::DOWN { let b = b.clone(); - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let w = w.traitcast_mut::>().unwrap(); if ee.key == EEKey::::UP { @@ -163,7 +163,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget for TextBox<'w,E,T s.off.1 as i32 + ee.y, ); let off = s.bound_off((off.0.max(0) as u32, off.1.max(0) as u32)); - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let w = w.traitcast_mut::>().unwrap(); w.set(off,ctx); })); @@ -175,7 +175,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget for TextBox<'w,E,T let mouse_pressed = l.is_hovered() && l.state().is_pressed_and_id(&[EEKey::::MOUSE_LEFT],self.id.clone()).is_some(); let b = b.clone(); - l.mutate_closure(Box::new(move |mut w,ctx,_| { + l.mutate_closure_try(Box::new(move |mut w,ctx,_| { let w = w.traitcast_mut::>().unwrap(); w._m(mouse_down,mouse_pressed,mouse,b,ctx); if mouse_pressed {