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

Remove LayoutSpec and undeprecate StyleMetrics.layout-* properties #7069

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
ogoffart marked this conversation as resolved.
Show resolved Hide resolved
- Slider: added `step` property
- StandardListView: improved keyboard navigation (#6955)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ Defines the brush that is used for borders such as separators and widget borders
### color-scheme
<SlintProperty propName="color-scheme" typeName="enum" enumName="ColorScheme" propertyVisibility="in-out">
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.
</SlintProperty>


## 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
Expand Down
12 changes: 6 additions & 6 deletions examples/gallery/ui/pages/table_view_page.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// 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";

Expand All @@ -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 <int> sort-index: -1;
property <bool> 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\"");
Expand All @@ -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;
Expand Down Expand Up @@ -64,7 +64,7 @@ export component TableViewPage inherits Page {
filter-edit := LineEdit {
placeholder-text: @tr("Enter filter text");
}
}
}
}
}
}
Expand Down
44 changes: 28 additions & 16 deletions internal/compiler/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,14 @@ impl LookupObject for ElementRc {
f: &mut impl FnMut(&SmolStr, LookupResult) -> Option<R>,
) -> Option<R> {
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);
}
}
Expand All @@ -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(
Expand Down Expand Up @@ -431,14 +433,35 @@ 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
}
}
}

pub fn check_deprecated_stylemetrics(
elem: &ElementRc,
ctx: &LookupCtx<'_>,
name: &SmolStr,
) -> Option<String> {
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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions internal/compiler/passes/resolving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

}
14 changes: 7 additions & 7 deletions internal/compiler/widgets/common/layout.slint
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// 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;
}
9 changes: 1 addition & 8 deletions internal/compiler/widgets/cosmic/std-widgets-impl.slint
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ export { LineEdit } from "lineedit.slint";

import { CosmicPalette } from "styling.slint";


export global LayoutSpec {
export global StyleMetrics {
out property <length> layout-spacing: 8px;
out property <length> layout-padding: 8px;
}

export global StyleMetrics {
out property <length> layout-spacing: LayoutSpec.layout-spacing;
out property <length> layout-padding: LayoutSpec.layout-padding;
out property <length> text-cursor-width: 1px;
out property <color> window-background: CosmicPalette.background;
out property <color> default-text-color: CosmicPalette.foreground;
Expand All @@ -42,4 +36,3 @@ export global Palette {
out property <brush> border: CosmicPalette.border;
in-out property <ColorScheme> color-scheme <=> CosmicPalette.color-scheme;
}

2 changes: 1 addition & 1 deletion internal/compiler/widgets/cosmic/std-widgets.slint
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 0 additions & 6 deletions internal/compiler/widgets/cosmic/styling.slint
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ export global CosmicPalette {
out property <brush> state-secondary: dark-color-scheme ? #000000 : #ffffff;
}

export global CosmicLayoutSpec {
out property <length> layout-spacing: 8px;
out property <length> layout-padding: 8px;
out property <length> text-cursor-width: 1px;
}

export global Icons {
out property <image> arrow-down: @image-url("_arrow_down.svg");
out property <image> arrow-up: @image-url("_arrow_up.svg");
Expand Down
7 changes: 1 addition & 6 deletions internal/compiler/widgets/cupertino/std-widgets-impl.slint
Original file line number Diff line number Diff line change
Expand Up @@ -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 <length> layout-spacing: 10px;
out property <length> layout-padding: 12px;
}

export global StyleMetrics {
out property <length> layout-spacing: LayoutSpec.layout-spacing;
out property <length> layout-padding: LayoutSpec.layout-padding;
out property <length> text-cursor-width: 1px;
out property <color> window-background: CupertinoPalette.background;
out property <color> default-text-color: CupertinoPalette.foreground;
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/widgets/cupertino/std-widgets.slint
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 1 addition & 7 deletions internal/compiler/widgets/fluent/std-widgets-impl.slint
Original file line number Diff line number Diff line change
Expand Up @@ -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 <length> layout-spacing: 8px;
out property <length> layout-padding: 8px;
}

export global StyleMetrics {
out property <length> layout-spacing: LayoutSpec.layout-spacing;
out property <length> layout-padding: LayoutSpec.layout-padding;
out property <length> text-cursor-width: 1px;
out property <color> window-background: FluentPalette.background;
out property <color> default-text-color: FluentPalette.foreground;
Expand All @@ -39,4 +34,3 @@ export global Palette {
out property <brush> border: FluentPalette.border;
in-out property <ColorScheme> color-scheme <=> FluentPalette.color-scheme;
}

2 changes: 1 addition & 1 deletion internal/compiler/widgets/fluent/std-widgets.slint
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
10 changes: 3 additions & 7 deletions internal/compiler/widgets/material/std-widgets-impl.slint
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ export { Switch } from "switch.slint";
export { ListItem } from "components.slint";
export { LineEdit } from "lineedit.slint";

export global LayoutSpec {
out property <length> layout-spacing: 16px;
out property <length> layout-padding: 16px;
}

export global StyleMetrics {
out property <length> layout-spacing: LayoutSpec.layout-spacing;
out property <length> layout-padding: LayoutSpec.layout-padding;
out property <length> layout-spacing: 16px;
out property <length> layout-padding: 16px;
out property <length> text-cursor-width: 2px;

out property <color> default-text-color: MaterialPalette.foreground;
out property <color> textedit-background: transparent;
out property <color> textedit-text-color: MaterialPalette.foreground;
Expand All @@ -43,4 +40,3 @@ export global Palette {
out property <brush> border: MaterialPalette.border;
in-out property <ColorScheme> color-scheme <=> MaterialPalette.color-scheme;
}

2 changes: 1 addition & 1 deletion internal/compiler/widgets/material/std-widgets.slint
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 0 additions & 5 deletions internal/compiler/widgets/qt/std-widgets-impl.slint
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,4 @@ export { NativePalette as Palette }
export { ScrollView } from "scrollview.slint";
export { LineEdit } from "lineedit.slint";

export global LayoutSpec {
out property <length> layout-spacing: NativeStyleMetrics.layout-spacing;
out property <length> layout-padding: NativeStyleMetrics.layout-padding;
}

export component ListItem inherits NativeStandardListViewItem {}
2 changes: 1 addition & 1 deletion internal/compiler/widgets/qt/std-widgets.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-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";
Expand Down
Loading