Remove the error when using @children on the root component

This complicates multi-component handling
This commit is contained in:
Olivier Goffart 2024-06-20 12:23:25 +02:00
parent acb7da11d2
commit 8933f3308c
7 changed files with 14 additions and 26 deletions

View file

@ -224,11 +224,6 @@ pub async fn compile_syntax_node(
&type_registry, &type_registry,
); );
if let Some((_, _, node)) = &*doc.root_component.child_insertion_point.borrow() {
diagnostics
.push_error("@children placeholder not allowed in the final component".into(), node)
}
if !diagnostics.has_error() { if !diagnostics.has_error() {
passes::run_passes(&doc, &mut loader, false, &mut diagnostics).await; passes::run_passes(&doc, &mut loader, false, &mut diagnostics).await;
} else { } else {

View file

@ -116,7 +116,7 @@ pub async fn run_passes(
focus_handling::call_focus_on_init(root_component); focus_handling::call_focus_on_init(root_component);
ensure_window::ensure_window(root_component, &doc.local_registry, &style_metrics); ensure_window::ensure_window(root_component, &doc.local_registry, &style_metrics, diag);
doc.visit_all_used_components(|component| { doc.visit_all_used_components(|component| {
border_radius::handle_border_radius(component, diag); border_radius::handle_border_radius(component, diag);

View file

@ -3,6 +3,7 @@
//! Make sure that the top level element of the component is always a Window //! Make sure that the top level element of the component is always a Window
use crate::diagnostics::BuildDiagnostics;
use crate::expression_tree::{BindingExpression, BuiltinFunction, Expression}; use crate::expression_tree::{BindingExpression, BuiltinFunction, Expression};
use crate::langtype::Type; use crate::langtype::Type;
use crate::namedreference::NamedReference; use crate::namedreference::NamedReference;
@ -16,7 +17,15 @@ pub fn ensure_window(
component: &Rc<Component>, component: &Rc<Component>,
type_register: &TypeRegister, type_register: &TypeRegister,
style_metrics: &Rc<Component>, style_metrics: &Rc<Component>,
diag: &mut BuildDiagnostics,
) { ) {
if component.inherits_popup_window.get() {
diag.push_error(
"PopupWindow cannot be the top level".into(),
&*component.root_element.borrow(),
);
}
if component.root_element.borrow().builtin_type().map_or(true, |b| { if component.root_element.borrow().builtin_type().map_or(true, |b| {
matches!(b.name.as_str(), "Window" | "Dialog" | "WindowItem" | "PopupWindow") matches!(b.name.as_str(), "Window" | "Dialog" | "WindowItem" | "PopupWindow")
}) { }) {

View file

@ -45,13 +45,6 @@ fn lower_popup_window(
let parent_component = popup_window_element.borrow().enclosing_component.upgrade().unwrap(); let parent_component = popup_window_element.borrow().enclosing_component.upgrade().unwrap();
let parent_element = match parent_element { let parent_element = match parent_element {
None => { None => {
if parent_component.is_root_component.get() {
diag.push_error(
"PopupWindow cannot be the top level".into(),
&*popup_window_element.borrow(),
);
return;
}
if matches!(popup_window_element.borrow().base_type, ElementType::Builtin(_)) { if matches!(popup_window_element.borrow().base_type, ElementType::Builtin(_)) {
popup_window_element.borrow_mut().base_type = window_type.clone(); popup_window_element.borrow_mut().base_type = window_type.clone();
} }

View file

@ -36,6 +36,5 @@ export TestBox2 := Rectangle {
export Final := TestBox { export Final := TestBox {
Rectangle { Rectangle {
@children @children
// ^error{children placeholder not allowed in the final component}
} }
} }

View file

@ -1,9 +0,0 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
export Final := Window {
VerticalLayout {
@children
// ^error{children placeholder not allowed in the final component}
}
}

View file

@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint.dev> // Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
Container := Rectangle { component Container inherits Rectangle {
GridLayout { GridLayout {
padding: 0phx; padding: 0phx;
spacing: 0phx; spacing: 0phx;
@ -19,15 +19,16 @@ Container := Rectangle {
} }
} }
TestCase := Container { export component TestCase inherits Container {
width: 300phx; width: 300phx;
height: 200phx; height: 200phx;
rect1 := Rectangle { rect1 := Rectangle {
background: black; background: black;
@children
} }
property <bool> rect1_pos_ok: rect1.x == 150phx; out property <bool> rect1_pos_ok: rect1.x == 150phx;
out property <bool> test: rect1_pos_ok; out property <bool> test: rect1_pos_ok;
} }