Skip to content

Commit 7dc7451

Browse files
committed
Move reordering of dialog buttons to the organize step
This repairs the feature of reordering buttons, which was temporarily left out in the previous commit.
1 parent cde5ec7 commit 7dc7451

File tree

9 files changed

+159
-161
lines changed

9 files changed

+159
-161
lines changed

api/cpp/include/slint.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ organize_grid_layout(cbindgen_private::Slice<cbindgen_private::GridLayoutInputDa
131131
return result;
132132
}
133133

134+
inline SharedVector<float>
135+
organize_dialog_button_layout(cbindgen_private::Slice<cbindgen_private::GridLayoutInputData> input_data,
136+
cbindgen_private::Slice<DialogButtonRole> dialog_button_roles)
137+
{
138+
SharedVector<float> result;
139+
cbindgen_private::slint_organize_dialog_button_layout(input_data, dialog_button_roles, &result);
140+
return result;
141+
}
142+
134143
inline SharedVector<float>
135144
solve_grid_layout(const cbindgen_private::GridLayoutData &data,
136145
cbindgen_private::Slice<cbindgen_private::LayoutInfo> constraints,

internal/compiler/generator/cpp.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,23 +3555,6 @@ fn compile_expression(expr: &llr::Expression, ctx: &EvaluationContext) -> String
35553555
sub_expression,
35563556
ctx,
35573557
),
3558-
Expression::ComputeDialogLayoutCells { cells_variable, roles, unsorted_cells } => {
3559-
let cells_variable = ident(cells_variable);
3560-
let mut cells = match &**unsorted_cells {
3561-
Expression::Array { values, .. } => {
3562-
values.iter().map(|v| compile_expression(v, ctx))
3563-
}
3564-
_ => panic!("dialog layout unsorted cells not an array"),
3565-
};
3566-
format!("slint::cbindgen_private::GridLayoutCellData {cv}_array [] = {{ {c} }};\
3567-
slint::cbindgen_private::slint_reorder_dialog_button_layout({cv}_array, {r});\
3568-
slint::cbindgen_private::Slice<slint::cbindgen_private::GridLayoutCellData> {cv} = slint::private_api::make_slice(std::span({cv}_array))",
3569-
r = compile_expression(roles, ctx),
3570-
cv = cells_variable,
3571-
c = cells.join(", "),
3572-
)
3573-
3574-
}
35753558
Expression::MinMax { ty, op, lhs, rhs } => {
35763559
let ident = match op {
35773560
MinMaxOp::Min => "min",

internal/compiler/generator/rust.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,21 +2711,6 @@ fn compile_expression(expr: &Expression, ctx: &EvaluationContext) -> TokenStream
27112711
sub_expression,
27122712
ctx,
27132713
),
2714-
Expression::ComputeDialogLayoutCells { cells_variable, roles, unsorted_cells } => {
2715-
let cells_variable = ident(cells_variable);
2716-
let roles = compile_expression(roles, ctx);
2717-
let cells = match &**unsorted_cells {
2718-
Expression::Array { values, .. } => {
2719-
values.iter().map(|v| compile_expression(v, ctx))
2720-
}
2721-
_ => panic!("dialog layout unsorted cells not an array"),
2722-
};
2723-
quote! {
2724-
let mut #cells_variable = [#(#cells),*];
2725-
sp::reorder_dialog_button_layout(&mut #cells_variable, &#roles);
2726-
let #cells_variable = sp::Slice::from_slice(&#cells_variable);
2727-
}
2728-
}
27292714
Expression::MinMax { ty, op, lhs, rhs } => {
27302715
let lhs = compile_expression(lhs, ctx);
27312716
let t = rust_primitive_type(ty);

internal/compiler/llr/expression.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,6 @@ pub enum Expression {
184184
orientation: Orientation,
185185
sub_expression: Box<Expression>,
186186
},
187-
188-
ComputeDialogLayoutCells {
189-
/// The local variable where the slice of cells is going to be stored
190-
cells_variable: String,
191-
roles: Box<Expression>,
192-
/// This is an Expression::Array
193-
unsorted_cells: Box<Expression>,
194-
},
195-
196187
MinMax {
197188
ty: Type,
198189
op: MinMaxOp,
@@ -320,9 +311,6 @@ impl Expression {
320311
Self::EnumerationValue(e) => Type::Enumeration(e.enumeration.clone()),
321312
Self::LayoutCacheAccess { .. } => Type::LogicalLength,
322313
Self::BoxLayoutFunction { sub_expression, .. } => sub_expression.ty(ctx),
323-
Self::ComputeDialogLayoutCells { .. } => {
324-
Type::Array(super::lower_expression::grid_layout_cell_data_ty().into())
325-
}
326314
Self::MinMax { ty, .. } => ty.clone(),
327315
Self::EmptyComponentFactory => Type::ComponentFactory,
328316
Self::TranslationReference { .. } => Type::String,
@@ -406,10 +394,6 @@ macro_rules! visit_impl {
406394
$visitor(sub_expression);
407395
elements.$iter().filter_map(|x| x.$as_ref().left()).for_each($visitor);
408396
}
409-
Expression::ComputeDialogLayoutCells { roles, unsorted_cells, .. } => {
410-
$visitor(roles);
411-
$visitor(unsorted_cells);
412-
}
413397
Expression::MinMax { ty: _, op: _, lhs, rhs } => {
414398
$visitor(lhs);
415399
$visitor(rhs);

internal/compiler/llr/lower_expression.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,34 @@ fn organize_grid_layout(
667667
ctx: &mut ExpressionLoweringCtx,
668668
) -> llr_Expression {
669669
let cells = grid_layout_input_data(layout, ctx);
670-
llr_Expression::ExtraBuiltinFunctionCall {
671-
function: "organize_grid_layout".into(),
672-
arguments: vec![cells],
673-
return_ty: Type::Array(Type::Int32.into()),
670+
671+
if let Some(button_roles) = &layout.dialog_button_roles {
672+
let e = crate::typeregister::BUILTIN.with(|e| e.enums.DialogButtonRole.clone());
673+
let roles = button_roles
674+
.iter()
675+
.map(|r| {
676+
llr_Expression::EnumerationValue(EnumerationValue {
677+
value: e.values.iter().position(|x| x == r).unwrap() as _,
678+
enumeration: e.clone(),
679+
})
680+
})
681+
.collect();
682+
let roles_expr = llr_Expression::Array {
683+
element_ty: Type::Enumeration(e),
684+
values: roles,
685+
as_model: false,
686+
};
687+
llr_Expression::ExtraBuiltinFunctionCall {
688+
function: "organize_dialog_button_layout".into(),
689+
arguments: vec![cells, roles_expr],
690+
return_ty: Type::Array(Type::Int32.into()),
691+
}
692+
} else {
693+
llr_Expression::ExtraBuiltinFunctionCall {
694+
function: "organize_grid_layout".into(),
695+
arguments: vec![cells],
696+
return_ty: Type::Array(Type::Int32.into()),
697+
}
674698
}
675699
}
676700

@@ -899,20 +923,6 @@ fn grid_layout_input_data(
899923
}
900924
}
901925

902-
pub(super) fn grid_layout_cell_data_ty() -> Type {
903-
Type::Struct(Rc::new(Struct {
904-
fields: IntoIterator::into_iter([
905-
(SmolStr::new_static("col_or_row"), Type::Int32),
906-
(SmolStr::new_static("span"), Type::Int32),
907-
(SmolStr::new_static("constraint"), crate::typeregister::layout_info_type().into()),
908-
])
909-
.collect(),
910-
name: Some("GridLayoutCellData".into()),
911-
node: None,
912-
rust_attributes: None,
913-
}))
914-
}
915-
916926
pub(super) fn grid_layout_input_data_ty() -> Type {
917927
Type::Struct(Rc::new(Struct {
918928
fields: IntoIterator::into_iter([

internal/compiler/llr/optim_passes/inline_expressions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ fn expression_cost(exp: &Expression, ctx: &EvaluationContext) -> isize {
6767
Expression::EnumerationValue(_) => 0,
6868
Expression::LayoutCacheAccess { .. } => PROPERTY_ACCESS_COST,
6969
Expression::BoxLayoutFunction { .. } => return isize::MAX,
70-
Expression::ComputeDialogLayoutCells { .. } => return isize::MAX,
7170
Expression::MinMax { .. } => 10,
7271
Expression::EmptyComponentFactory => 10,
7372
Expression::TranslationReference { .. } => PROPERTY_ACCESS_COST + 2 * ALLOC_COST,

internal/compiler/llr/pretty_print.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,6 @@ impl<'a, T> Display for DisplayExpression<'a, T> {
362362
write!(f, "{}[{} % {}]", DisplayPropertyRef(layout_cache_prop, ctx), index, e(ri))
363363
}
364364
Expression::BoxLayoutFunction { .. } => write!(f, "BoxLayoutFunction(TODO)",),
365-
Expression::ComputeDialogLayoutCells { .. } => {
366-
write!(f, "ComputeDialogLayoutCells(TODO)",)
367-
}
368365
Expression::MinMax { ty: _, op, lhs, rhs } => match op {
369366
MinMaxOp::Min => write!(f, "min({}, {})", e(lhs), e(rhs)),
370367
MinMaxOp::Max => write!(f, "max({}, {})", e(lhs), e(rhs)),

0 commit comments

Comments
 (0)