11import { Page } from "../components/page.slint" ;
22import { ScrollView } from "std-widgets.slint" ;
3- import { QuickActions } from "../state.slint" ;
3+ import { QuickActions , PowerDevices } from "../state.slint" ;
44import { Icons , Constants } from "../constants.slint" ;
5- import { Palette , StyleMetrics } from "std-widgets.slint" ;
5+ import { Palette , StyleMetrics , Switch } from "std-widgets.slint" ;
66import { SmallButton } from "../components/small-button.slint" ;
77import { VerticalScrollable } from "../components/vertical.slint" ;
88import { HorizontalStretch } from "../components/horizontal.slint" ;
9+ import { PowerDevice } from "../types.slint" ;
910
10- component QuickAction inherits Rectangle
11+ component PowerDevice inherits HorizontalStretch
1112{
12- in property <string> quick-action;
13- width: 100% ;
13+ in property <PowerDevice> power-device;
1414
15- HorizontalStretch {
16- Image {
17- source: Icons.action;
18- colorize: Palette.foreground;
19- width: Constants.thumbnail-size;
20- height: Constants.thumbnail-size;
21- }
15+ Image {
16+ source: Icons.power-device;
17+ colorize: Palette.foreground;
18+ }
2219
23- Text {
24- text: quick-action;
25- horizontal-stretch: 1 ;
26- vertical-alignment: center;
27- overflow: elide;
20+ Text {
21+ text: power-device.device;
22+ horizontal-stretch: 1 ;
23+ vertical-alignment: center;
24+ overflow: elide;
25+ }
26+
27+ Switch {
28+ text: self .checked ? "On" : "Off" ;
29+ vertical-stretch: 1 ;
30+ checked: power-device.status == "On" ;
31+ toggled () => {
32+ PowerDevices.set_power_device_state (power-device.device, self .checked);
2833 }
34+ }
35+ }
36+
37+ component QuickAction inherits HorizontalStretch
38+ {
39+ in property <string> quick-action;
40+
41+ Image {
42+ source: Icons.action;
43+ colorize: Palette.foreground;
44+ }
45+
46+ Text {
47+ text: quick-action;
48+ horizontal-stretch: 1 ;
49+ vertical-alignment: center;
50+ overflow: elide;
51+ }
2952
30- SmallButton {
31- text: "Run" ;
32- width: 50px ;
33- vertical-stretch: 1 ;
34- border-radius: Constants.radius-md;
35- clicked => { QuickActions.execute_quick_action (quick-action); }
53+ SmallButton {
54+ text: "Run" ;
55+ width: 50px ;
56+ vertical-stretch: 1 ;
57+ border-radius: Constants.radius-md;
58+ clicked => {
59+ QuickActions.execute_quick_action (quick-action);
3660 }
3761 }
3862}
@@ -41,11 +65,19 @@ export component QuickActionsPage inherits Page
4165{
4266 header: "Quick Actions" ;
4367
44- // TODO: Power devices
45-
68+ init => {
69+ PowerDevices.fetch_power_devices ();
70+ }
71+
4672 VerticalScrollable {
73+ for power-device in PowerDevices.power_devices: PowerDevice {
74+ power-device: power-device;
75+ height: Constants.thumbnail-size;
76+ }
77+
4778 for quick-action in QuickActions.quick-actions: QuickAction {
4879 quick-action: quick-action;
80+ height: Constants.thumbnail-size;
4981 }
5082 }
5183
@@ -56,4 +88,25 @@ export component QuickActionsPage inherits Page
5688 horizontal-alignment: center;
5789 }
5890 }
91+ }
92+
93+ component LivePreviewTest {
94+ width : 480px - 100px ;
95+ height : 272px - 40px ;
96+
97+ init => {
98+ QuickActions.quick-actions = [
99+ "Test1" ,
100+ "Test2"
101+ ];
102+
103+ PowerDevices.power_devices = [
104+ { device: "Test device" , status: "Off" , locked_while_printing: false , device_type: "Simulated" },
105+ { device: "Test device 2" , status: "On" , locked_while_printing: false , device_type: "Simulated" }
106+ ]
107+ }
108+
109+ QuickActionsPage {
110+
111+ }
59112}
0 commit comments