Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/ctx/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ pub trait Queue<I,O> { //TODO probably remove mandatory StdEnqueueable bound
pub enum StdEnqueueable<E> where E: Env {
Render{force: bool},
Event{event: EEvent<E>, ts: u64},
MutateWidget{path: E::WidgetPath, f: fn(WidgetRefMut<E>,&mut E::Context,E::WidgetPath)},
MutateWidgetClosure{path: E::WidgetPath, f: Box<dyn FnOnce(WidgetRefMut<E>,&mut E::Context,E::WidgetPath)+'static>},
MutateWidget{path: E::WidgetPath, f: fn(Result<WidgetRefMut<E>,GuionError<E>>,&mut E::Context,E::WidgetPath)},
MutateWidgetClosure{path: E::WidgetPath, f: Box<dyn FnOnce(Result<WidgetRefMut<E>,GuionError<E>>,&mut E::Context,E::WidgetPath)+'static>},
MutateWidgetTry{path: E::WidgetPath, f: fn(WidgetRefMut<E>,&mut E::Context,E::WidgetPath)},
MutateWidgetClosureTry{path: E::WidgetPath, f: Box<dyn FnOnce(WidgetRefMut<E>,&mut E::Context,E::WidgetPath)+'static>},
MutateRoot{f: fn(&mut E::Storage,&mut E::Context)},
MutateRootClosure{f: Box<dyn FnOnce(&mut E::Storage,&mut E::Context)+'static>},
AccessWidget{path: E::WidgetPath, f: fn(WidgetRef<E>,&mut E::Context)},
AccessWidgetClosure{path: E::WidgetPath, f: Box<dyn FnOnce(WidgetRef<E>,&mut E::Context)+'static>},
AccessWidget{path: E::WidgetPath, f: fn(Result<WidgetRef<E>,GuionError<E>>,&mut E::Context)},
AccessWidgetClosure{path: E::WidgetPath, f: Box<dyn FnOnce(Result<WidgetRef<E>,GuionError<E>>,&mut E::Context)+'static>},
AccessWidgetTry{path: E::WidgetPath, f: fn(WidgetRef<E>,&mut E::Context)},
AccessWidgetClosureTry{path: E::WidgetPath, f: Box<dyn FnOnce(WidgetRef<E>,&mut E::Context)+'static>},
AccessRoot{f: fn(&E::Storage,&mut E::Context)},
AccessRootClosure{f: Box<dyn FnOnce(&E::Storage,&mut E::Context)+'static>},
MutMessage{path: E::WidgetPath, msg: E::Message},
Expand Down
52 changes: 44 additions & 8 deletions src/widget/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E>,&mut E::Context,E::WidgetPath)) {
pub fn mutate(&mut self, f: fn(Result<WidgetRefMut<E>,GuionError<E>>,&mut E::Context,E::WidgetPath)) {
self.mutate_at(f,StdOrder::PostCurrent,0)
}
#[inline]
pub fn mutate_at<O>(&mut self, f: fn(WidgetRefMut<E>,&mut E::Context,E::WidgetPath), o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,O> {
pub fn mutate_at<O>(&mut self, f: fn(Result<WidgetRefMut<E>,GuionError<E>>,&mut E::Context,E::WidgetPath), o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,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<dyn FnOnce(WidgetRefMut<E>,&mut E::Context,E::WidgetPath)+'static>) {
pub fn mutate_closure(&mut self, f: Box<dyn FnOnce(Result<WidgetRefMut<E>,GuionError<E>>,&mut E::Context,E::WidgetPath)+'static>) {
self.mutate_closure_at(f,StdOrder::PostCurrent,0)
}
#[inline]
pub fn mutate_closure_at<O>(&mut self, f: Box<dyn FnOnce(WidgetRefMut<E>,&mut E::Context,E::WidgetPath)+'static>, o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,O> {
pub fn mutate_closure_at<O>(&mut self, f: Box<dyn FnOnce(Result<WidgetRefMut<E>,GuionError<E>>,&mut E::Context,E::WidgetPath)+'static>, o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,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<E>,&mut E::Context,E::WidgetPath)) {
self.mutate_at_try(f,StdOrder::PostCurrent,0)
}
#[inline]
pub fn mutate_at_try<O>(&mut self, f: fn(WidgetRefMut<E>,&mut E::Context,E::WidgetPath), o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,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<dyn FnOnce(WidgetRefMut<E>,&mut E::Context,E::WidgetPath)+'static>) {
self.mutate_closure_at_try(f,StdOrder::PostCurrent,0)
}
#[inline]
pub fn mutate_closure_at_try<O>(&mut self, f: Box<dyn FnOnce(WidgetRefMut<E>,&mut E::Context,E::WidgetPath)+'static>, o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,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) {
Expand All @@ -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<E>,&mut E::Context)) {
pub fn later(&mut self, f: fn(Result<WidgetRef<E>,GuionError<E>>,&mut E::Context)) {
self.later_at(f,StdOrder::PostCurrent,0)
}
#[inline]
pub fn later_at<O>(&mut self, f: fn(WidgetRef<E>,&mut E::Context), o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,O> {
pub fn later_at<O>(&mut self, f: fn(Result<WidgetRef<E>,GuionError<E>>,&mut E::Context), o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,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<dyn FnOnce(WidgetRef<E>,&mut E::Context)+Sync>) {
pub fn later_closure(&mut self, f: Box<dyn FnOnce(Result<WidgetRef<E>,GuionError<E>>,&mut E::Context)+Sync>) {
self.later_closure_at(f,StdOrder::PostCurrent,0)
}
#[inline]
pub fn later_closure_at<O>(&mut self, f: Box<dyn FnOnce(WidgetRef<E>,&mut E::Context)+Sync>, o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,O> {
pub fn later_closure_at<O>(&mut self, f: Box<dyn FnOnce(Result<WidgetRef<E>,GuionError<E>>,&mut E::Context)+Sync>, o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,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<E>,&mut E::Context)) {
self.later_at_try(f,StdOrder::PostCurrent,0)
}
#[inline]
pub fn later_at_try<O>(&mut self, f: fn(WidgetRef<E>,&mut E::Context), o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,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<dyn FnOnce(WidgetRef<E>,&mut E::Context)+Sync>) {
self.later_closure_at_try(f,StdOrder::PostCurrent,0)
}
#[inline]
pub fn later_closure_at_try<O>(&mut self, f: Box<dyn FnOnce(WidgetRef<E>,&mut E::Context)+Sync>, o: O, p: i64) where ECQueue<E>: Queue<StdEnqueueable<E>,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)
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/area/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'w,E,W,Scroll> Widget<E> for Area<'w,E,W,Scroll> where
ee.key == EEKey::<E>::UP || ee.key == EEKey::<E>::DOWN ||
ee.key == EEKey::<E>::LEFT || ee.key == EEKey::<E>::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::<dyn AtomStateMut<E,(u32,u32)>>().unwrap();
let mut v = w.get(ctx);
if ee.key == EEKey::<E>::UP {
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/checkbox/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'w,E,State,Text> CheckBox<'w,E,State,Text> where
Text: AsWidget<E>,
{
pub fn set(mut l: Link<E>, v: bool) {
l.mutate_closure(Box::new(move |mut w,c,_|{
l.mutate_closure_try(Box::new(move |mut w,c,_|{
//w.traitcast_mut::<dyn AtomStateMut<E,bool>>().unwrap().set(v,c);
let w = w.traitcast_mut::<dyn ICheckBoxMut<E>>().unwrap();
w.state_mut().set(v,c);
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/label/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'w,E,Text,GlyphCache> Label<'w,E,Text,GlyphCache> where
let glyphs = Arc::new(ESGlyphs::<E>::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::<dyn ValidationMut<E>>().unwrap();
let key = vali.validate();
let cache = w.traitcast_mut::<dyn AtomStateMut<E,LocalGlyphCache<E>>>().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/splitpane/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'w,E,L,R,V> Widget<E> 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::<dyn AtomStateMut<E,f32>>().unwrap();
w.set(fcx,c);
}));
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/textbox/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> TextBox<'w,E,Text,Scroll,Cur
let glyphs = Arc::new(ESGlyphs::<E>::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::<dyn ValidationMut<E>>().unwrap();
let key = vali.validate();
let cache = w.traitcast_mut::<dyn AtomStateMut<E,LocalGlyphCache<E>>>().unwrap();
Expand Down
14 changes: 7 additions & 7 deletions src/widgets/textbox/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget<E> 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::<dyn ITextBoxMut<E>>().unwrap();
w.insert_text(&s,ctx);
w.scroll_to_cursor(ctx,&b);
Expand All @@ -83,7 +83,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget<E> for TextBox<'w,E,T
{
let ctrl = l.state().is_pressed(&[EEKey::<E>::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::<dyn ITextBoxMut<E>>().unwrap();
if ee.key == EEKey::<E>::BACKSPACE {
w.remove_selection_or_n(1,ctx);
Expand All @@ -101,7 +101,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget<E> for TextBox<'w,E,T
}));
passed = true;
}else if ee.key == EEKey::<E>::A && l.state().is_pressed(&[EEKey::<E>::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::<dyn CaptionMut<E>>().unwrap();
cursor.select = 0;
cursor.caret = wc.len() as u32;
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget<E> for TextBox<'w,E,T
l.clipboard_set_text(text);

if ee.key == EEKey::<E>::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::<dyn ITextBoxMut<E>>().unwrap();
w.remove_selection(ctx);
w.scroll_to_cursor(ctx,&b);
Expand All @@ -142,7 +142,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget<E> for TextBox<'w,E,T
passed = true;
}else if ee.key == EEKey::<E>::UP || ee.key == EEKey::<E>::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::<dyn ITextBoxMut<E>>().unwrap();

if ee.key == EEKey::<E>::UP {
Expand All @@ -163,7 +163,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget<E> 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::<dyn AtomStateMut<E,(u32,u32)>>().unwrap();
w.set(off,ctx);
}));
Expand All @@ -175,7 +175,7 @@ impl<'w,E,Text,Scroll,Curs,CursorStickX,GlyphCache> Widget<E> for TextBox<'w,E,T
let mouse_pressed = l.is_hovered() && l.state().is_pressed_and_id(&[EEKey::<E>::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::<dyn ITextBoxMut<E>>().unwrap();
w._m(mouse_down,mouse_pressed,mouse,b,ctx);
if mouse_pressed {
Expand Down