Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old syntax #422

Merged
merged 1 commit into from
Sep 15, 2023
Merged
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
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
4 changes: 2 additions & 2 deletions core/src/animation/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::{ops::Deref, rc::Rc, time::Duration};
/// smoothly.
#[derive(Declare2, Clone, Debug, PartialEq)]
pub struct Transition<E: 'static> {
#[declare(default, convert=strip_option)]
#[declare(default)]
pub delay: Option<Duration>,
pub duration: Duration,
#[declare(strict)]
pub easing: E,
#[declare(default, convert=strip_option)]
#[declare(default)]
pub repeat: Option<f32>,
}

Expand Down
16 changes: 8 additions & 8 deletions core/src/builtin_widgets/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ pub enum VAlign {
}

/// A widget that align its child in x-axis, base on child's width.
#[derive(Declare, Declare2, SingleChild)]
#[derive(Declare2, SingleChild)]
pub struct HAlignWidget {
#[declare(default, builtin)]
pub h_align: HAlign,
}

/// A widget that align its child in y-axis, base on child's height.
#[derive(Declare, Declare2, SingleChild)]
#[derive(Declare2, SingleChild)]
pub struct VAlignWidget {
#[declare(default, builtin)]
pub v_align: VAlign,
Expand Down 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
48 changes: 24 additions & 24 deletions core/src/builtin_widgets/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ pub enum PositionUnit {
}

/// Widget use to anchor child constraints with the left edge of parent widget.
#[derive(Declare, Declare2, SingleChild)]
#[derive(Declare2, SingleChild)]
pub struct LeftAnchor {
#[declare(convert=into, builtin, default=0.)]
#[declare(builtin, default = 0.)]
pub left_anchor: PositionUnit,
}

/// Widget use to anchor child constraints with the right edge of parent widget.
#[derive(Declare, Declare2, SingleChild)]
#[derive(Declare2, SingleChild)]
pub struct RightAnchor {
#[declare(convert=into, builtin, default=0.)]
#[declare(builtin, default = 0.)]
pub right_anchor: PositionUnit,
}

/// Widget use to anchor child constraints with the top edge of parent widget.
#[derive(Declare, Declare2, SingleChild)]
#[derive(Declare2, SingleChild)]
pub struct TopAnchor {
#[declare(convert=into, builtin, default=0.)]
#[declare(builtin, default = 0.)]
pub top_anchor: PositionUnit,
}

/// Widget use to anchor child constraints with the bottom edge of parent
/// widget.
#[derive(Declare, Declare2, SingleChild)]
#[derive(Declare2, SingleChild)]
pub struct BottomAnchor {
#[declare(convert=into, builtin, default=0.)]
#[declare(builtin, default = 0.)]
pub bottom_anchor: PositionUnit,
}

Expand Down 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
51 changes: 12 additions & 39 deletions core/src/builtin_widgets/box_decoration.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::{impl_query_self_only, prelude::*};

/// The BoxDecoration provides a variety of ways to draw a box.
#[derive(SingleChild, Default, Clone, Declare, Declare2)]
#[derive(SingleChild, Default, Clone, Declare2)]
pub struct BoxDecoration {
/// The background of the box.
#[declare(builtin, default, convert=custom)]
#[declare(builtin, default)]
pub background: Option<Brush>,
/// A border to draw above the background
#[declare(builtin, default, convert=strip_option)]
#[declare(builtin, default)]
pub border: Option<Border>,
/// The corners of this box are rounded by this `BorderRadius`. The round
/// corner only work if the two borders beside it are same style.
#[declare(builtin, default, convert=strip_option)]
#[declare(builtin, default)]
pub border_radius: Option<Radius>,
}

Expand Down Expand Up @@ -61,35 +61,6 @@ impl Render for BoxDecoration {

impl_query_self_only!(BoxDecoration);

pub trait IntoBackground<M> {
fn into_background(self) -> Option<Brush>;
}

impl<T: Into<Brush>> IntoBackground<Brush> for T {
#[inline]
fn into_background(self) -> Option<Brush> { Some(self.into()) }
}

impl IntoBackground<Option<Brush>> for Option<Brush> {
#[inline]
fn into_background(self) -> Option<Brush> { self }
}

impl BoxDecorationDeclarer {
#[inline]
pub fn background<M>(mut self, b: impl IntoBackground<M>) -> Self {
self.background = Some(b.into_background());
self
}
}

impl BoxDecoration {
#[inline]
pub fn set_declare_background<M>(&mut self, b: impl IntoBackground<M>) {
self.background = b.into_background();
}
}

impl BoxDecoration {
fn paint_border(&self, painter: &mut Painter, rect: &Rect) {
if self.border.is_none() {
Expand Down Expand Up @@ -228,17 +199,19 @@ mod tests {
let dummy = std::mem::MaybeUninit::uninit();
// just for test, we know BoxDecoration not use `ctx` to build.
let ctx: BuildCtx<'static> = unsafe { dummy.assume_init() };
let w = BoxDecoration::declare_builder().build_declare(&ctx);
let w = BoxDecoration::declare2_builder().build_declare(&ctx);

assert_eq!(w.read().border, None);
assert_eq!(w.read().border_radius, None);
assert_eq!(w.read().background, None);

assert_eq!(w.border, None);
assert_eq!(w.border_radius, None);
assert_eq!(w.background, None);
std::mem::forget(ctx);
}

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
2 changes: 1 addition & 1 deletion core/src/builtin_widgets/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub enum ClipType {
Path(Path),
}

#[derive(SingleChild, Clone, Declare, Declare2)]
#[derive(SingleChild, Clone, Declare2)]
pub struct Clip {
#[declare(default)]
pub clip: ClipType,
Expand Down
16 changes: 8 additions & 8 deletions core/src/builtin_widgets/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use winit::window::CursorIcon;

/// `Cursor` is an attribute to assign an `cursor` to a widget.

#[derive(Declare, Default, Debug, Declare2)]
#[derive(Default, Debug, Declare2)]
pub struct Cursor {
#[declare(builtin, default)]
pub cursor: CursorIcon,
Expand Down 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
2 changes: 1 addition & 1 deletion core/src/builtin_widgets/delay_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{impl_query_self_only, prelude::*};
/// dropped.
///
/// It's useful when you need run a leave animation for a widget.
#[derive(Declare, Declare2)]
#[derive(Declare2)]
pub struct DelayDrop {
#[declare(builtin)]
pub delay_drop_until: bool,
Expand Down
6 changes: 3 additions & 3 deletions core/src/builtin_widgets/fitted_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum BoxFit {
}

/// Widget set how its child should be scale to fit its box.
#[derive(Declare, Declare2, SingleChild)]
#[derive(Declare2, SingleChild)]
pub struct FittedBox {
#[declare(builtin)]
pub box_fit: BoxFit,
Expand Down 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
Loading