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
This commit is contained in:
Olivier Goffart 2022-01-18 11:15:52 +01:00 committed by Simon Hausmann
parent 4b0ae4d5a1
commit b36de552e5
3 changed files with 7 additions and 17 deletions

View file

@ -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));

View file

@ -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>,
}

View file

@ -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()),
},