Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First stage of cleaning up the export handling of the slint root component #2095

Merged
merged 3 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
First stage of cleaning up the export handling of the slint root comp…
…onent

We implicitly export the last component of a .slint file to the generator.
Issue a warning when that happens and suggest to export it explicitly.
  • Loading branch information
tronical committed Jan 23, 2023
commit ec64754b96cc5a6ed6107d33d4b34c4c761c5280
4 changes: 2 additions & 2 deletions examples/carousel/ui/carousel_demo.slint
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Carousel } from "carousel.slint";
import { Card } from "card.slint";
import { Theme } from "theme.slint";

component MainWindow inherits Window {
export component MainWindow inherits Window {
private property<[{ title: string, image: image}]> navigation-items: [
{ title: "Settings", image: @image-url("svg/settings_black.svg") },
{ title: "Home", image: @image-url("svg/home_black.svg") },
Expand Down Expand Up @@ -38,4 +38,4 @@ component MainWindow inherits Window {
clicked => { root.selected-index = index; }
}
}
}
}
4 changes: 2 additions & 2 deletions examples/gallery/ui/gallery_settings.slint
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

global GallerySettings {
export global GallerySettings {
in property<bool> widgets-disabled: false;
}
}
2 changes: 1 addition & 1 deletion examples/opengl_underlay/scene.slint
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { ScrollView, Button, CheckBox, SpinBox, Slider, GroupBox, LineEdit, StandardListView,
ComboBox, HorizontalBox, VerticalBox, GridBox, TabWidget, TextEdit, AboutSixtyFPS } from "std-widgets.slint";

component App inherits Window {
export component App inherits Window {
preferred-width: 500px;
preferred-height: 600px;
title: "Slint OpenGL Underlay Example";
Expand Down
2 changes: 1 addition & 1 deletion examples/printerdemo_old/ui/print_page.slint
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { SpinBox, Button, CheckBox, Slider, GroupBox, StandardListView, GridBox } from "std-widgets.slint";
import { Label, Page, Preview } from "common.slint";

component PrintPage inherits Page {
export component PrintPage inherits Page {

layout := GridLayout {
padding-left: 40px;
Expand Down
2 changes: 1 addition & 1 deletion examples/printerdemo_old/ui/printerdemo.slint
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct InkLevel {
level: float,
}

component MainWindow inherits Window {
export component MainWindow inherits Window {
callback quit();

width: 800px;
Expand Down
12 changes: 11 additions & 1 deletion internal/compiler/object_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub struct UsedSubTypes {
/// Or is materialized for repeated expression.
#[derive(Default, Debug)]
pub struct Component {
// node: SyntaxNode,
pub node: Option<SyntaxNode>,
pub id: String,
pub root_element: ElementRc,

Expand Down Expand Up @@ -254,6 +254,7 @@ impl Component {
let mut child_insertion_point = None;
let is_legacy_syntax = node.child_token(SyntaxKind::ColonEqual).is_some();
let c = Component {
node: Some(node.clone().into()),
id: parser::identifier_text(&node.DeclaredIdentifier()).unwrap_or_default(),
root_element: Element::from_node(
node.Element(),
Expand Down Expand Up @@ -2215,6 +2216,15 @@ impl Exports {

if sorted_deduped_exports.is_empty() {
if let Some(last_compo) = inner_components.last() {
if last_compo.is_global() {
diag.push_warning(
"Global singleton is implicitly marked for export. This is deprecated and it should be explicitly exported"
.into(),
&last_compo.node,
);
} else {
diag.push_warning("Component is implicitly marked for export. This is deprecated and it should be explicitly exported".into(), &last_compo.node)
}
let name = last_compo.id.clone();
sorted_deduped_exports.push((
ExportedName { name, name_ident: doc.clone().into() },
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/passes/inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ fn duplicate_sub_component(
) -> Rc<Component> {
debug_assert!(component_to_duplicate.parent_element.upgrade().is_some());
let new_component = Component {
node: component_to_duplicate.node.clone(),
id: component_to_duplicate.id.clone(),
root_element: duplicate_element_with_mapping(
&component_to_duplicate.root_element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Button3 := Rectangle {
}
}

Test := Window {
export Test := Window {

Button1 { }
Button1 { accessible-description: "ok"; } // ok because Button1 has a role
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WithStates := Rectangle {
]
}

Test := Rectangle {
export Test := Rectangle {

property <int> a: 45 + root.b;
// ^error{The binding for the property 'a' is part of a binding loop}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ T4 := Rectangle {
property <length> my_property <=> x;
}

App := Rectangle {
export App := Rectangle {


VerticalLayout {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Compo1 := Rectangle {
// ^error{The binding for the property 'bb' is part of a binding loop}
}

App := Rectangle {
export App := Rectangle {
cc := Compo1 {
aa() => { return self.a; }
// ^error{The binding for the property 'aa' is part of a binding loop}
Expand All @@ -29,4 +29,4 @@ App := Rectangle {



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Alias := Rectangle {
property <int> ps_width <=> viewport_width;
}

Foo := Rectangle {
export Foo := Rectangle {
property <int> base-prop: alias.viewport_width;
// ^error{The binding for the property 'base-prop' is part of a binding loop}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TC := Rectangle {
}


Test := Rectangle {
export Test := Rectangle {
VerticalLayout {
// ^error{The binding for the property 'layoutinfo-h' is part of a binding loop} // FIXME: That's an internal property, but people might understand
// ^^error{The binding for the property 'min-width' is part of a binding loop}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Wrap := Rectangle {
property <bool> test: square.width == square.height;
}

Test := Rectangle {
export Test := Rectangle {
property <image> source;
GridLayout {
// ^error{The binding for the property 'layout-cache-h' is part of a binding loop}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Compo := Rectangle {

}

Foo := Rectangle {
export Foo := Rectangle {
Compo {
// ^error{The binding for the property 'preferred-width' is part of a binding loop}
the_text: self.preferred-width / 1px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Key := Rectangle { property <int> pos; property <int> num_elements; }

Test := Rectangle {
export Test := Rectangle {
Rectangle {
property <int> num_elements;
num-elements: 4;
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/animate.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

SuperSimple := Rectangle {
export SuperSimple := Rectangle {

animate x {
duration: 1000ms;
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/arithmetic_op.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

SuperSimple := Rectangle {
export SuperSimple := Rectangle {
property<duration> p1: 3s + 1ms;
property<int> p2: 3s + 1;
// ^error{Cannot convert float to duration}
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/array.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

Test := Window {
export Test := Window {
a: [,];
// ^error{invalid expression}
}
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/assign.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

SuperSimple := Rectangle {
export SuperSimple := Rectangle {
TouchArea {
clicked => { root.x = 1phx; }
}
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/box_shadow.slint
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Foo := Rectangle {
drop-shadow-color: red;
}

SuperSimple := Window {
export SuperSimple := Window {
drop-shadow-color: #00000080;
// ^warning{The drop-shadow-color property cannot be used on the root element, the shadow will not be visible}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TestBox2 := Rectangle {
// ^error{The @children placeholder can only appear once in an element hierarchy}
}

Final := TestBox {
export Final := TestBox {
Rectangle {
@children
// ^error{children placeholder not allowed in the final component}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

Final := Window {
export Final := Window {
VerticalLayout {
@children
// ^error{children placeholder not allowed in the final component}
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/clip.slint
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

MyTouchArea := TouchArea { }

SubElements := Rectangle {
export SubElements := Rectangle {
Rectangle {
clip: 42;
// ^error{Cannot convert float to bool}
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/comments.slint
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// comment

// line comment
SuperSimple := Rectangle {
export SuperSimple := Rectangle {
/* block comment */
background: green;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

SuperSimple := Rectangle {
export SuperSimple := Rectangle {
property<bool> zz: aa > bb == cc
// ^error{Use parentheses to disambiguate equality expression on the same level}
< dd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SuperSimple := Rectangle {
}


Test2 := Rectangle {
export Test2 := Rectangle {
background: {
// ^error{Cannot convert void to brush}
if (true) {
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/dialog.slint
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ MyDialog4 := Dialog {
}
}

Test := Rectangle {
export Test := Rectangle {
MyDiag1 {}
MyDiag2 {}
MyDiag3 {}
Expand Down
4 changes: 2 additions & 2 deletions internal/compiler/tests/syntax/basic/dialog2.slint
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { StandardButton } from "std-widgets.slint";

Test := Dialog {
// ^error{A Dialog must have a single child element that is not StandardButton}
export Test := Dialog {
// ^error{A Dialog must have a single child element that is not StandardButton}
StandardButton { kind: ok; }
StandardButton { }
// ^error{The `kind` property of the StandardButton in a Dialog must be set}
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/double_binding.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

X := Rectangle {
export X := Rectangle {

x: 42phx;
x: 32phx;
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/double_color.slint
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial


SuperSimple := Rectangle {
export SuperSimple := Rectangle {
background: green;
background: red;
// ^error{Duplicated property}
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/duplicated_id.slint
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SubElement := Rectangle {
// ^error{duplicated element id 'hello'}
}

TestCase := Rectangle {
export TestCase := Rectangle {

unique := Rectangle {
foo := SubElement { }
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/easing.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

X := Rectangle {
export X := Rectangle {
animate x { easing: ease-in; }
animate y { easing: foo; }
// ^error{Unknown unqualified identifier 'foo'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// Cannot be put in the easing.slint test because it is in a different pass

X := Rectangle {
export X := Rectangle {
property <int> g; animate g { easing: cubic-bezier; }
// ^error{must be called}
}
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/for.slint
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial


SuperSimple := Rectangle {
export SuperSimple := Rectangle {
background: green;

for xx Text {}
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/image.slint
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial


SubElements := Rectangle {
export SubElements := Rectangle {

background: blue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Inline1 := Rectangle {
}
}

SubElements := Rectangle {
export SubElements := Rectangle {
Inline1 {
background: yellow;
invalid: yellow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Comp := Rectangle {
// ^error{'Rectangle' is not a valid type}
}

Foo := Rectangle {
export Foo := Rectangle {
xx := Rectangle { }
Comp {
r: xx;
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/layout.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

X := Rectangle {
export X := Rectangle {

lay := GridLayout {
property<string> foo: "hello";
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/tests/syntax/basic/layout2.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

X := Rectangle {
export X := Rectangle {

lay := GridLayout {
property<string> foo: "hello";
Expand Down
Loading