Skip to content

Commit

Permalink
refactor(ribir): 💡 migrate full project to new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Sep 15, 2023
1 parent 40cb202 commit fe40eec
Show file tree
Hide file tree
Showing 66 changed files with 501 additions and 938 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ serde_json = "1.0.82"
smallvec = "1.8.0"
syn = "1.0.109"
tiny-skia-path = {version = "0.11.0"}
trybuild = "1.0.77"
unicode-bidi = "0.3.7"
unicode-script = "0.5.4"
unicode-segmentation = "1.9.0"
Expand Down
12 changes: 6 additions & 6 deletions core/src/builtin_widgets/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ mod tests {
const WND_SIZE: Size = Size::new(100., 100.);

fn h_align(h_align: HAlign) -> Widget {
widget! {
HAlignWidget {
fn_widget! {
@HAlignWidget {
h_align,
MockBox { size: CHILD_SIZE }
@MockBox { size: CHILD_SIZE }
}
}
.into()
Expand Down Expand Up @@ -203,10 +203,10 @@ mod tests {
);

fn v_align(v_align: VAlign) -> Widget {
widget! {
VAlignWidget {
fn_widget! {
@VAlignWidget {
v_align,
MockBox { size: CHILD_SIZE }
@MockBox { size: CHILD_SIZE }
}
}
.into()
Expand Down
32 changes: 16 additions & 16 deletions core/src/builtin_widgets/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ mod test {
const WND_SIZE: Size = Size::new(100., 100.);

fn pixel_left_top() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: CHILD_SIZE,
left_anchor: 1.,
top_anchor: 1.,
Expand All @@ -158,8 +158,8 @@ mod test {
);

fn pixel_left_bottom() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: CHILD_SIZE,
left_anchor: 1.,
bottom_anchor: 1.,
Expand All @@ -175,8 +175,8 @@ mod test {
);

fn pixel_top_right() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: CHILD_SIZE,
right_anchor: 1.,
top_anchor: 1.,
Expand All @@ -192,8 +192,8 @@ mod test {
);

fn pixel_bottom_right() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: CHILD_SIZE,
right_anchor: 1.,
bottom_anchor: 1.,
Expand All @@ -209,8 +209,8 @@ mod test {
);

fn percent_left_top() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: CHILD_SIZE,
left_anchor: Percent(10.),
top_anchor: Percent(10.),
Expand All @@ -226,8 +226,8 @@ mod test {
);

fn percent_left_bottom() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: CHILD_SIZE,
left_anchor: Percent( 10.),
bottom_anchor: Percent( 10.),
Expand All @@ -243,8 +243,8 @@ mod test {
}

fn percent_top_right() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: CHILD_SIZE,
right_anchor: Percent(10.),
top_anchor: Percent(10.),
Expand All @@ -260,8 +260,8 @@ mod test {
);

fn percent_bottom_right() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: CHILD_SIZE,
right_anchor: Percent(10.),
bottom_anchor: Percent(10.),
Expand Down
4 changes: 2 additions & 2 deletions core/src/builtin_widgets/box_decoration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ mod tests {

const SIZE: Size = Size::new(100., 100.);
fn with_border() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: SIZE,
border: Border {
left: BorderSide::new(1., Color::BLACK.into()),
Expand Down
14 changes: 7 additions & 7 deletions core/src/builtin_widgets/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ impl Cursor {
#[cfg(test)]
mod tests {
use super::*;
use crate::test_helper::*;
use crate::{reset_test_env, test_helper::*};
use winit::event::{DeviceId, WindowEvent};

#[test]
fn tree_down_up() {
let _guard = unsafe { AppCtx::new_lock_scope() };
reset_test_env!();

let row_tree = widget! {
MockBox {
let row_tree = fn_widget! {
@MockBox {
size: Size::new(f32::INFINITY, f32::INFINITY),
cursor: CursorIcon::AllScroll,
MockMulti{
MockBox {
@MockMulti{
@MockBox {
size: Size::new(200., 200.),
cursor: CursorIcon::Hand,
MockBox {
@MockBox {
size: Size::new(100., 100.),
cursor: CursorIcon::Help,
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/builtin_widgets/fitted_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ mod tests {
}

fn as_builtin_field() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
size: Size::new(200., 200.),
box_fit: BoxFit::Fill,
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/builtin_widgets/focus_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ impl_query_self_only!(RequestFocus);
#[cfg(test)]
mod tests {
use super::*;
use crate::test_helper::*;
use crate::{reset_test_env, test_helper::*};

#[test]
fn dynamic_focus_node() {
let _guard = unsafe { AppCtx::new_lock_scope() };
reset_test_env!();

#[derive(Declare)]
#[derive(Declare, Declare2)]
struct AutoFocusNode {}

impl ComposeChild for AutoFocusNode {
Expand All @@ -151,11 +151,11 @@ mod tests {
dynamic_compose_focus_node(child)
}
}
let widget = widget! {
AutoFocusNode{
AutoFocusNode{
AutoFocusNode {
MockBox {
let widget = fn_widget! {
@AutoFocusNode{
@AutoFocusNode{
@AutoFocusNode {
@MockBox {
size: Size::default(),
}
}
Expand Down
74 changes: 37 additions & 37 deletions core/src/builtin_widgets/focus_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ impl_query_self_only!(FocusScope);

#[cfg(test)]
mod tests {
use std::{cell::RefCell, rc::Rc};

use winit::{
dpi::LogicalPosition,
event::{DeviceId, ElementState, KeyboardInput, MouseButton, WindowEvent},
Expand All @@ -46,19 +44,19 @@ mod tests {
let _guard = unsafe { AppCtx::new_lock_scope() };

let size = Size::zero();
let widget = widget! {
MockMulti {
MockBox { size, tab_index: 0, auto_focus: true }
FocusScope {
let widget = fn_widget! {
@MockMulti {
@MockBox { size, tab_index: 0i16, auto_focus: true }
@FocusScope {
skip_descendants: false,
tab_index: 3,
MockMulti {
MockBox { size, tab_index: 1, }
MockBox { size, tab_index: 2, }
MockBox { size, tab_index: 3, }
tab_index: 3i16,
@MockMulti {
@MockBox { size, tab_index: 1i16, }
@MockBox { size, tab_index: 2i16, }
@MockBox { size, tab_index: 3i16, }
}
}
MockBox { size, tab_index: 1 }
@MockBox { size, tab_index: 1i16 }
}
};

Expand Down Expand Up @@ -105,20 +103,20 @@ mod tests {
let _guard = unsafe { AppCtx::new_lock_scope() };

let size = Size::zero();
let widget = widget! {
MockMulti {
MockBox { size, tab_index: 0, auto_focus: true }
FocusScope {
let widget = fn_widget! {
@MockMulti {
@MockBox { size, tab_index: 0i16, auto_focus: true }
@FocusScope {
can_focus: true,
skip_descendants: true,
tab_index: 3,
MockMulti {
MockBox { size, tab_index: 1, }
MockBox { size, tab_index: 2, }
MockBox { size, tab_index: 3, }
tab_index: 3i16,
@MockMulti {
@MockBox { size, tab_index: 1i16, }
@MockBox { size, tab_index: 2i16, }
@MockBox { size, tab_index: 3i16, }
}
}
MockBox { size, tab_index: 1 }
@MockBox { size, tab_index: 1i16 }
}
};

Expand Down Expand Up @@ -154,22 +152,24 @@ mod tests {
let _guard = unsafe { AppCtx::new_lock_scope() };

let size = Size::new(50., 50.);
let tap_cnt = Rc::new(RefCell::new(0));
let result = tap_cnt.clone();
let widget = widget! {
init {
let tap_cnt2 = tap_cnt.clone();
}
MockMulti {
FocusScope {
id: host,
can_focus: false,
on_key_down: move |_| *tap_cnt.borrow_mut() += 1,
MockMulti {
MockBox { size, on_key_down: move |_| *tap_cnt2.borrow_mut() += 1, }
let tap_cnt = Stateful::new(0);
let result = tap_cnt.clone_reader();
let widget = fn_widget! {
let mut host = @FocusScope {
can_focus: false,
on_key_down: move |_| *$tap_cnt.write() += 1,
};
let request_focus_box = @MockBox {
size,
on_pointer_down: move |_| $host.request_focus()
};
@MockMulti {
@$host {
@MockMulti {
@MockBox { size, on_key_down: move |_| *$tap_cnt.write() += 1, }
}
}
MockBox { size, on_pointer_down: move |_| host.request_focus(),}
@ { request_focus_box }
}
};

Expand Down Expand Up @@ -208,6 +208,6 @@ mod tests {

wnd.run_frame_tasks();
wnd.draw_frame();
assert_eq!(*result.borrow(), 2);
assert_eq!(*result.read(), 2);
}
}
12 changes: 5 additions & 7 deletions core/src/builtin_widgets/layout_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ mod tests {
use ribir_dev_helper::*;

fn smoke() -> Widget {
widget! {
MockMulti {
LayoutBox {
id: layout_box,
MockBox { size: Size::new(100., 200.) }
}
MockBox { size: layout_box.rect.size }
fn_widget! {
let mut first_box = @MockBox { size: Size::new(100., 200.) };
let second_box = @MockBox { size: pipe!($first_box.layout_size()) };
@MockMulti {
@ { [first_box, second_box ] }
}
}
.into()
Expand Down
4 changes: 2 additions & 2 deletions core/src/builtin_widgets/margin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ mod tests {
use ribir_dev_helper::*;

fn smoke() -> Widget {
widget! {
MockBox {
fn_widget! {
@MockBox {
margin: EdgeInsets::symmetrical(1., 1.),
size: Size::new(100., 100.)
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/builtin_widgets/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ mod tests {
use ribir_dev_helper::*;

fn smoke() -> Widget {
widget! {
MockMulti {
fn_widget! {
@MockMulti {
padding: EdgeInsets::only_left(1.),
MockBox {
@MockBox {
size: Size::new(100., 100.),
}
}
Expand Down
Loading

0 comments on commit fe40eec

Please sign in to comment.