Skip to content

Commit 1978adb

Browse files
Move constants to constants file; add standardised horizontal/vertical layouts
1 parent 917a8dc commit 1978adb

19 files changed

Lines changed: 280 additions & 198 deletions

src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
8585

8686
register_temperature_set_new_target_temperature(&ui, &moonraker_connection);
8787

88-
register_util_image_exists(&ui);
8988
register_util_format_bytes(&ui);
9089
register_util_prettify_name(&ui);
9190
register_util_time_in_seconds_to_string(&ui);

src/ui_functions/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub mod util_format_bytes;
22
pub mod filesystem_fetch_metadata;
3-
pub mod util_image_exists;
43
pub mod filesystem_list_files;
54
pub mod util_prettify_name;
65
pub mod temperature_set_new_target_temperature;
@@ -15,7 +14,6 @@ pub mod util_time_in_seconds_to_string;
1514

1615
pub use util_format_bytes::*;
1716
pub use filesystem_fetch_metadata::*;
18-
pub use util_image_exists::*;
1917
pub use filesystem_list_files::*;
2018
pub use util_prettify_name::*;
2119
pub use temperature_set_new_target_temperature::*;

src/ui_functions/util_image_exists.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

ui/components/bottom-bar.slint

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ export component BottomBar inherits Rectangle {
77
background: Palette.alternate-background;
88
in property <string> text;
99

10-
HorizontalLayout {
11-
Text {
12-
text: text;
13-
horizontal-alignment: center;
14-
vertical-alignment: center;
15-
color: Palette.alternate-foreground;
16-
}
10+
Text {
11+
text: text;
12+
horizontal-alignment: center;
13+
vertical-alignment: bottom;
14+
color: Palette.alternate-foreground;
1715
}
1816
}
1917

ui/components/ghost-button.slint

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
import { Palette } from "std-widgets.slint";
2+
import { Constants } from "../constants.slint";
23

3-
export component GhostButton inherits VerticalLayout {
4+
export component GhostButton inherits Rectangle {
45
in property <string> text;
56
in property <color> text-color: Palette.foreground;
67
callback clicked;
78

89
states [
910
pressed when touch-area.pressed : {
10-
container.background: Palette.selection-background;
11+
root.background: Palette.selection-background;
1112
}
1213
]
1314

14-
container := Rectangle {
15-
min-height: t.height * 2;
16-
min-width: t.width * 1.5;
17-
border-radius: 10px;
18-
//background: red;
15+
min-height: t.height * 2;
16+
min-width: t.width * 1.5;
17+
border-radius: Constants.radius-md;
18+
//background: red;
1919

20-
t := Text {
21-
text: text;
22-
color: text-color;
23-
font-weight: 600;
24-
}
20+
t := Text {
21+
text: text;
22+
color: text-color;
23+
font-weight: 600;
24+
}
2525

26-
touch-area := TouchArea {
27-
clicked => { root.clicked(); }
28-
}
26+
touch-area := TouchArea {
27+
clicked => { root.clicked(); }
2928
}
3029
}

ui/components/horizontal.slint

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
import { Palette, StyleMetrics } from "std-widgets.slint";
3+
import { Constants } from "../constants.slint";
4+
export component HorizontalStart inherits HorizontalLayout {
5+
spacing: Constants.spacing;
6+
alignment: LayoutAlignment.start;
7+
}
8+
9+
export component HorizontalStretch inherits HorizontalStart {
10+
alignment: LayoutAlignment.stretch;
11+
}
12+
13+
export component HorizontalCenter inherits HorizontalStart {
14+
alignment: LayoutAlignment.center;
15+
}
16+
17+
export component HorizontalEnd inherits HorizontalStart {
18+
alignment: LayoutAlignment.end;
19+
}
20+
21+
export component HorizontalScrollable inherits Flickable {
22+
in property <length> list-padding <=> layout.padding;
23+
in property <length> list-spacing <=> layout.spacing;
24+
25+
layout := HorizontalStart {
26+
@children
27+
}
28+
}

ui/components/icon-button.slint

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Palette, StyleMetrics } from "std-widgets.slint";
2+
import { Constants } from "../constants.slint";
23

34
export component IconButton inherits Rectangle {
45
in property <image> icon <=> img.source;
@@ -30,13 +31,13 @@ export component IconButton inherits Rectangle {
3031
export component RightSideIconButton inherits IconButton {
3132
border-top-left-radius: 0;
3233
border-bottom-left-radius: 0;
33-
border-top-right-radius: StyleMetrics.layout-padding;
34-
border-bottom-right-radius: StyleMetrics.layout-padding;
34+
border-top-right-radius: Constants.radius-lg;
35+
border-bottom-right-radius: Constants.radius-lg;
3536
}
3637

3738
export component LeftSideIconButton inherits IconButton {
38-
border-top-left-radius: StyleMetrics.layout-padding;
39-
border-bottom-left-radius: StyleMetrics.layout-padding;
39+
border-top-left-radius: Constants.radius-lg;
40+
border-bottom-left-radius: Constants.radius-lg;
4041
border-top-right-radius: 0;
4142
border-bottom-right-radius: 0;
4243
}

ui/components/number-pad.slint

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { VirtualKeyboardButton } from "../virtual_keyboard.slint";
2-
import { Icons } from "../constants.slint";
2+
import { Icons, Constants } from "../constants.slint";
33
import { StyleMetrics } from "std-widgets.slint";
44
import { TemperatureSensors } from "../state.slint";
5+
import { VerticalStart, VerticalStretch } from "vertical.slint";
6+
import { HorizontalStart, HorizontalStretch } from "horizontal.slint";
57

68
export component NumberPad inherits Rectangle
79
{
@@ -28,19 +30,16 @@ export component NumberPad inherits Rectangle
2830
: ceil(current-number / 10);
2931
}
3032

31-
VerticalLayout {
32-
spacing: 5px;
33-
34-
HorizontalLayout {
35-
spacing: 5px;
33+
VerticalStretch {
34+
HorizontalStretch {
3635
vertical-stretch: 1;
3736

3837
Text {
3938
text: name + ": " + current-number;
4039
horizontal-alignment: center;
4140
vertical-alignment: center;
42-
font-size: 20px;
43-
font-weight: 900;
41+
font-size: Constants.font-size-lg;
42+
font-weight: Constants.font-weight-bold;
4443
horizontal-stretch: 5;
4544
}
4645

@@ -49,26 +48,23 @@ export component NumberPad inherits Rectangle
4948
if can_go_negative: VirtualKeyboardButton { key: current-number >= 0 ? "-" : "+"; key-pressed => { current-number *= -1; } }
5049
}
5150

52-
HorizontalLayout {
53-
spacing: 5px;
51+
HorizontalStretch {
5452
vertical-stretch: 1;
5553
VirtualKeyboardButton { key: "1"; key-pressed => { add(1) } }
5654
VirtualKeyboardButton { key: "2"; key-pressed => { add(2) } }
5755
VirtualKeyboardButton { key: "3"; key-pressed => { add(3) } }
5856
VirtualKeyboardButton { icon: Icons.check; key-pressed => { accept(current-number); current-number = 0; } }
5957
}
6058

61-
HorizontalLayout {
62-
spacing: 5px;
59+
HorizontalStretch {
6360
vertical-stretch: 1;
6461
VirtualKeyboardButton { key: "4"; key-pressed => { add(4) } }
6562
VirtualKeyboardButton { key: "5"; key-pressed => { add(5) } }
6663
VirtualKeyboardButton { key: "6"; key-pressed => { add(6) } }
6764
VirtualKeyboardButton { icon: Icons.close; key-pressed => { cancel(); } }
6865
}
6966

70-
HorizontalLayout {
71-
spacing: 5px;
67+
HorizontalStretch {
7268
vertical-stretch: 1;
7369
VirtualKeyboardButton { key: "7"; key-pressed => { add(7) } }
7470
VirtualKeyboardButton { key: "8"; key-pressed => { add(8) } }
@@ -94,8 +90,8 @@ export component TemperatureEntry
9490
height: 100%;
9591

9692
if is_keyboard_open: GridLayout {
97-
padding-left: StyleMetrics.layout-padding / 2;
98-
padding-right: StyleMetrics.layout-padding / 2;
93+
padding-left: Constants.padding-half;
94+
padding-right: Constants.padding-half;
9995
NumberPad {
10096
name: friendly_temp_device_name;
10197
accept(number) => {

ui/components/page.slint

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { StyleMetrics } from "std-widgets.slint";
2+
import { Constants } from "../constants.slint";
23

34
export component Page inherits Rectangle {
45
in property <string> header;
56
width: 100%;
67
height: 100%;
78
GridLayout {
8-
padding: StyleMetrics.layout-padding / 2;
9+
padding-top: Constants.padding-half;
10+
padding-bottom: Constants.padding-half;
11+
padding-left: Constants.padding;
12+
padding-right: Constants.padding;
913
Rectangle {
1014
vertical-stretch: 1;
1115
@children

ui/components/small-button.slint

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { Palette, StyleMetrics } from "std-widgets.slint";
22
import { Utils } from "../state.slint";
3+
import { Constants } from "../constants.slint";
4+
import { HorizontalStart, HorizontalCenter } from "horizontal.slint";
35

46
export component SmallButton inherits Rectangle {
57
in property <string> text;
68
in property <image> icon;
79
callback clicked();
810

911
background: Palette.control-background;
10-
border-radius: 20px;
12+
border-radius: Constants.radius-lg;
1113

1214
states [
1315
pressed when touch-area.pressed : {
@@ -16,17 +18,16 @@ export component SmallButton inherits Rectangle {
1618
]
1719

1820
GridLayout {
19-
padding-left: 10px;
20-
padding-right: 10px;
21+
padding-left: Constants.padding-half;
22+
padding-right: Constants.padding-half;
2123

2224
Rectangle {
2325
touch-area := TouchArea {
2426
clicked => { root.clicked(); }
2527
}
2628

27-
HorizontalLayout {
28-
spacing: 10px;
29-
alignment: center;
29+
HorizontalCenter {
30+
spacing: Constants.spacing-half;
3031
if Utils.image_exists(root.icon) : Image {
3132
source: root.icon;
3233
colorize: Palette.control-foreground;

0 commit comments

Comments
 (0)