mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
C++: adapt to the layout horizontal/vertical split
This commit is contained in:
parent
7aba0f2a0b
commit
cfc04bb4ab
2 changed files with 104 additions and 96 deletions
|
@ -307,10 +307,12 @@ using cbindgen_private::GridLayoutCellData;
|
||||||
using cbindgen_private::GridLayoutData;
|
using cbindgen_private::GridLayoutData;
|
||||||
using cbindgen_private::LayoutAlignment;
|
using cbindgen_private::LayoutAlignment;
|
||||||
using cbindgen_private::LayoutInfo;
|
using cbindgen_private::LayoutInfo;
|
||||||
|
using cbindgen_private::Orientation;
|
||||||
using cbindgen_private::Padding;
|
using cbindgen_private::Padding;
|
||||||
using cbindgen_private::PathLayoutData;
|
using cbindgen_private::PathLayoutData;
|
||||||
using cbindgen_private::Rect;
|
using cbindgen_private::Rect;
|
||||||
using cbindgen_private::sixtyfps_box_layout_info;
|
using cbindgen_private::sixtyfps_box_layout_info;
|
||||||
|
using cbindgen_private::sixtyfps_box_layout_info_ortho;
|
||||||
using cbindgen_private::sixtyfps_grid_layout_info;
|
using cbindgen_private::sixtyfps_grid_layout_info;
|
||||||
using cbindgen_private::sixtyfps_solve_box_layout;
|
using cbindgen_private::sixtyfps_solve_box_layout;
|
||||||
using cbindgen_private::sixtyfps_solve_grid_layout;
|
using cbindgen_private::sixtyfps_solve_grid_layout;
|
||||||
|
@ -329,38 +331,25 @@ inline LayoutInfo LayoutInfo::merge(const LayoutInfo &other) const
|
||||||
return (left_size + right_size) / 2.;
|
return (left_size + right_size) / 2.;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return LayoutInfo { std::max(min_width, other.min_width),
|
return LayoutInfo { std::max(min, other.min),
|
||||||
std::min(max_width, other.max_width),
|
std::min(max, other.max),
|
||||||
std::max(min_height, other.min_height),
|
std::max(min_percent, other.min_percent),
|
||||||
std::min(max_height, other.max_height),
|
std::min(max_percent, other.max_percent),
|
||||||
std::max(min_width_percent, other.min_width_percent),
|
merge_preferred_size(stretch, preferred,
|
||||||
std::min(max_width_percent, other.max_width_percent),
|
other.stretch, other.preferred),
|
||||||
std::max(min_height_percent, other.min_height_percent),
|
std::min(stretch, other.stretch) };
|
||||||
std::min(max_height_percent, other.max_height_percent),
|
|
||||||
merge_preferred_size(horizontal_stretch, preferred_width,
|
|
||||||
other.horizontal_stretch, other.preferred_width),
|
|
||||||
merge_preferred_size(vertical_stretch, preferred_height,
|
|
||||||
other.vertical_stretch, other.preferred_height),
|
|
||||||
std::min(horizontal_stretch, other.horizontal_stretch),
|
|
||||||
std::min(vertical_stretch, other.vertical_stretch) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FIXME! this should be done by cbindgen
|
/// FIXME! this should be done by cbindgen
|
||||||
namespace cbindgen_private {
|
namespace cbindgen_private {
|
||||||
inline bool operator==(const LayoutInfo &a, const LayoutInfo &b)
|
inline bool operator==(const LayoutInfo &a, const LayoutInfo &b)
|
||||||
{
|
{
|
||||||
return a.min_width == b.min_width &&
|
return a.min == b.min &&
|
||||||
a.max_width == b.max_width &&
|
a.max == b.max &&
|
||||||
a.min_height == b.min_height &&
|
a.min_percent == b.min_percent &&
|
||||||
a.max_height == b.max_height &&
|
a.max_percent == b.max_percent &&
|
||||||
a.min_width_percent == b.min_width_percent &&
|
a.preferred == b.preferred &&
|
||||||
a.max_width_percent == b.max_width_percent &&
|
a.stretch == b.stretch;
|
||||||
a.min_height_percent == b.min_height_percent &&
|
|
||||||
a.max_height_percent == b.max_height_percent &&
|
|
||||||
a.preferred_width == b.preferred_width &&
|
|
||||||
a.preferred_height == b.preferred_height &&
|
|
||||||
a.horizontal_stretch == b.horizontal_stretch &&
|
|
||||||
a.vertical_stretch == b.vertical_stretch;
|
|
||||||
}
|
}
|
||||||
inline bool operator!=(const LayoutInfo &a, const LayoutInfo &b)
|
inline bool operator!=(const LayoutInfo &a, const LayoutInfo &b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -221,7 +221,7 @@ use crate::expression_tree::{
|
||||||
BindingExpression, BuiltinFunction, EasingCurve, Expression, NamedReference,
|
BindingExpression, BuiltinFunction, EasingCurve, Expression, NamedReference,
|
||||||
};
|
};
|
||||||
use crate::langtype::Type;
|
use crate::langtype::Type;
|
||||||
use crate::layout::{Layout, LayoutGeometry, LayoutRect};
|
use crate::layout::{Layout, LayoutGeometry, LayoutRect, Orientation};
|
||||||
use crate::object_tree::{
|
use crate::object_tree::{
|
||||||
Component, Document, Element, ElementRc, PropertyDeclaration, RepeatedElementInfo,
|
Component, Document, Element, ElementRc, PropertyDeclaration, RepeatedElementInfo,
|
||||||
};
|
};
|
||||||
|
@ -272,6 +272,13 @@ fn get_cpp_type(ty: &Type, decl: &PropertyDeclaration, diag: &mut BuildDiagnosti
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_cpp_orientation(o: Orientation) -> &'static str {
|
||||||
|
match o {
|
||||||
|
Orientation::Horizontal => "sixtyfps::Orientation::Horizontal",
|
||||||
|
Orientation::Vertical => "sixtyfps::Orientation::Vertical",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If the expression is surrounded with parentheses, remove these parentheses
|
/// If the expression is surrounded with parentheses, remove these parentheses
|
||||||
fn remove_parentheses(expr: &str) -> &str {
|
fn remove_parentheses(expr: &str) -> &str {
|
||||||
if expr.starts_with('(') && expr.ends_with(')') {
|
if expr.starts_with('(') && expr.ends_with(')') {
|
||||||
|
@ -859,8 +866,8 @@ fn generate_component(
|
||||||
Access::Public, // Because Repeater accesses it
|
Access::Public, // Because Repeater accesses it
|
||||||
Declaration::Function(Function {
|
Declaration::Function(Function {
|
||||||
name: "box_layout_data".into(),
|
name: "box_layout_data".into(),
|
||||||
signature: "() const -> sixtyfps::BoxLayoutCellData".to_owned(),
|
signature: "(sixtyfps::Orientation o) const -> sixtyfps::BoxLayoutCellData".to_owned(),
|
||||||
statements: Some(vec!["return { layout_info({&static_vtable, const_cast<void *>(static_cast<const void *>(this))}) };".into()]),
|
statements: Some(vec!["return { layout_info({&static_vtable, const_cast<void *>(static_cast<const void *>(this))}, o) };".into()]),
|
||||||
|
|
||||||
..Function::default()
|
..Function::default()
|
||||||
}),
|
}),
|
||||||
|
@ -1194,12 +1201,15 @@ fn generate_component(
|
||||||
Declaration::Function(Function {
|
Declaration::Function(Function {
|
||||||
name: "layout_info".into(),
|
name: "layout_info".into(),
|
||||||
signature:
|
signature:
|
||||||
"([[maybe_unused]] sixtyfps::private_api::ComponentRef component) -> sixtyfps::LayoutInfo"
|
"([[maybe_unused]] sixtyfps::private_api::ComponentRef component, sixtyfps::Orientation o) -> sixtyfps::LayoutInfo"
|
||||||
.into(),
|
.into(),
|
||||||
is_static: true,
|
is_static: true,
|
||||||
statements: Some(vec![
|
statements: Some(vec![
|
||||||
format!("[[maybe_unused]] auto self = reinterpret_cast<const {}*>(component.instance);", component_id),
|
format!("[[maybe_unused]] auto self = reinterpret_cast<const {}*>(component.instance);", component_id),
|
||||||
format!("return {};", get_layout_info(&component.root_element, component, &component.root_constraints.borrow()))
|
format!("if (o == sixtyfps::Orientation::Horizontal) return {};",
|
||||||
|
get_layout_info(&component.root_element, component, &component.root_constraints.borrow(), Orientation::Horizontal)),
|
||||||
|
format!("else return {};",
|
||||||
|
get_layout_info(&component.root_element, component, &component.root_constraints.borrow(), Orientation::Vertical))
|
||||||
]),
|
]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
|
@ -1555,17 +1565,19 @@ fn compile_expression(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::BuiltinFunctionReference(BuiltinFunction::ImplicitLayoutInfo, _) => {
|
Expression::BuiltinFunctionReference(BuiltinFunction::ImplicitLayoutInfo, _) => {
|
||||||
if arguments.len() != 1 {
|
if arguments.len() != 2 {
|
||||||
panic!("internal error: incorrect argument count to ImplicitLayoutInfo call");
|
panic!("internal error: incorrect argument count to ImplicitLayoutInfo call");
|
||||||
}
|
}
|
||||||
if let Expression::ElementReference(item) = &arguments[0] {
|
if let Expression::ElementReference(item) = &arguments[0] {
|
||||||
let item = item.upgrade().unwrap();
|
let item = item.upgrade().unwrap();
|
||||||
let item = item.borrow();
|
let item = item.borrow();
|
||||||
let native_item = item.base_type.as_native();
|
let native_item = item.base_type.as_native();
|
||||||
format!("{vt}->layouting_info({{{vt}, const_cast<sixtyfps::{ty}*>(&self->{id})}}, &window)",
|
let orient = compile_expression(&arguments[1], component);
|
||||||
|
format!("{vt}->layouting_info({{{vt}, const_cast<sixtyfps::{ty}*>(&self->{id})}}, {o}, &window)",
|
||||||
vt = native_item.cpp_vtable_getter,
|
vt = native_item.cpp_vtable_getter,
|
||||||
ty = native_item.class_name,
|
ty = native_item.class_name,
|
||||||
id = item.id
|
id = item.id,
|
||||||
|
o = orient,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
panic!("internal error: argument to ImplicitLayoutInfo must be an element")
|
panic!("internal error: argument to ImplicitLayoutInfo must be an element")
|
||||||
|
@ -1697,14 +1709,14 @@ fn compile_expression(
|
||||||
Expression::LayoutCacheAccess { layout_cache_prop, index, repeater_index } => {
|
Expression::LayoutCacheAccess { layout_cache_prop, index, repeater_index } => {
|
||||||
let cache = access_named_reference(layout_cache_prop, component, "self");
|
let cache = access_named_reference(layout_cache_prop, component, "self");
|
||||||
if let Some(ri) = repeater_index {
|
if let Some(ri) = repeater_index {
|
||||||
format!("[&](auto cache) {{ return cache[int(cache[{}]) + {} * 4]; }} ({}.get())", index, compile_expression(&ri, component), cache)
|
format!("[&](auto cache) {{ return cache[int(cache[{}]) + {} * 2]; }} ({}.get())", index, compile_expression(&ri, component), cache)
|
||||||
} else {
|
} else {
|
||||||
format!("{}.get()[{}]", cache, index)
|
format!("{}.get()[{}]", cache, index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::ComputeLayoutInfo(Layout::GridLayout(layout)) => {
|
Expression::ComputeLayoutInfo(Layout::GridLayout(layout), o) => {
|
||||||
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, component);
|
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, *o, component);
|
||||||
let cells = grid_layout_cell_data(layout, component);
|
let cells = grid_layout_cell_data(layout, *o, component);
|
||||||
format!("[&] {{ \
|
format!("[&] {{ \
|
||||||
const auto padding = {};\
|
const auto padding = {};\
|
||||||
sixtyfps::GridLayoutCellData cells[] = {{ {} }}; \
|
sixtyfps::GridLayoutCellData cells[] = {{ {} }}; \
|
||||||
|
@ -1714,58 +1726,63 @@ fn compile_expression(
|
||||||
padding, cells, spacing
|
padding, cells, spacing
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Expression::ComputeLayoutInfo(Layout::BoxLayout(layout)) => {
|
Expression::ComputeLayoutInfo(Layout::BoxLayout(layout), o) => {
|
||||||
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, component);
|
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, *o, component);
|
||||||
let (cells, alignment) = box_layout_data(layout, component, None);
|
let (cells, alignment) = box_layout_data(layout, *o, component, None);
|
||||||
|
let call = if *o == layout.orientation {
|
||||||
|
format!("sixtyfps_box_layout_info(slice, {}, &padding, {})", spacing, alignment)
|
||||||
|
} else {
|
||||||
|
format!("sixtyfps_box_layout_info_ortho(slice, &padding)")
|
||||||
|
};
|
||||||
format!("[&] {{ \
|
format!("[&] {{ \
|
||||||
const auto padding = {};\
|
const auto padding = {};\
|
||||||
{}\
|
{}\
|
||||||
const sixtyfps::Slice<sixtyfps::BoxLayoutCellData> slice{{ &*std::begin(cells), std::size(cells)}}; \
|
const sixtyfps::Slice<sixtyfps::BoxLayoutCellData> slice{{ &*std::begin(cells), std::size(cells)}}; \
|
||||||
return sixtyfps::sixtyfps_box_layout_info(slice, {}, &padding, {}, {});\
|
return sixtyfps::{};\
|
||||||
}}()",
|
}}()",
|
||||||
padding, cells, spacing, alignment, layout.is_horizontal
|
padding, cells, call
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Expression::ComputeLayoutInfo(Layout::PathLayout(_)) => unimplemented!(),
|
Expression::ComputeLayoutInfo(Layout::PathLayout(_), _) => unimplemented!(),
|
||||||
Expression::SolveLayout(Layout::GridLayout(layout)) => {
|
Expression::SolveLayout(Layout::GridLayout(layout), o) => {
|
||||||
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, component);
|
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, *o, component);
|
||||||
let cells = grid_layout_cell_data(layout, component);
|
let cells = grid_layout_cell_data(layout, *o, component);
|
||||||
let (width, height) = layout_geometry_width_height(&layout.geometry.rect, component);
|
let size = layout_geometry_size(&layout.geometry.rect, *o, component);
|
||||||
format!("[&] {{ \
|
format!("[&] {{ \
|
||||||
const auto padding = {p};\
|
const auto padding = {p};\
|
||||||
sixtyfps::GridLayoutCellData cells[] = {{ {c} }}; \
|
sixtyfps::GridLayoutCellData cells[] = {{ {c} }}; \
|
||||||
const sixtyfps::Slice<sixtyfps::GridLayoutCellData> slice{{ cells, std::size(cells)}}; \
|
const sixtyfps::Slice<sixtyfps::GridLayoutCellData> slice{{ cells, std::size(cells)}}; \
|
||||||
const sixtyfps::GridLayoutData grid {{ {w}, {h}, 0, 0, {s}, &padding, slice }};
|
const sixtyfps::GridLayoutData grid {{ {sz}, {s}, &padding, slice }};
|
||||||
sixtyfps::SharedVector<float> result;
|
sixtyfps::SharedVector<float> result;
|
||||||
sixtyfps::sixtyfps_solve_grid_layout(&grid, &result);\
|
sixtyfps::sixtyfps_solve_grid_layout(&grid, &result);\
|
||||||
return result;
|
return result;
|
||||||
}}()",
|
}}()",
|
||||||
p = padding, c = cells, s = spacing, w = width, h = height
|
p = padding, c = cells, s = spacing, sz = size
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Expression::SolveLayout(Layout::BoxLayout(layout)) => {
|
Expression::SolveLayout(Layout::BoxLayout(layout), o) => {
|
||||||
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, component);
|
let (padding, spacing) = generate_layout_padding_and_spacing(&layout.geometry, *o, component);
|
||||||
let mut repeated_indices = Default::default();
|
let mut repeated_indices = Default::default();
|
||||||
let mut repeated_indices_init = Default::default();
|
let mut repeated_indices_init = Default::default();
|
||||||
let (cells, alignment) = box_layout_data(layout, component, Some((&mut repeated_indices, &mut repeated_indices_init)));
|
let (cells, alignment) = box_layout_data(layout, *o, component, Some((&mut repeated_indices, &mut repeated_indices_init)));
|
||||||
let (width, height) = layout_geometry_width_height(&layout.geometry.rect, component);
|
let size = layout_geometry_size(&layout.geometry.rect, *o, component);
|
||||||
format!("[&] {{ \
|
format!("[&] {{ \
|
||||||
{ri_init}\
|
{ri_init}\
|
||||||
const auto padding = {p};\
|
const auto padding = {p};\
|
||||||
{c}\
|
{c}\
|
||||||
const sixtyfps::Slice<sixtyfps::BoxLayoutCellData> slice{{ &*std::begin(cells), std::size(cells)}}; \
|
const sixtyfps::Slice<sixtyfps::BoxLayoutCellData> slice{{ &*std::begin(cells), std::size(cells)}}; \
|
||||||
sixtyfps::BoxLayoutData box {{ {w}, {h}, 0, 0, {s}, &padding, {a}, slice }};
|
sixtyfps::BoxLayoutData box {{ {sz}, {s}, &padding, {a}, slice }};
|
||||||
sixtyfps::SharedVector<float> result;
|
sixtyfps::SharedVector<float> result;
|
||||||
sixtyfps::sixtyfps_solve_box_layout(&box, {hz}, {ri}, &result);\
|
sixtyfps::sixtyfps_solve_box_layout(&box, {ri}, &result);\
|
||||||
return result;
|
return result;
|
||||||
}}()",
|
}}()",
|
||||||
ri_init = repeated_indices_init, ri = repeated_indices,
|
ri_init = repeated_indices_init, ri = repeated_indices,
|
||||||
p = padding, c = cells, s = spacing, w = width, h = height, a = alignment,
|
p = padding, c = cells, s = spacing, sz = size, a = alignment,
|
||||||
hz = layout.is_horizontal
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Expression::SolveLayout(Layout::PathLayout(layout)) => {
|
Expression::SolveLayout(Layout::PathLayout(layout), _) => {
|
||||||
let (width, height) = layout_geometry_width_height(&layout.rect, component);
|
let width = layout_geometry_size(&layout.rect, Orientation::Horizontal, component);
|
||||||
|
let height = layout_geometry_size(&layout.rect, Orientation::Vertical, component);
|
||||||
let elements = compile_path(&layout.path, component);
|
let elements = compile_path(&layout.path, component);
|
||||||
let prop = |expr: &Option<NamedReference>| {
|
let prop = |expr: &Option<NamedReference>| {
|
||||||
if let Some(nr) = expr.as_ref() {
|
if let Some(nr) = expr.as_ref() {
|
||||||
|
@ -1872,18 +1889,21 @@ fn compile_assignment(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn grid_layout_cell_data(layout: &crate::layout::GridLayout, component: &Rc<Component>) -> String {
|
fn grid_layout_cell_data(
|
||||||
|
layout: &crate::layout::GridLayout,
|
||||||
|
orientation: Orientation,
|
||||||
|
component: &Rc<Component>,
|
||||||
|
) -> String {
|
||||||
layout
|
layout
|
||||||
.elems
|
.elems
|
||||||
.iter()
|
.iter()
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
|
let (col_or_row, span) = c.col_or_row_and_span(orientation);
|
||||||
format!(
|
format!(
|
||||||
"sixtyfps::GridLayoutCellData {{ {col}, {row}, {cs}, {rs}, {cstr} }}",
|
"sixtyfps::GridLayoutCellData {{ {}, {}, {} }}",
|
||||||
col = c.col,
|
col_or_row,
|
||||||
row = c.row,
|
span,
|
||||||
cs = c.colspan,
|
get_layout_info(&c.item.element, component, &c.item.constraints, orientation),
|
||||||
rs = c.rowspan,
|
|
||||||
cstr = get_layout_info(&c.item.element, component, &c.item.constraints),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.join(", ")
|
.join(", ")
|
||||||
|
@ -1893,6 +1913,7 @@ fn grid_layout_cell_data(layout: &crate::layout::GridLayout, component: &Rc<Comp
|
||||||
/// The repeated_indices initialize the repeated_indices (var, init_code)
|
/// The repeated_indices initialize the repeated_indices (var, init_code)
|
||||||
fn box_layout_data(
|
fn box_layout_data(
|
||||||
layout: &crate::layout::BoxLayout,
|
layout: &crate::layout::BoxLayout,
|
||||||
|
orientation: Orientation,
|
||||||
component: &Rc<Component>,
|
component: &Rc<Component>,
|
||||||
mut repeated_indices: Option<(&mut String, &mut String)>,
|
mut repeated_indices: Option<(&mut String, &mut String)>,
|
||||||
) -> (String, String) {
|
) -> (String, String) {
|
||||||
|
@ -1909,7 +1930,7 @@ fn box_layout_data(
|
||||||
let mut cells = layout.elems.iter().map(|li| {
|
let mut cells = layout.elems.iter().map(|li| {
|
||||||
format!(
|
format!(
|
||||||
"sixtyfps::BoxLayoutCellData{{ {} }}",
|
"sixtyfps::BoxLayoutCellData{{ {} }}",
|
||||||
get_layout_info(&li.element, component, &li.constraints)
|
get_layout_info(&li.element, component, &li.constraints, orientation)
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
if let Some((ri, _)) = &mut repeated_indices {
|
if let Some((ri, _)) = &mut repeated_indices {
|
||||||
|
@ -1941,13 +1962,14 @@ fn box_layout_data(
|
||||||
push_code += &format!(
|
push_code += &format!(
|
||||||
"if (self->repeater_{id}.inner) \
|
"if (self->repeater_{id}.inner) \
|
||||||
for (auto &&sub_comp : self->repeater_{id}.inner->data) \
|
for (auto &&sub_comp : self->repeater_{id}.inner->data) \
|
||||||
cells.push_back((*sub_comp.ptr)->box_layout_data());",
|
cells.push_back((*sub_comp.ptr)->box_layout_data({o}));",
|
||||||
id = item.element.borrow().id
|
id = item.element.borrow().id,
|
||||||
|
o = to_cpp_orientation(orientation),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
push_code += &format!(
|
push_code += &format!(
|
||||||
"cells.push_back({{ {} }});",
|
"cells.push_back({{ {} }});",
|
||||||
get_layout_info(&item.element, component, &item.constraints)
|
get_layout_info(&item.element, component, &item.constraints, orientation)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1957,59 +1979,56 @@ fn box_layout_data(
|
||||||
|
|
||||||
fn generate_layout_padding_and_spacing(
|
fn generate_layout_padding_and_spacing(
|
||||||
layout_geometry: &LayoutGeometry,
|
layout_geometry: &LayoutGeometry,
|
||||||
|
orientation: Orientation,
|
||||||
component: &Rc<Component>,
|
component: &Rc<Component>,
|
||||||
) -> (String, String) {
|
) -> (String, String) {
|
||||||
let prop = |expr: &Option<NamedReference>| {
|
let prop = |expr: Option<&NamedReference>| {
|
||||||
if let Some(nr) = expr.as_ref() {
|
if let Some(nr) = expr {
|
||||||
format!("{}.get()", access_named_reference(nr, component, "self"))
|
format!("{}.get()", access_named_reference(nr, component, "self"))
|
||||||
} else {
|
} else {
|
||||||
"0.".into()
|
"0.".into()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let spacing = prop(&layout_geometry.spacing);
|
let spacing = prop(layout_geometry.spacing.as_ref());
|
||||||
let padding = format!(
|
let (begin, end) = layout_geometry.padding.begin_end(orientation);
|
||||||
"sixtyfps::Padding {{ {}, {}, {}, {} }};",
|
let padding = format!("sixtyfps::Padding {{ {}, {} }};", prop(begin), prop(end));
|
||||||
prop(&layout_geometry.padding.left),
|
|
||||||
prop(&layout_geometry.padding.right),
|
|
||||||
prop(&layout_geometry.padding.top),
|
|
||||||
prop(&layout_geometry.padding.bottom),
|
|
||||||
);
|
|
||||||
|
|
||||||
(padding, spacing)
|
(padding, spacing)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_geometry_width_height(rect: &LayoutRect, component: &Rc<Component>) -> (String, String) {
|
fn layout_geometry_size(
|
||||||
let prop = |expr: &Option<NamedReference>| {
|
rect: &LayoutRect,
|
||||||
if let Some(nr) = expr.as_ref() {
|
orientation: Orientation,
|
||||||
format!("{}.get()", access_named_reference(nr, component, "self"))
|
component: &Rc<Component>,
|
||||||
} else {
|
) -> String {
|
||||||
"0.".into()
|
rect.size_reference(orientation).map_or_else(
|
||||||
}
|
|| "0.".into(),
|
||||||
};
|
|nr| format!("{}.get()", access_named_reference(nr, component, "self")),
|
||||||
(prop(&rect.width_reference), prop(&rect.height_reference))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_layout_info(
|
fn get_layout_info(
|
||||||
elem: &ElementRc,
|
elem: &ElementRc,
|
||||||
component: &Rc<Component>,
|
component: &Rc<Component>,
|
||||||
constraints: &crate::layout::LayoutConstraints,
|
constraints: &crate::layout::LayoutConstraints,
|
||||||
|
orientation: Orientation,
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut layout_info = if let Some(layout_info_prop) = &elem.borrow().layout_info_prop {
|
let mut layout_info = if let Some(layout_info_prop) =
|
||||||
|
&elem.borrow().layout_info_prop(orientation)
|
||||||
|
{
|
||||||
format!("{}.get()", access_named_reference(layout_info_prop, component, "self"))
|
format!("{}.get()", access_named_reference(layout_info_prop, component, "self"))
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{vt}->layouting_info({{{vt}, const_cast<sixtyfps::{ty}*>(&self->{id})}}, &self->window)",
|
"{vt}->layouting_info({{{vt}, const_cast<sixtyfps::{ty}*>(&self->{id})}}, {o}, &self->window)",
|
||||||
vt = elem.borrow().base_type.as_native().cpp_vtable_getter,
|
vt = elem.borrow().base_type.as_native().cpp_vtable_getter,
|
||||||
ty = elem.borrow().base_type.as_native().class_name,
|
ty = elem.borrow().base_type.as_native().class_name,
|
||||||
id = elem.borrow().id,
|
id = elem.borrow().id,
|
||||||
|
o = to_cpp_orientation(orientation),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
if constraints.has_explicit_restrictions() {
|
if constraints.has_explicit_restrictions() {
|
||||||
layout_info = format!("[&]{{ auto layout_info = {};", layout_info);
|
layout_info = format!("[&]{{ auto layout_info = {};", layout_info);
|
||||||
for (expr, name) in constraints.for_each_restrictions() {
|
for (expr, name) in constraints.for_each_restrictions(orientation) {
|
||||||
layout_info += &format!(
|
layout_info += &format!(
|
||||||
" layout_info.{} = {}.get();",
|
" layout_info.{} = {}.get();",
|
||||||
name,
|
name,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue