Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Aug 19, 2023
1 parent 17fd9e5 commit f114631
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 106 deletions.
25 changes: 14 additions & 11 deletions examples/counter_redux_nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ fn main() {
rui(redux(AppState::new, reduce, |app_state| {
vstack((
format!("{}", app_state.count).padding(Auto),
state(|| 0, |handle, _| {
button("increment every 5 clicks", move|cx| {
cx[handle] += 1;
if cx[handle] == 5 {
cx[handle] = 0;
Action::Increment
} else {
Action::None
}
})
}),
state(
|| 0,
|handle, _| {
button("increment every 5 clicks", move |cx| {
cx[handle] += 1;
if cx[handle] == 5 {
cx[handle] = 0;
Action::Increment
} else {
Action::None
}
})
},
),
))
}));
}
10 changes: 6 additions & 4 deletions examples/counter_redux_redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ fn main() {
rui(redux(AppState::new, reduce, |app_state| {
vstack((
format!("{}", app_state.count).padding(Auto),
redux(|| LocalState{ count: 0 }, reduce_local, |_| {
button_a("increment every 5 clicks", LocalAction::Increment)
}),
redux(
|| LocalState { count: 0 },
reduce_local,
|_| button_a("increment every 5 clicks", LocalAction::Increment),
),
))
}));
}
}
6 changes: 4 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl Context {

// Get a new accesskit tree.
let mut nodes = vec![];

view.access(&mut path, self, &mut nodes);
assert_eq!(path.len(), 1);

Expand Down Expand Up @@ -334,7 +334,9 @@ impl Context {
pub(crate) fn update_layout(&mut self, path: &IdPath, layout_box: LayoutBox) {
match self.layout.get_mut(path) {
Some(bref) => *bref = layout_box,
None => { self.layout.insert(path.clone(), layout_box); }
None => {
self.layout.insert(path.clone(), layout_box);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/viewid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ pub fn hh<H: Hash>(index: &H) -> u64 {
let mut hasher = DefaultHasher::new();
index.hash(&mut hasher);
hasher.finish()
}
}
7 changes: 3 additions & 4 deletions src/views/anim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ where
(self.func)(cx, 1.0 / 60.0) // XXX: assume 60fps for now.
}


path.push(0);
self.child.process(event, path, cx, actions);
path.pop();
self.child.process(event, path, cx, actions);
path.pop();
}

fn draw(&self, path: &mut IdPath, args: &mut DrawArgs) {
Expand Down Expand Up @@ -86,7 +85,7 @@ path.pop();
path.push(0);
let node_id = self.child.access(path, cx, nodes);
path.pop();
node_id
node_id
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/views/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ where
let child_size = self.child.layout(path, args);
path.pop();
path.push(1);
self.background
.layout(path, &mut args.size(child_size));
self.background.layout(path, &mut args.size(child_size));
path.pop();
child_size
}
Expand Down
11 changes: 7 additions & 4 deletions src/views/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ where
}

fn layout(&self, path: &mut IdPath, args: &mut LayoutArgs) -> LocalSize {
args.cx.update_layout(path, LayoutBox {
rect: LocalRect::new(LocalPoint::zero(), args.sz),
offset: LocalOffset::zero(),
});
args.cx.update_layout(
path,
LayoutBox {
rect: LocalRect::new(LocalPoint::zero(), args.sz),
offset: LocalOffset::zero(),
},
);
args.sz
}

Expand Down
17 changes: 10 additions & 7 deletions src/views/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ where
actions: &mut Vec<Box<dyn Any>>,
) {
path.push(0);
self.child.process(event, path, cx, actions);
path.pop();
self.child.process(event, path, cx, actions);
path.pop();
}

fn draw(&self, path: &mut IdPath, args: &mut DrawArgs) {
Expand All @@ -49,10 +49,13 @@ path.pop();
path.push(0);
self.child.layout(path, args);
path.pop();
args.cx.update_layout(path, LayoutBox {
rect: LocalRect::new(LocalPoint::zero(), args.sz),
offset: LocalOffset::zero(),
});
args.cx.update_layout(
path,
LayoutBox {
rect: LocalRect::new(LocalPoint::zero(), args.sz),
offset: LocalOffset::zero(),
},
);
// XXX: should this expand to the available space?
args.sz
}
Expand Down Expand Up @@ -93,7 +96,7 @@ path.pop();
path.push(0);
let node_id = self.child.access(path, cx, nodes);
path.pop();
node_id
node_id
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/views/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ where
}
}
path.push(0);
self.child.process(event, path, cx, actions);
path.pop();
self.child.process(event, path, cx, actions);
path.pop();
}

fn draw(&self, path: &mut IdPath, args: &mut DrawArgs) {
Expand Down Expand Up @@ -277,8 +277,8 @@ where
});
}
path.push(0);
self.child.process(event, path, cx, actions);
path.pop();
self.child.process(event, path, cx, actions);
path.pop();
}

fn draw(&self, path: &mut IdPath, args: &mut DrawArgs) {
Expand Down Expand Up @@ -328,7 +328,7 @@ path.pop();
path.push(0);
let node_id = self.child.access(path, cx, nodes);
path.pop();
node_id
node_id
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/views/drag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where

actions.push(Box::new((self.func)(
cx,
[0.0,0.0].into(),
[0.0, 0.0].into(),
GestureState::Began,
cx.mouse_button,
)));
Expand Down Expand Up @@ -298,13 +298,12 @@ where
path.push(0);
let node_id = self.child.access(path, cx, nodes);
path.pop();
node_id
node_id
}
}

impl<V, F, B, T> private::Sealed for DragS<V, F, B, T> {}


#[cfg(test)]
mod tests {

Expand All @@ -316,12 +315,7 @@ mod tests {

let ui = state(
|| vec![],
|states, _| {
rectangle()
.drag(move |cx, _delta, state, _| {
cx[states].push(state)
})
},
|states, _| rectangle().drag(move |cx, _delta, state, _| cx[states].push(state)),
);
let sz = [100.0, 100.0].into();
let mut path = vec![0];
Expand Down Expand Up @@ -362,7 +356,13 @@ mod tests {
}
assert_eq!(path.len(), 1);

assert_eq!(cx[s], vec![GestureState::Began, GestureState::Changed, GestureState::Ended]);

assert_eq!(
cx[s],
vec![
GestureState::Began,
GestureState::Changed,
GestureState::Ended
]
);
}
}
}
4 changes: 2 additions & 2 deletions src/views/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ where
) {
let old = cx.set_env(&self.env_val);
path.push(0);
self.child.process(event, path, cx, actions);
path.pop();
self.child.process(event, path, cx, actions);
path.pop();
old.and_then(|s| cx.set_env(&s));
}

Expand Down
6 changes: 3 additions & 3 deletions src/views/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ where
actions: &mut Vec<Box<dyn Any>>,
) {
path.push(0);
self.child.process(event, path, cx, actions);
path.pop();
self.child.process(event, path, cx, actions);
path.pop();
}

fn draw(&self, path: &mut IdPath, args: &mut DrawArgs) {
Expand Down Expand Up @@ -69,7 +69,7 @@ path.pop();
path.push(0);
let node_id = self.child.access(path, cx, nodes);
path.pop();
node_id
node_id
}

fn is_flexible(&self) -> bool {
Expand Down
17 changes: 10 additions & 7 deletions src/views/geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ where
actions: &mut Vec<Box<dyn Any>>,
) {
path.push(0);
self.child.process(event, path, cx, actions);
path.pop();
self.child.process(event, path, cx, actions);
path.pop();
}

fn draw(&self, path: &mut IdPath, args: &mut DrawArgs) {
Expand All @@ -37,10 +37,13 @@ path.pop();
let sz = self.child.layout(path, args);
path.pop();

args.cx.update_layout(path, LayoutBox {
rect: LocalRect::new(LocalPoint::zero(), sz),
offset: LocalOffset::zero(),
});
args.cx.update_layout(
path,
LayoutBox {
rect: LocalRect::new(LocalPoint::zero(), sz),
offset: LocalOffset::zero(),
},
);

sz
}
Expand Down Expand Up @@ -80,7 +83,7 @@ path.pop();
path.push(0);
let node_id = self.child.access(path, cx, nodes);
path.pop();
node_id
node_id
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/views/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ where
) {
let mut child_actions = vec![];
path.push(0);
self.child
.process(event, path, cx, &mut child_actions);
self.child.process(event, path, cx, &mut child_actions);
path.pop();

for action in child_actions {
Expand Down Expand Up @@ -94,7 +93,7 @@ where
path.push(0);
let node_id = self.child.access(path, cx, nodes);
path.pop();
node_id
node_id
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ where
path.push(0);
let node_id = self.child.access(path, cx, nodes);
path.pop();
node_id
node_id
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ where
path.push(0);
let node_id = self.child.access(path, cx, nodes);
path.pop();
node_id
node_id
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/views/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ where
fn draw(&self, path: &mut IdPath, args: &mut DrawArgs) {
for child in &self.ids {
path.push(hh(child));
let offset = args.cx.layout.get(path).map(|b| b.offset).unwrap_or_default();
let offset = args
.cx
.layout
.get(path)
.map(|b| b.offset)
.unwrap_or_default();

args.vger.save();

Expand Down Expand Up @@ -90,7 +95,13 @@ where
match args.cx.layout.get_mut(path) {
Some(boxref) => boxref.offset = child_offset,
None => {
args.cx.layout.insert(path.clone(), LayoutBox { rect: LocalRect::default(), offset: child_offset });
args.cx.layout.insert(
path.clone(),
LayoutBox {
rect: LocalRect::default(),
offset: child_offset,
},
);
}
}

Expand Down Expand Up @@ -219,7 +230,10 @@ where
.collect();

builder.set_children(children);
nodes.push((hash(path).access_id(), builder.build(&mut cx.access_node_classes)));
nodes.push((
hash(path).access_id(),
builder.build(&mut cx.access_node_classes),
));
Some(hash(path).access_id())
}
}
Expand Down
Loading

0 comments on commit f114631

Please sign in to comment.