Skip to content

Commit 804ca74

Browse files
dfaure-kdabogoffart
authored andcommitted
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 8ae28ad commit 804ca74

File tree

10 files changed

+159
-164
lines changed

10 files changed

+159
-164
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> organize_dialog_button_layout(
135+
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
@@ -3664,23 +3664,6 @@ fn compile_expression(expr: &llr::Expression, ctx: &EvaluationContext) -> String
36643664
sub_expression,
36653665
ctx,
36663666
),
3667-
Expression::ComputeDialogLayoutCells { cells_variable, roles, unsorted_cells } => {
3668-
let cells_variable = ident(cells_variable);
3669-
let mut cells = match &**unsorted_cells {
3670-
Expression::Array { values, .. } => {
3671-
values.iter().map(|v| compile_expression(v, ctx))
3672-
}
3673-
_ => panic!("dialog layout unsorted cells not an array"),
3674-
};
3675-
format!(
3676-
"slint::cbindgen_private::GridLayoutCellData {cv}_array [] = {{ {c} }};\
3677-
slint::cbindgen_private::slint_reorder_dialog_button_layout({cv}_array, {r});\
3678-
slint::cbindgen_private::Slice<slint::cbindgen_private::GridLayoutCellData> {cv} = slint::private_api::make_slice(std::span({cv}_array))",
3679-
r = compile_expression(roles, ctx),
3680-
cv = cells_variable,
3681-
c = cells.join(", "),
3682-
)
3683-
}
36843667
Expression::MinMax { ty, op, lhs, rhs } => {
36853668
let ident = match op {
36863669
MinMaxOp::Min => "min",

internal/compiler/generator/rust.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,21 +2710,6 @@ fn compile_expression(expr: &Expression, ctx: &EvaluationContext) -> TokenStream
27102710
sub_expression,
27112711
ctx,
27122712
),
2713-
Expression::ComputeDialogLayoutCells { cells_variable, roles, unsorted_cells } => {
2714-
let cells_variable = ident(cells_variable);
2715-
let roles = compile_expression(roles, ctx);
2716-
let cells = match &**unsorted_cells {
2717-
Expression::Array { values, .. } => {
2718-
values.iter().map(|v| compile_expression(v, ctx))
2719-
}
2720-
_ => panic!("dialog layout unsorted cells not an array"),
2721-
};
2722-
quote! {
2723-
let mut #cells_variable = [#(#cells),*];
2724-
sp::reorder_dialog_button_layout(&mut #cells_variable, &#roles);
2725-
let #cells_variable = sp::Slice::from_slice(&#cells_variable);
2726-
}
2727-
}
27282713
Expression::MinMax { ty, op, lhs, rhs } => {
27292714
let lhs = compile_expression(lhs, ctx);
27302715
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
@@ -186,15 +186,6 @@ pub enum Expression {
186186
orientation: Orientation,
187187
sub_expression: Box<Expression>,
188188
},
189-
190-
ComputeDialogLayoutCells {
191-
/// The local variable where the slice of cells is going to be stored
192-
cells_variable: String,
193-
roles: Box<Expression>,
194-
/// This is an Expression::Array
195-
unsorted_cells: Box<Expression>,
196-
},
197-
198189
MinMax {
199190
ty: Type,
200191
op: MinMaxOp,
@@ -322,9 +313,6 @@ impl Expression {
322313
Self::EnumerationValue(e) => Type::Enumeration(e.enumeration.clone()),
323314
Self::LayoutCacheAccess { .. } => Type::LogicalLength,
324315
Self::BoxLayoutFunction { sub_expression, .. } => sub_expression.ty(ctx),
325-
Self::ComputeDialogLayoutCells { .. } => {
326-
Type::Array(super::lower_expression::grid_layout_cell_data_ty().into())
327-
}
328316
Self::MinMax { ty, .. } => ty.clone(),
329317
Self::EmptyComponentFactory => Type::ComponentFactory,
330318
Self::TranslationReference { .. } => Type::String,
@@ -409,10 +397,6 @@ macro_rules! visit_impl {
409397
$visitor(sub_expression);
410398
elements.$iter().filter_map(|x| x.$as_ref().left()).for_each($visitor);
411399
}
412-
Expression::ComputeDialogLayoutCells { roles, unsorted_cells, .. } => {
413-
$visitor(roles);
414-
$visitor(unsorted_cells);
415-
}
416400
Expression::MinMax { ty: _, op: _, lhs, rhs } => {
417401
$visitor(lhs);
418402
$visitor(rhs);

internal/compiler/llr/lower_expression.rs

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

@@ -896,18 +920,6 @@ fn grid_layout_input_data(
896920
}
897921
}
898922

899-
pub(super) fn grid_layout_cell_data_ty() -> Type {
900-
Type::Struct(Rc::new(Struct {
901-
fields: IntoIterator::into_iter([
902-
(SmolStr::new_static("col_or_row"), Type::Int32),
903-
(SmolStr::new_static("span"), Type::Int32),
904-
(SmolStr::new_static("constraint"), crate::typeregister::layout_info_type().into()),
905-
])
906-
.collect(),
907-
name: BuiltinPrivateStruct::GridLayoutCellData.into(),
908-
}))
909-
}
910-
911923
pub(super) fn grid_layout_input_data_ty() -> Type {
912924
Type::Struct(Rc::new(Struct {
913925
fields: IntoIterator::into_iter([
@@ -919,7 +931,6 @@ pub(super) fn grid_layout_input_data_ty() -> Type {
919931
])
920932
.collect(),
921933
name: BuiltinPrivateStruct::GridLayoutInputData.into(),
922-
rust_attributes: None,
923934
}))
924935
}
925936

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
@@ -403,9 +403,6 @@ impl<'a, T> Display for DisplayExpression<'a, T> {
403403
write!(f, "{}[{} % {}]", DisplayPropertyRef(layout_cache_prop, ctx), index, e(ri))
404404
}
405405
Expression::BoxLayoutFunction { .. } => write!(f, "BoxLayoutFunction(TODO)",),
406-
Expression::ComputeDialogLayoutCells { .. } => {
407-
write!(f, "ComputeDialogLayoutCells(TODO)",)
408-
}
409406
Expression::MinMax { ty: _, op, lhs, rhs } => match op {
410407
MinMaxOp::Min => write!(f, "min({}, {})", e(lhs), e(rhs)),
411408
MinMaxOp::Max => write!(f, "max({}, {})", e(lhs), e(rhs)),

internal/compiler/typeregister.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ impl BuiltinTypes {
153153
])
154154
.collect(),
155155
name: BuiltinPrivateStruct::GridLayoutInputData.into(),
156-
rust_attributes: None,
157156
})),
158157
}
159158
}

0 commit comments

Comments
 (0)