mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
Remove undocumented and dysfunctional PathLayout
This type is poorly implemented and not documented. Let's remove it for now. It shall remain available in the git history in the event of a resurrection.
This commit is contained in:
parent
587c9f6942
commit
629c7ed80e
22 changed files with 16 additions and 663 deletions
|
@ -354,22 +354,6 @@ export Path := _ {
|
|||
//-default_size_binding:expands_to_parent_geometry
|
||||
}
|
||||
|
||||
export PathLayout := _ {
|
||||
in property <length> x;
|
||||
in property <length> y;
|
||||
in property <length> width;
|
||||
in property <length> height;
|
||||
in property <string> commands;
|
||||
in property <float> offset;
|
||||
|
||||
MoveTo {}
|
||||
LineTo {}
|
||||
ArcTo {}
|
||||
CubicTo {}
|
||||
QuadraticTo {}
|
||||
Close {}
|
||||
}
|
||||
|
||||
Tab := _ {
|
||||
in property <string> title;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ pub enum Orientation {
|
|||
#[derive(Clone, Debug, derive_more::From)]
|
||||
pub enum Layout {
|
||||
GridLayout(GridLayout),
|
||||
PathLayout(PathLayout),
|
||||
BoxLayout(BoxLayout),
|
||||
}
|
||||
|
||||
|
@ -29,21 +28,18 @@ impl Layout {
|
|||
match self {
|
||||
Layout::GridLayout(g) => &g.geometry.rect,
|
||||
Layout::BoxLayout(g) => &g.geometry.rect,
|
||||
Layout::PathLayout(p) => &p.rect,
|
||||
}
|
||||
}
|
||||
pub fn rect_mut(&mut self) -> &mut LayoutRect {
|
||||
match self {
|
||||
Layout::GridLayout(g) => &mut g.geometry.rect,
|
||||
Layout::BoxLayout(g) => &mut g.geometry.rect,
|
||||
Layout::PathLayout(p) => &mut p.rect,
|
||||
}
|
||||
}
|
||||
pub fn geometry(&self) -> Option<&LayoutGeometry> {
|
||||
pub fn geometry(&self) -> &LayoutGeometry {
|
||||
match self {
|
||||
Layout::GridLayout(l) => Some(&l.geometry),
|
||||
Layout::BoxLayout(l) => Some(&l.geometry),
|
||||
Layout::PathLayout(_) => None,
|
||||
Layout::GridLayout(l) => &l.geometry,
|
||||
Layout::BoxLayout(l) => &l.geometry,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +50,6 @@ impl Layout {
|
|||
match self {
|
||||
Layout::GridLayout(grid) => grid.visit_named_references(visitor),
|
||||
Layout::BoxLayout(l) => l.visit_named_references(visitor),
|
||||
Layout::PathLayout(path) => path.visit_named_references(visitor),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -451,22 +446,6 @@ impl BoxLayout {
|
|||
}
|
||||
}
|
||||
|
||||
/// Internal representation of a path layout
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PathLayout {
|
||||
pub path: Path,
|
||||
pub elements: Vec<ElementRc>,
|
||||
pub rect: LayoutRect,
|
||||
pub offset_reference: Option<NamedReference>,
|
||||
}
|
||||
|
||||
impl PathLayout {
|
||||
fn visit_named_references(&mut self, visitor: &mut impl FnMut(&mut NamedReference)) {
|
||||
self.rect.visit_named_references(visitor);
|
||||
self.offset_reference.as_mut().map(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
/// The [`Type`] for a runtime LayoutInfo structure
|
||||
pub fn layout_info_type() -> Type {
|
||||
Type::Struct {
|
||||
|
|
|
@ -493,7 +493,6 @@ fn compute_layout_info(
|
|||
None => sub_expression,
|
||||
}
|
||||
}
|
||||
crate::layout::Layout::PathLayout(_) => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -619,40 +618,6 @@ fn solve_layout(
|
|||
},
|
||||
}
|
||||
}
|
||||
crate::layout::Layout::PathLayout(layout) => {
|
||||
let width = layout_geometry_size(&layout.rect, Orientation::Horizontal, ctx);
|
||||
let height = layout_geometry_size(&layout.rect, Orientation::Vertical, ctx);
|
||||
let elements = compile_path(&layout.path, ctx);
|
||||
let offset = if let Some(expr) = &layout.offset_reference {
|
||||
llr_Expression::PropertyReference(ctx.map_property_reference(expr))
|
||||
} else {
|
||||
llr_Expression::NumberLiteral(0.)
|
||||
};
|
||||
|
||||
// FIXME! repeater
|
||||
let repeater_indices =
|
||||
llr_Expression::Array { element_ty: Type::Int32, values: vec![], as_model: false };
|
||||
let count = layout.elements.len();
|
||||
llr_Expression::ExtraBuiltinFunctionCall {
|
||||
function: "solve_path_layout".into(),
|
||||
arguments: vec![
|
||||
make_struct(
|
||||
"PathLayoutData".into(),
|
||||
[
|
||||
("width", Type::Float32, width),
|
||||
("height", Type::Float32, height),
|
||||
("x", Type::Float32, llr_Expression::NumberLiteral(0.)),
|
||||
("y", Type::Float32, llr_Expression::NumberLiteral(0.)),
|
||||
("elements", elements.ty(ctx), elements),
|
||||
("offset", Type::Int32, offset),
|
||||
("item_count", Type::Int32, llr_Expression::NumberLiteral(count as _)),
|
||||
],
|
||||
),
|
||||
repeater_indices,
|
||||
],
|
||||
return_ty: Type::LayoutCache,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -352,18 +352,11 @@ fn recurse_expression(expr: &Expression, vis: &mut impl FnMut(&PropertyPath)) {
|
|||
crate::layout::Layout::BoxLayout(l) => {
|
||||
visit_layout_items_dependencies(l.elems.iter(), *o, vis)
|
||||
}
|
||||
crate::layout::Layout::PathLayout(l) => {
|
||||
for it in &l.elements {
|
||||
vis(&NamedReference::new(it, "width").into());
|
||||
vis(&NamedReference::new(it, "height").into());
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(g) = l.geometry() {
|
||||
let mut g = g.clone();
|
||||
g.rect = Default::default(); // already visited;
|
||||
g.visit_named_references(&mut |nr| vis(&nr.clone().into()))
|
||||
}
|
||||
|
||||
let mut g = l.geometry().clone();
|
||||
g.rect = Default::default(); // already visited;
|
||||
g.visit_named_references(&mut |nr| vis(&nr.clone().into()))
|
||||
}
|
||||
Expression::FunctionCall { function, arguments, .. } => {
|
||||
if let Expression::BuiltinFunctionReference(
|
||||
|
|
|
@ -24,8 +24,6 @@ pub fn compile_paths(
|
|||
) {
|
||||
let path_type = tr.lookup_element("Path").unwrap();
|
||||
let path_type = path_type.as_builtin();
|
||||
let pathlayout_type = tr.lookup_element("PathLayout").unwrap();
|
||||
let pathlayout_type = pathlayout_type.as_builtin();
|
||||
|
||||
recurse_elem(&component.root_element, &(), &mut |elem_, _| {
|
||||
let accepted_type = match &elem_.borrow().base_type {
|
||||
|
@ -34,11 +32,6 @@ pub fn compile_paths(
|
|||
{
|
||||
path_type
|
||||
}
|
||||
ElementType::Builtin(be)
|
||||
if be.native_class.class_name == pathlayout_type.native_class.class_name =>
|
||||
{
|
||||
pathlayout_type
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
|
||||
|
|
|
@ -146,7 +146,6 @@ fn is_layout(base_type: &ElementType) -> bool {
|
|||
if let ElementType::Builtin(be) = base_type {
|
||||
match be.name.as_str() {
|
||||
"GridLayout" | "HorizontalLayout" | "VerticalLayout" => true,
|
||||
"PathLayout" => false,
|
||||
_ => false,
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -427,11 +427,6 @@ fn fixup_element_references(
|
|||
fxe(&mut e.item.element);
|
||||
}
|
||||
}
|
||||
crate::layout::Layout::PathLayout(l) => {
|
||||
for e in &mut l.elements {
|
||||
fxe(e);
|
||||
}
|
||||
}
|
||||
crate::layout::Layout::BoxLayout(l) => {
|
||||
for e in &mut l.elems {
|
||||
fxe(&mut e.element);
|
||||
|
|
|
@ -62,7 +62,6 @@ fn lower_element_layout(
|
|||
"GridLayout" => lower_grid_layout(component, elem, diag),
|
||||
"HorizontalLayout" => lower_box_layout(elem, diag, Orientation::Horizontal),
|
||||
"VerticalLayout" => lower_box_layout(elem, diag, Orientation::Vertical),
|
||||
"PathLayout" => lower_path_layout(elem, diag),
|
||||
"Dialog" => {
|
||||
lower_dialog_layout(elem, style_metrics, diag);
|
||||
return; // the Dialog stays in the tree as a Dialog
|
||||
|
@ -89,7 +88,7 @@ fn lower_element_layout(
|
|||
}
|
||||
|
||||
pub fn is_layout_element(element: &ElementRc) -> bool {
|
||||
matches!(&element.borrow().base_type, ElementType::Builtin(n) if n.name == "GridLayout" || n.name == "HorizontalLayout" || n.name == "VerticalLayout" || n.name == "PathLayout")
|
||||
matches!(&element.borrow().base_type, ElementType::Builtin(n) if n.name == "GridLayout" || n.name == "HorizontalLayout" || n.name == "VerticalLayout")
|
||||
}
|
||||
|
||||
fn lower_grid_layout(
|
||||
|
@ -588,73 +587,6 @@ fn lower_dialog_layout(
|
|||
dialog_element.borrow_mut().layout_info_prop = Some((layout_info_prop_h, layout_info_prop_v));
|
||||
}
|
||||
|
||||
fn lower_path_layout(layout_element: &ElementRc, diag: &mut BuildDiagnostics) {
|
||||
let layout_cache_prop = create_new_prop(layout_element, "layout-cache", Type::LayoutCache);
|
||||
|
||||
let path_elements_expr =
|
||||
match layout_element.borrow_mut().bindings.remove("elements").map(RefCell::into_inner) {
|
||||
Some(BindingExpression { expression: Expression::PathData(data), .. }) => data,
|
||||
_ => {
|
||||
assert!(diag.has_error());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let elements = layout_element.borrow().children.clone();
|
||||
if elements.is_empty() {
|
||||
return;
|
||||
}
|
||||
for (index, e) in elements.iter().enumerate() {
|
||||
let (repeater_index, actual_elem) = if e.borrow().repeated.is_some() {
|
||||
(
|
||||
Some(Expression::RepeaterIndexReference { element: Rc::downgrade(e) }),
|
||||
e.borrow().base_type.as_component().root_element.clone(),
|
||||
)
|
||||
} else {
|
||||
(None, e.clone())
|
||||
};
|
||||
let set_prop_from_cache = |prop: &str, offset: usize, size_prop: &str| {
|
||||
let size = NamedReference::new(&actual_elem, size_prop);
|
||||
let expression = Expression::BinaryExpression {
|
||||
lhs: Box::new(Expression::LayoutCacheAccess {
|
||||
layout_cache_prop: layout_cache_prop.clone(),
|
||||
index: index * 2 + offset,
|
||||
repeater_index: repeater_index.as_ref().map(|x| Box::new(x.clone())),
|
||||
}),
|
||||
op: '-',
|
||||
rhs: Box::new(Expression::BinaryExpression {
|
||||
lhs: Box::new(Expression::PropertyReference(size)),
|
||||
op: '/',
|
||||
rhs: Box::new(Expression::NumberLiteral(2., Unit::None)),
|
||||
}),
|
||||
};
|
||||
actual_elem.borrow_mut().bindings.insert(prop.into(), RefCell::new(expression.into()));
|
||||
};
|
||||
set_prop_from_cache("x", 0, "width");
|
||||
set_prop_from_cache("y", 1, "height");
|
||||
}
|
||||
let rect = LayoutRect::install_on_element(layout_element);
|
||||
let path_layout = Layout::PathLayout(PathLayout {
|
||||
elements,
|
||||
path: path_elements_expr,
|
||||
rect,
|
||||
offset_reference: layout_element
|
||||
.borrow()
|
||||
.bindings
|
||||
.contains_key("spacing")
|
||||
.then(|| NamedReference::new(layout_element, "spacing")),
|
||||
});
|
||||
let binding = BindingExpression::new_with_span(
|
||||
Expression::SolveLayout(path_layout, Orientation::Horizontal),
|
||||
layout_element.borrow().to_source_location(),
|
||||
);
|
||||
layout_cache_prop
|
||||
.element()
|
||||
.borrow_mut()
|
||||
.bindings
|
||||
.insert(layout_cache_prop.name().into(), binding.into());
|
||||
}
|
||||
|
||||
struct CreateLayoutItemResult {
|
||||
item: LayoutItem,
|
||||
elem: ElementRc,
|
||||
|
|
|
@ -12,5 +12,5 @@ TestCase := Rectangle {
|
|||
}
|
||||
|
||||
LineTo { x: 100; y: 0; }
|
||||
// ^error{LineTo can only be within the following elements: Path, PathLayout}
|
||||
// ^error{LineTo can only be within a Path element}
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||
|
||||
X := Rectangle {
|
||||
|
||||
PathLayout {
|
||||
for item[index] in [
|
||||
{name: "First Item"},
|
||||
{name: "Second Item"}
|
||||
] : Text {
|
||||
text: item.name;
|
||||
}
|
||||
|
||||
x: 50phx;
|
||||
y: 50phx;
|
||||
|
||||
LineTo {
|
||||
x: 300;
|
||||
y: 300;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue