Skip to content

Commit 4762a56

Browse files
committed
Update sidebar to use new Palette for theme colors
1 parent 2d3805a commit 4762a56

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

demo/ui/widgets/side_bar.slint

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Copyright © SixtyFPS GmbH <info@slint.dev>
22
// SPDX-License-Identifier: MIT
33

4-
import { StyleMetrics } from "std-widgets.slint";
4+
import { Palette, StyleMetrics } from "std-widgets.slint";
55

66
component SideBarItem inherits Rectangle {
77
callback clicked <=> touch.clicked;
8-
in-out property<string> text <=> label.text;
9-
in property<bool> selected;
10-
in property<bool> has-focus;
8+
in-out property <string> text <=> label.text;
9+
in property <bool> selected;
10+
in property <bool> has-focus;
1111

1212
min-height: l.preferred-height;
1313

1414
state := Rectangle {
1515
opacity: 0;
16-
background: StyleMetrics.window-background;
16+
background: Palette.background;
1717

1818
animate opacity { duration: 150ms; }
1919
}
@@ -24,9 +24,9 @@ component SideBarItem inherits Rectangle {
2424
spacing: 0px;
2525

2626
label := Text {
27-
color: StyleMetrics.default-text-color;
27+
color: Palette.foreground;
2828
vertical-alignment: center;
29-
}
29+
}
3030
}
3131

3232
touch := TouchArea {
@@ -35,26 +35,26 @@ component SideBarItem inherits Rectangle {
3535
}
3636

3737
states [
38-
pressed when touch.pressed : {
38+
pressed when touch.pressed: {
3939
state.opacity: 0.8;
4040
}
41-
hover when touch.has-hover : {
41+
hover when touch.has-hover: {
4242
state.opacity: 0.6;
4343
}
44-
selected when root.selected : {
44+
selected when root.selected: {
4545
state.opacity: 1;
4646
}
47-
focused when root.has-focus : {
47+
focused when root.has-focus: {
4848
state.opacity: 0.8;
4949
}
5050
]
5151
}
5252

5353
export component SideBar inherits Rectangle {
54-
in property<[string]> model: [];
55-
out property<int> current-item: 0;
56-
in property<string> title <=> label.text;
57-
out property<int> current-focused: fs.has-focus ? fs.focused-tab : -1; // The currently focused tab
54+
in property <[string]> model: [];
55+
out property <int> current-item: 0;
56+
in property <string> title <=> label.text;
57+
out property <int> current-focused: fs.has-focus ? fs.focused-tab : -1; // The currently focused tab
5858
width: 180px;
5959

6060
forward-focus: fs;
@@ -63,33 +63,33 @@ export component SideBar inherits Rectangle {
6363
accessible-delegate-focus: root.current-focused >= 0 ? root.current-focused : root.current-item;
6464

6565
Rectangle {
66-
background: StyleMetrics.window-background.darker(0.2);
66+
background: Palette.background.darker(0.2);
6767

6868
fs := FocusScope {
69-
x:0;
69+
x: 0;
7070
width: 0px; // Do not react on clicks
71-
property<int> focused-tab: 0;
71+
property <int> focused-tab: 0;
7272

7373
key-pressed(event) => {
7474
if (event.text == "\n") {
75-
root.current-item = root.current-focused;
76-
return accept;
75+
root.current-item = root.current-focused;
76+
return accept;
7777
}
7878
if (event.text == Key.UpArrow) {
79-
self.focused-tab = Math.max(self.focused-tab - 1, 0);
80-
return accept;
79+
self.focused-tab = Math.max(self.focused-tab - 1, 0);
80+
return accept;
8181
}
8282
if (event.text == Key.DownArrow) {
83-
self.focused-tab = Math.min(self.focused-tab + 1, root.model.length - 1);
84-
return accept;
83+
self.focused-tab = Math.min(self.focused-tab + 1, root.model.length - 1);
84+
return accept;
8585
}
8686
return reject;
8787
}
8888

8989
key-released(event) => {
9090
if (event.text == " ") {
91-
root.current-item = root.current-focused;
92-
return accept;
91+
root.current-item = root.current-focused;
92+
return accept;
9393
}
9494
return reject;
9595
}
@@ -110,11 +110,13 @@ export component SideBar inherits Rectangle {
110110
navigation := VerticalLayout {
111111
alignment: start;
112112
vertical-stretch: 0;
113-
for item[index] in root.model : SideBarItem {
113+
for item[index] in root.model: SideBarItem {
114114
has-focus: index == root.current-focused;
115115
text: item;
116116
selected: index == root.current-item;
117-
clicked => { root.current-item = index; }
117+
clicked => {
118+
root.current-item = index;
119+
}
118120
}
119121
}
120122

@@ -124,7 +126,7 @@ export component SideBar inherits Rectangle {
124126
padding-right: StyleMetrics.layout-padding;
125127

126128
@children
127-
}
129+
}
128130
}
129131
}
130132
}

0 commit comments

Comments
 (0)