From b36de552e562f65a407fb539ff329f9cc79b28f0 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 18 Jan 2022 11:15:52 +0100 Subject: [PATCH] Pass the Padding by value in the layout data struct It can simply be a Copy type anyway. So there is no more special code needed in the rust (and also in C++) generator for it --- sixtyfps_compiler/generator/rust.rs | 14 ++------------ sixtyfps_runtime/corelib/layout.rs | 6 +++--- sixtyfps_runtime/interpreter/eval_layout.rs | 4 ++-- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/sixtyfps_compiler/generator/rust.rs b/sixtyfps_compiler/generator/rust.rs index 054055b19..ede797fd7 100644 --- a/sixtyfps_compiler/generator/rust.rs +++ b/sixtyfps_compiler/generator/rust.rs @@ -1529,18 +1529,8 @@ fn compile_expression(expr: &Expression, ctx: &EvaluationContext) -> TokenStream } } Expression::Struct { ty, values } => { - if let Type::Struct { fields, name, node } = ty { - let elem = fields.keys().map(|k| { - values.get(k).map(|e| { - let e = compile_expression(e, ctx); - if node.is_none() && k == "padding" { - // FIXME: it would be nice if we didn't have to handle this field specially - quote!(&#e) - } else { - e - } - }) - }); + if let Type::Struct { fields, name, .. } = ty { + let elem = fields.keys().map(|k| values.get(k).map(|e| compile_expression(e, ctx))); if let Some(name) = name { let name_tokens: TokenStream = struct_name_to_tokens(name.as_str()); let keys = fields.keys().map(|k| ident(k)); diff --git a/sixtyfps_runtime/corelib/layout.rs b/sixtyfps_runtime/corelib/layout.rs index f1fcdff4e..2d5aa0898 100644 --- a/sixtyfps_runtime/corelib/layout.rs +++ b/sixtyfps_runtime/corelib/layout.rs @@ -334,7 +334,7 @@ impl Default for Constraint { } #[repr(C)] -#[derive(Debug, Default)] +#[derive(Copy, Clone, Debug, Default)] pub struct Padding { pub begin: Coord, pub end: Coord, @@ -345,7 +345,7 @@ pub struct Padding { pub struct GridLayoutData<'a> { pub size: Coord, pub spacing: Coord, - pub padding: &'a Padding, + pub padding: Padding, pub cells: Slice<'a, GridLayoutCellData>, } @@ -432,7 +432,7 @@ impl Default for LayoutAlignment { pub struct BoxLayoutData<'a> { pub size: Coord, pub spacing: Coord, - pub padding: &'a Padding, + pub padding: Padding, pub alignment: LayoutAlignment, pub cells: Slice<'a, BoxLayoutCellData>, } diff --git a/sixtyfps_runtime/interpreter/eval_layout.rs b/sixtyfps_runtime/interpreter/eval_layout.rs index d0250f014..bb119bd17 100644 --- a/sixtyfps_runtime/interpreter/eval_layout.rs +++ b/sixtyfps_runtime/interpreter/eval_layout.rs @@ -104,7 +104,7 @@ pub(crate) fn solve_layout( core_layout::solve_grid_layout(&core_layout::GridLayoutData { size: size_ref.map(expr_eval).unwrap_or(0.), spacing, - padding: &padding, + padding, cells: Slice::from(cells.as_slice()), }) .into() @@ -128,7 +128,7 @@ pub(crate) fn solve_layout( &core_layout::BoxLayoutData { size: size_ref.as_ref().map(expr_eval).unwrap_or(0.), spacing, - padding: &padding, + padding, alignment, cells: Slice::from(cells.as_slice()), },