Skip to content
Open
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
9 changes: 5 additions & 4 deletions api/cpp/include/slint.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,19 @@ inline SharedVector<float> solve_box_layout(const cbindgen_private::BoxLayoutDat
return result;
}

inline SharedVector<float> solve_grid_layout(const cbindgen_private::GridLayoutData &data)
inline SharedVector<float> solve_grid_layout(const cbindgen_private::GridLayoutData &data,
cbindgen_private::Orientation orientation)
{
SharedVector<float> result;
cbindgen_private::slint_solve_grid_layout(&data, &result);
cbindgen_private::slint_solve_grid_layout(&data, orientation, &result);
return result;
}

inline cbindgen_private::LayoutInfo
grid_layout_info(cbindgen_private::Slice<cbindgen_private::GridLayoutCellData> cells, float spacing,
const cbindgen_private::Padding &padding)
const cbindgen_private::Padding &padding, cbindgen_private::Orientation o)
{
return cbindgen_private::slint_grid_layout_info(cells, spacing, &padding);
return cbindgen_private::slint_grid_layout_info(cells, spacing, &padding, o);
}

inline cbindgen_private::LayoutInfo
Expand Down
15 changes: 8 additions & 7 deletions internal/compiler/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,19 @@ impl LayoutConstraints {
/// An element in a GridLayout
#[derive(Debug, Clone)]
pub struct GridLayoutElement {
pub col: u16,
pub row: u16,
pub colspan: u16,
pub rowspan: u16,
pub new_row: bool,
pub col_expr: Option<Expression>,
pub row_expr: Option<Expression>,
pub colspan_expr: Option<Expression>,
pub rowspan_expr: Option<Expression>,
pub item: LayoutItem,
}

impl GridLayoutElement {
pub fn col_or_row_and_span(&self, orientation: Orientation) -> (u16, u16) {
pub fn span(&self, orientation: Orientation) -> &Option<Expression> {
match orientation {
Orientation::Horizontal => (self.col, self.colspan),
Orientation::Vertical => (self.row, self.rowspan),
Orientation::Horizontal => &self.colspan_expr,
Orientation::Vertical => &self.rowspan_expr,
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion internal/compiler/llr/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,10 @@ impl<T> TypeResolutionContext for EvaluationContext<'_, T> {
&self.compilation_unit.sub_components[sub_component.sub_components[*i].ty];
}

sub_component.items[*item_index].ty.lookup_property(prop_name).unwrap()
sub_component.items[*item_index]
.ty
.lookup_property(prop_name)
.unwrap_or_else(|| panic!("property not found: {}", prop_name))
}
PropertyReference::InParent { level, parent_reference } => {
let mut ctx = self;
Expand Down
93 changes: 64 additions & 29 deletions internal/compiler/llr/lower_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,13 @@ fn compute_layout_info(
crate::layout::Layout::GridLayout(layout) => {
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, o, ctx);
let cells = grid_layout_cell_data(layout, o, ctx);
let orientation_literal = llr_Expression::EnumerationValue(EnumerationValue {
value: o as _,
enumeration: crate::typeregister::BUILTIN.with(|b| b.enums.Orientation.clone()),
});
llr_Expression::ExtraBuiltinFunctionCall {
function: "grid_layout_info".into(),
arguments: vec![cells, spacing, padding],
arguments: vec![cells, spacing, padding, orientation_literal],
return_ty: crate::typeregister::layout_info_type().into(),
}
}
Expand Down Expand Up @@ -643,6 +647,10 @@ fn solve_layout(
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, o, ctx);
let cells = grid_layout_cell_data(layout, o, ctx);
let size = layout_geometry_size(&layout.geometry.rect, o, ctx);
let orientation_expr = llr_Expression::EnumerationValue(EnumerationValue {
value: o as _,
enumeration: crate::typeregister::BUILTIN.with(|b| b.enums.Orientation.clone()),
});
if let (Some(button_roles), Orientation::Horizontal) = (&layout.dialog_button_roles, o)
{
let cells_ty = cells.ty(ctx);
Expand All @@ -669,37 +677,43 @@ fn solve_layout(
},
llr_Expression::ExtraBuiltinFunctionCall {
function: "solve_grid_layout".into(),
arguments: vec![make_struct(
"GridLayoutData",
[
("size", Type::Float32, size),
("spacing", Type::Float32, spacing),
("padding", padding.ty(ctx), padding),
(
"cells",
cells_ty.clone(),
llr_Expression::ReadLocalVariable {
name: "cells".into(),
ty: cells_ty,
},
),
],
)],
arguments: vec![
make_struct(
"GridLayoutData",
[
("size", Type::Float32, size),
("spacing", Type::Float32, spacing),
("padding", padding.ty(ctx), padding),
(
"cells",
cells_ty.clone(),
llr_Expression::ReadLocalVariable {
name: "cells".into(),
ty: cells_ty,
},
),
],
),
orientation_expr,
],
return_ty: Type::LayoutCache,
},
])
} else {
llr_Expression::ExtraBuiltinFunctionCall {
function: "solve_grid_layout".into(),
arguments: vec![make_struct(
"GridLayoutData",
[
("size", Type::Float32, size),
("spacing", Type::Float32, spacing),
("padding", padding.ty(ctx), padding),
("cells", cells.ty(ctx), cells),
],
)],
arguments: vec![
make_struct(
"GridLayoutData",
[
("size", Type::Float32, size),
("spacing", Type::Float32, spacing),
("padding", padding.ty(ctx), padding),
("cells", cells.ty(ctx), cells),
],
),
orientation_expr,
],
return_ty: Type::LayoutCache,
}
}
Expand Down Expand Up @@ -846,16 +860,36 @@ fn grid_layout_cell_data(
.elems
.iter()
.map(|c| {
let (col_or_row, span) = c.col_or_row_and_span(orientation);
let layout_info =
get_layout_info(&c.item.element, ctx, &c.item.constraints, orientation);

let mut lower_expr_or_default =
|expr: &Option<crate::expression_tree::Expression>, default: u16| {
expr.as_ref().map_or_else(
|| llr_Expression::NumberLiteral(default.into()),
|e| lower_expression(e, ctx),
)
};
// MAX means "auto", see to_layout_data()
let row_expr = lower_expr_or_default(&c.row_expr, u16::MAX);
let col_expr = lower_expr_or_default(&c.col_expr, u16::MAX);
let span_expr = lower_expr_or_default(&c.span(orientation), 1);

make_struct(
"GridLayoutCellData",
[
("constraint", crate::typeregister::layout_info_type().into(), layout_info),
("col_or_row", Type::Int32, llr_Expression::NumberLiteral(col_or_row as _)),
("span", Type::Int32, llr_Expression::NumberLiteral(span as _)),
("new_row", Type::Bool, llr_Expression::BoolLiteral(c.new_row)),
(
"col_or_row",
Type::Int32,
match orientation {
Orientation::Horizontal => col_expr,
Orientation::Vertical => row_expr.clone(),
},
),
("row", Type::Int32, row_expr),
("span", Type::Int32, span_expr),
],
)
})
Expand All @@ -867,6 +901,7 @@ fn grid_layout_cell_data(
pub(super) fn grid_layout_cell_data_ty() -> Type {
Type::Struct(Rc::new(Struct {
fields: IntoIterator::into_iter([
(SmolStr::new_static("new_row"), Type::Bool),
(SmolStr::new_static("col_or_row"), Type::Int32),
(SmolStr::new_static("span"), Type::Int32),
(SmolStr::new_static("constraint"), crate::typeregister::layout_info_type().into()),
Expand Down
Loading
Loading