From fff2e974710091ed37bb5c70822c468302372c21 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 11 Dec 2024 17:52:53 +0100 Subject: [PATCH 1/2] Remove `LayoutSpec` and undeprecate `StyleMetrics.layout-*` properties StyleMetrics is the right name for these --- CHANGELOG.md | 2 +- .../docs/reference/std-widgets/overview.mdx | 6 +-- .../gallery/ui/pages/table_view_page.slint | 12 ++--- internal/compiler/lookup.rs | 44 ++++++++++++------- internal/compiler/passes/resolving.rs | 6 +++ .../syntax/lookup/deprecated_property.slint | 9 +++- internal/compiler/widgets/common/layout.slint | 14 +++--- .../widgets/cosmic/std-widgets-impl.slint | 9 +--- .../compiler/widgets/cosmic/std-widgets.slint | 2 +- .../compiler/widgets/cosmic/styling.slint | 6 --- .../widgets/cupertino/std-widgets-impl.slint | 7 +-- .../widgets/cupertino/std-widgets.slint | 2 +- .../widgets/fluent/std-widgets-impl.slint | 8 +--- .../compiler/widgets/fluent/std-widgets.slint | 2 +- .../widgets/material/std-widgets-impl.slint | 10 ++--- .../widgets/material/std-widgets.slint | 2 +- .../widgets/qt/std-widgets-impl.slint | 5 --- .../compiler/widgets/qt/std-widgets.slint | 2 +- 18 files changed, 70 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f8b9b8ffbd..2eed914e380 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ All notable changes to this project are documented in this file. - LineEdit: fixed cursor drawing out of bounds (#6243) - TabWidget: fixed tabs overflow behavior (#6517) - SpinBox: added `horizontal-alignment` - - Added `LayoutSpec` global + - Undeprecared `StyleMetrics` layout properties - Slider: added `step` property - StandardListView: improved keyboard navigation (#6955) diff --git a/docs/astro/src/content/docs/reference/std-widgets/overview.mdx b/docs/astro/src/content/docs/reference/std-widgets/overview.mdx index aec93501173..ef88b868d14 100644 --- a/docs/astro/src/content/docs/reference/std-widgets/overview.mdx +++ b/docs/astro/src/content/docs/reference/std-widgets/overview.mdx @@ -98,14 +98,14 @@ Defines the brush that is used for borders such as separators and widget borders ### color-scheme Read this property to determine the color scheme used by the palette. -Set this property to force a dark or light color scheme. All styles +Set this property to force a dark or light color scheme. All styles except for the Qt style support setting a dark or light color scheme. -## LayoutSpec Properties +## StyleMetrics Properties -Use `LayoutSpec` to create custom widgets that match the layout settings of +Use `StyleMetrics` to create custom widgets that match the layout settings of the selected style e.g. fluent, cupertino, material, or qt. ### layout-spacing diff --git a/examples/gallery/ui/pages/table_view_page.slint b/examples/gallery/ui/pages/table_view_page.slint index 6b294638179..48e65a2c778 100644 --- a/examples/gallery/ui/pages/table_view_page.slint +++ b/examples/gallery/ui/pages/table_view_page.slint @@ -1,7 +1,7 @@ // Copyright © SixtyFPS GmbH // SPDX-License-Identifier: MIT -import { HorizontalBox, VerticalBox, StandardTableView, GroupBox, LayoutSpec, LineEdit } from "std-widgets.slint"; +import { HorizontalBox, VerticalBox, StandardTableView, GroupBox, StyleMetrics, LineEdit } from "std-widgets.slint"; import { GallerySettings } from "../gallery_settings.slint"; import { Page } from "page.slint"; @@ -14,14 +14,14 @@ export global TableViewPageAdapter { [ { text: "Item 5.1" }, { text: "Item 5.2" }, { text: "Item 5.3" }, { text: "Item 5.4" }, ], [ { text: "Item 6.1" }, { text: "Item 6.2" }, { text: "Item 6.3" }, { text: "Item 6.4" }, ], ]; - + pure callback filter_sort_model([[StandardListViewItem]], string, int, bool) -> [[StandardListViewItem]]; } export component TableViewPage inherits Page { property sort-index: -1; property sort-acending; - + title: @tr("TableView"); show-enable-switch: false; description: @tr("StandardTableView can be used to display a list of text elements in columns and rows. It can be imported from \"std-widgets.slint\""); @@ -34,8 +34,8 @@ export component TableViewPage inherits Page { vertical-stretch: 0; VerticalLayout { - spacing: LayoutSpec.layout-spacing; - + spacing: StyleMetrics.layout-spacing; + StandardTableView { sort-ascending(index) => { root.sort-index = index; @@ -64,7 +64,7 @@ export component TableViewPage inherits Page { filter-edit := LineEdit { placeholder-text: @tr("Enter filter text"); } - } + } } } } diff --git a/internal/compiler/lookup.rs b/internal/compiler/lookup.rs index 0597ff8c364..13fc149314d 100644 --- a/internal/compiler/lookup.rs +++ b/internal/compiler/lookup.rs @@ -382,12 +382,14 @@ impl LookupObject for ElementRc { f: &mut impl FnMut(&SmolStr, LookupResult) -> Option, ) -> Option { for (name, prop) in &self.borrow().property_declarations { - let e = expression_from_reference( + let expression = expression_from_reference( NamedReference::new(self, name.clone()), &prop.property_type, &ctx.current_token, ); - if let Some(r) = f(name, e.into()) { + + let deprecated = check_deprecated_stylemetrics(self, ctx, name); + if let Some(r) = f(name, LookupResult::Expression { expression, deprecated }) { return Some(r); } } @@ -402,7 +404,7 @@ impl LookupObject for ElementRc { return Some(r); } } - if !matches!(self.borrow().base_type, ElementType::Global) { + if !(matches!(self.borrow().base_type, ElementType::Global)) { for (name, ty, _) in crate::typeregister::reserved_properties() { let name = SmolStr::new_static(name); let e = expression_from_reference( @@ -431,7 +433,8 @@ impl LookupObject for ElementRc { &ctx.current_token, ), deprecated: (lookup_result.resolved_name != name.as_str()) - .then(|| lookup_result.resolved_name.to_string()), + .then(|| lookup_result.resolved_name.to_string()) + .or_else(|| check_deprecated_stylemetrics(self, ctx, name)), }) } else { None @@ -439,6 +442,26 @@ impl LookupObject for ElementRc { } } +pub fn check_deprecated_stylemetrics( + elem: &ElementRc, + ctx: &LookupCtx<'_>, + name: &SmolStr, +) -> Option { + let borrow = elem.borrow(); + (!ctx.type_register.expose_internal_types + && matches!( + borrow.enclosing_component.upgrade().unwrap().id.as_str(), + "StyleMetrics" | "NativeStyleMetrics" + ) + && borrow + .debug + .first() + .and_then(|x| x.node.source_file()) + .map_or(true, |x| x.path().starts_with("builtin:")) + && !name.starts_with("layout-")) + .then(|| format!("Palette.{}", name)) +} + fn expression_from_reference( n: NamedReference, ty: &Type, @@ -498,18 +521,7 @@ impl LookupType { { None } else { - Some(LookupResult::Expression { - expression: Expression::ElementReference(Rc::downgrade(&c.root_element)), - deprecated: (name == "StyleMetrics" - && !ctx.type_register.expose_internal_types - && c.root_element - .borrow() - .debug - .first() - .and_then(|x| x.node.source_file()) - .map_or(false, |x| x.path().starts_with("builtin:"))) - .then(|| "Palette".to_string()), - }) + Some(Expression::ElementReference(Rc::downgrade(&c.root_element)).into()) } } _ => None, diff --git a/internal/compiler/passes/resolving.rs b/internal/compiler/passes/resolving.rs index 4d1cba29d05..c6ced832eeb 100644 --- a/internal/compiler/passes/resolving.rs +++ b/internal/compiler/passes/resolving.rs @@ -1447,6 +1447,12 @@ fn continue_lookup_within_element( &lookup_result.resolved_name, &second, ); + } else if let Some(deprecated) = crate::lookup::check_deprecated_stylemetrics(elem, ctx, &prop_name) { + ctx.diag.push_property_deprecation_warning( + &prop_name, + &deprecated, + &second, + ); } let prop = Expression::PropertyReference(NamedReference::new( elem, diff --git a/internal/compiler/tests/syntax/lookup/deprecated_property.slint b/internal/compiler/tests/syntax/lookup/deprecated_property.slint index 8907d42e56f..30a04cdc2a1 100644 --- a/internal/compiler/tests/syntax/lookup/deprecated_property.slint +++ b/internal/compiler/tests/syntax/lookup/deprecated_property.slint @@ -24,8 +24,15 @@ export Xxx := Rectangle { not_called() => { color = #000000; // ^warning{The property 'color' has been deprecated. Please use 'background' instead} + debug(StyleMetrics.dark-color-scheme); -// ^warning{The property 'StyleMetrics' has been deprecated. Please use 'Palette' instead} +// ^warning{The property 'dark-color-scheme' has been deprecated. Please use 'Palette.dark-color-scheme' instead} + + // not deprecated + debug(StyleMetrics.layout-padding, StyleMetrics.layout-padding); + + background = StyleMetrics.window-background; +// ^warning{The property 'window-background' has been deprecated. Please use 'Palette.window-background' instead} } } diff --git a/internal/compiler/widgets/common/layout.slint b/internal/compiler/widgets/common/layout.slint index 28723e50e6b..4d51a72a410 100644 --- a/internal/compiler/widgets/common/layout.slint +++ b/internal/compiler/widgets/common/layout.slint @@ -1,17 +1,17 @@ // Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 -import { LayoutSpec } from "std-widgets-impl.slint"; +import { StyleMetrics } from "std-widgets-impl.slint"; export component VerticalBox inherits VerticalLayout { - spacing: LayoutSpec .layout-spacing; - padding: LayoutSpec .layout-padding; + spacing: StyleMetrics.layout-spacing; + padding: StyleMetrics.layout-padding; } export component HorizontalBox inherits HorizontalLayout { - spacing: LayoutSpec .layout-spacing; - padding: LayoutSpec .layout-padding; + spacing: StyleMetrics.layout-spacing; + padding: StyleMetrics.layout-padding; } export component GridBox inherits GridLayout { - spacing: LayoutSpec .layout-spacing; - padding: LayoutSpec .layout-padding; + spacing: StyleMetrics.layout-spacing; + padding: StyleMetrics.layout-padding; } diff --git a/internal/compiler/widgets/cosmic/std-widgets-impl.slint b/internal/compiler/widgets/cosmic/std-widgets-impl.slint index febfa4bbc5a..f2997b2916e 100644 --- a/internal/compiler/widgets/cosmic/std-widgets-impl.slint +++ b/internal/compiler/widgets/cosmic/std-widgets-impl.slint @@ -9,15 +9,9 @@ export { LineEdit } from "lineedit.slint"; import { CosmicPalette } from "styling.slint"; - -export global LayoutSpec { +export global StyleMetrics { out property layout-spacing: 8px; out property layout-padding: 8px; -} - -export global StyleMetrics { - out property layout-spacing: LayoutSpec.layout-spacing; - out property layout-padding: LayoutSpec.layout-padding; out property text-cursor-width: 1px; out property window-background: CosmicPalette.background; out property default-text-color: CosmicPalette.foreground; @@ -42,4 +36,3 @@ export global Palette { out property border: CosmicPalette.border; in-out property color-scheme <=> CosmicPalette.color-scheme; } - diff --git a/internal/compiler/widgets/cosmic/std-widgets.slint b/internal/compiler/widgets/cosmic/std-widgets.slint index a2ffed218bd..1a964b8b413 100644 --- a/internal/compiler/widgets/cosmic/std-widgets.slint +++ b/internal/compiler/widgets/cosmic/std-widgets.slint @@ -5,7 +5,7 @@ export { AboutSlint } from "../common/about-slint.slint"; export { StandardButton } from "../common/standardbutton.slint"; -export { StyleMetrics, ScrollView, Button, Palette, LayoutSpec } from "std-widgets-impl.slint"; +export { StyleMetrics, ScrollView, Button, Palette } from "std-widgets-impl.slint"; export { CheckBox } from "checkbox.slint"; export { ComboBox } from "combobox.slint"; diff --git a/internal/compiler/widgets/cosmic/styling.slint b/internal/compiler/widgets/cosmic/styling.slint index aee6f4798e1..55344e7106d 100644 --- a/internal/compiler/widgets/cosmic/styling.slint +++ b/internal/compiler/widgets/cosmic/styling.slint @@ -69,12 +69,6 @@ export global CosmicPalette { out property state-secondary: dark-color-scheme ? #000000 : #ffffff; } -export global CosmicLayoutSpec { - out property layout-spacing: 8px; - out property layout-padding: 8px; - out property text-cursor-width: 1px; -} - export global Icons { out property arrow-down: @image-url("_arrow_down.svg"); out property arrow-up: @image-url("_arrow_up.svg"); diff --git a/internal/compiler/widgets/cupertino/std-widgets-impl.slint b/internal/compiler/widgets/cupertino/std-widgets-impl.slint index 838c8a1f62e..455101853b9 100644 --- a/internal/compiler/widgets/cupertino/std-widgets-impl.slint +++ b/internal/compiler/widgets/cupertino/std-widgets-impl.slint @@ -7,14 +7,9 @@ export { ListItem } from "components.slint"; export { LineEdit } from "lineedit.slint"; import { CupertinoPalette } from "styling.slint"; -export global LayoutSpec { +export global StyleMetrics { out property layout-spacing: 10px; out property layout-padding: 12px; -} - -export global StyleMetrics { - out property layout-spacing: LayoutSpec.layout-spacing; - out property layout-padding: LayoutSpec.layout-padding; out property text-cursor-width: 1px; out property window-background: CupertinoPalette.background; out property default-text-color: CupertinoPalette.foreground; diff --git a/internal/compiler/widgets/cupertino/std-widgets.slint b/internal/compiler/widgets/cupertino/std-widgets.slint index 3b9cca3d8c3..321e57c4cb3 100644 --- a/internal/compiler/widgets/cupertino/std-widgets.slint +++ b/internal/compiler/widgets/cupertino/std-widgets.slint @@ -5,7 +5,7 @@ export { AboutSlint } from "../common/about-slint.slint"; export { StandardButton } from "../common/standardbutton.slint"; -export { StyleMetrics, ScrollView, Button, Palette, LayoutSpec } from "std-widgets-impl.slint"; +export { StyleMetrics, ScrollView, Button, Palette } from "std-widgets-impl.slint"; export { CheckBox } from "checkbox.slint"; export { ComboBox } from "combobox.slint"; diff --git a/internal/compiler/widgets/fluent/std-widgets-impl.slint b/internal/compiler/widgets/fluent/std-widgets-impl.slint index e094380de3c..d12bbd54a12 100644 --- a/internal/compiler/widgets/fluent/std-widgets-impl.slint +++ b/internal/compiler/widgets/fluent/std-widgets-impl.slint @@ -7,14 +7,9 @@ export { ListItem } from "components.slint"; export { LineEdit } from "lineedit.slint"; import { FluentPalette } from "styling.slint"; -export global LayoutSpec { +export global StyleMetrics { out property layout-spacing: 8px; out property layout-padding: 8px; -} - -export global StyleMetrics { - out property layout-spacing: LayoutSpec.layout-spacing; - out property layout-padding: LayoutSpec.layout-padding; out property text-cursor-width: 1px; out property window-background: FluentPalette.background; out property default-text-color: FluentPalette.foreground; @@ -39,4 +34,3 @@ export global Palette { out property border: FluentPalette.border; in-out property color-scheme <=> FluentPalette.color-scheme; } - diff --git a/internal/compiler/widgets/fluent/std-widgets.slint b/internal/compiler/widgets/fluent/std-widgets.slint index a2ffed218bd..1a964b8b413 100644 --- a/internal/compiler/widgets/fluent/std-widgets.slint +++ b/internal/compiler/widgets/fluent/std-widgets.slint @@ -5,7 +5,7 @@ export { AboutSlint } from "../common/about-slint.slint"; export { StandardButton } from "../common/standardbutton.slint"; -export { StyleMetrics, ScrollView, Button, Palette, LayoutSpec } from "std-widgets-impl.slint"; +export { StyleMetrics, ScrollView, Button, Palette } from "std-widgets-impl.slint"; export { CheckBox } from "checkbox.slint"; export { ComboBox } from "combobox.slint"; diff --git a/internal/compiler/widgets/material/std-widgets-impl.slint b/internal/compiler/widgets/material/std-widgets-impl.slint index f2628e9a991..2186847e5f6 100644 --- a/internal/compiler/widgets/material/std-widgets-impl.slint +++ b/internal/compiler/widgets/material/std-widgets-impl.slint @@ -10,15 +10,12 @@ export { Switch } from "switch.slint"; export { ListItem } from "components.slint"; export { LineEdit } from "lineedit.slint"; -export global LayoutSpec { - out property layout-spacing: 16px; - out property layout-padding: 16px; -} export global StyleMetrics { - out property layout-spacing: LayoutSpec.layout-spacing; - out property layout-padding: LayoutSpec.layout-padding; + out property layout-spacing: 16px; + out property layout-padding: 16px; out property text-cursor-width: 2px; + out property default-text-color: MaterialPalette.foreground; out property textedit-background: transparent; out property textedit-text-color: MaterialPalette.foreground; @@ -43,4 +40,3 @@ export global Palette { out property border: MaterialPalette.border; in-out property color-scheme <=> MaterialPalette.color-scheme; } - diff --git a/internal/compiler/widgets/material/std-widgets.slint b/internal/compiler/widgets/material/std-widgets.slint index 7fa561d748b..e5fc545b1b0 100644 --- a/internal/compiler/widgets/material/std-widgets.slint +++ b/internal/compiler/widgets/material/std-widgets.slint @@ -5,7 +5,7 @@ export { AboutSlint } from "../common/about-slint.slint"; export { StandardButton } from "../common/standardbutton.slint"; -export { StyleMetrics, ScrollView, Button, CheckBox, Palette, LayoutSpec } from "std-widgets-impl.slint"; +export { StyleMetrics, ScrollView, Button, CheckBox, Palette } from "std-widgets-impl.slint"; export { LineEdit } from "lineedit.slint"; export { TabWidgetImpl, TabImpl, TabBarImpl, TabWidget } from "tabwidget.slint"; export { GroupBox } from "groupbox.slint"; diff --git a/internal/compiler/widgets/qt/std-widgets-impl.slint b/internal/compiler/widgets/qt/std-widgets-impl.slint index 452e1c8d151..a411f07bd20 100644 --- a/internal/compiler/widgets/qt/std-widgets-impl.slint +++ b/internal/compiler/widgets/qt/std-widgets-impl.slint @@ -8,9 +8,4 @@ export { NativePalette as Palette } export { ScrollView } from "scrollview.slint"; export { LineEdit } from "lineedit.slint"; -export global LayoutSpec { - out property layout-spacing: NativeStyleMetrics.layout-spacing; - out property layout-padding: NativeStyleMetrics.layout-padding; -} - export component ListItem inherits NativeStandardListViewItem {} diff --git a/internal/compiler/widgets/qt/std-widgets.slint b/internal/compiler/widgets/qt/std-widgets.slint index c3dfe59585b..3b4dc899944 100644 --- a/internal/compiler/widgets/qt/std-widgets.slint +++ b/internal/compiler/widgets/qt/std-widgets.slint @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 export { AboutSlint } from "../common/about-slint.slint"; -export { StyleMetrics, ScrollView, Palette, LayoutSpec } from "std-widgets-impl.slint"; +export { StyleMetrics, ScrollView, Palette } from "std-widgets-impl.slint"; export { StandardTableView } from "tableview.slint"; export { Button, StandardButton } from "button.slint"; export { CheckBox } from "checkbox.slint"; From bb58f439750b662a3485fa66b24202aac92d3ad3 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 11 Dec 2024 18:16:48 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Simon Hausmann Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 +- internal/compiler/passes/resolving.rs | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eed914e380..f56477b4916 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ All notable changes to this project are documented in this file. - LineEdit: fixed cursor drawing out of bounds (#6243) - TabWidget: fixed tabs overflow behavior (#6517) - SpinBox: added `horizontal-alignment` - - Undeprecared `StyleMetrics` layout properties + - Undeprecated `StyleMetrics` layout properties - Slider: added `step` property - StandardListView: improved keyboard navigation (#6955) diff --git a/internal/compiler/passes/resolving.rs b/internal/compiler/passes/resolving.rs index c6ced832eeb..dc38c400bc8 100644 --- a/internal/compiler/passes/resolving.rs +++ b/internal/compiler/passes/resolving.rs @@ -1447,12 +1447,10 @@ fn continue_lookup_within_element( &lookup_result.resolved_name, &second, ); - } else if let Some(deprecated) = crate::lookup::check_deprecated_stylemetrics(elem, ctx, &prop_name) { - ctx.diag.push_property_deprecation_warning( - &prop_name, - &deprecated, - &second, - ); + } else if let Some(deprecated) = + crate::lookup::check_deprecated_stylemetrics(elem, ctx, &prop_name) + { + ctx.diag.push_property_deprecation_warning(&prop_name, &deprecated, &second); } let prop = Expression::PropertyReference(NamedReference::new( elem,