1+ import { VirtualKeyboardButton } from "../virtual_keyboard.slint" ;
2+ import { Icons } from "../constants.slint" ;
3+ import { StyleMetrics } from "std-widgets.slint" ;
4+ import { TemperatureSensors } from "../state.slint" ;
5+
6+ export component NumberPad inherits Rectangle
7+ {
8+ in property <string> name;
9+ callback accept (number: int);
10+ callback cancel ();
11+ property <int> current-number: 0 ;
12+ in property <bool> can_go_negative: false ;
13+
14+ function add (key: int) {
15+ if (current-number * 10 + key > 999
16+ || current-number * 10 - key < -999 ) {
17+ return ;
18+ }
19+
20+ current-number = current-number >= 0
21+ ? current-number * 10 + key
22+ : current-number * 10 - key;
23+ }
24+
25+ function remove () {
26+ current-number = current-number >= 0
27+ ? floor (current-number / 10 )
28+ : ceil (current-number / 10 );
29+ }
30+
31+ VerticalLayout {
32+ spacing: 5px ;
33+
34+ HorizontalLayout {
35+ spacing: 5px ;
36+ vertical-stretch: 1 ;
37+
38+ Text {
39+ text: name + ": " + current-number;
40+ horizontal-alignment: center;
41+ vertical-alignment: center;
42+ font-size: 20px ;
43+ font-weight: 900 ;
44+ horizontal-stretch: 5 ;
45+ }
46+
47+ VirtualKeyboardButton { icon: Icons.backspace; key-pressed => { remove (); } horizontal-stretch: 1 ; }
48+
49+ if can_go_negative: VirtualKeyboardButton { key: current-number >= 0 ? "-" : "+" ; key-pressed => { current-number *= -1 ; } }
50+ }
51+
52+ HorizontalLayout {
53+ spacing: 5px ;
54+ vertical-stretch: 1 ;
55+ VirtualKeyboardButton { key: "1" ; key-pressed => { add (1 ) } }
56+ VirtualKeyboardButton { key: "2" ; key-pressed => { add (2 ) } }
57+ VirtualKeyboardButton { key: "3" ; key-pressed => { add (3 ) } }
58+ VirtualKeyboardButton { icon: Icons.check; key-pressed => { accept (current-number); current-number = 0 ; } }
59+ }
60+
61+ HorizontalLayout {
62+ spacing: 5px ;
63+ vertical-stretch: 1 ;
64+ VirtualKeyboardButton { key: "4" ; key-pressed => { add (4 ) } }
65+ VirtualKeyboardButton { key: "5" ; key-pressed => { add (5 ) } }
66+ VirtualKeyboardButton { key: "6" ; key-pressed => { add (6 ) } }
67+ VirtualKeyboardButton { icon: Icons.close; key-pressed => { cancel (); } }
68+ }
69+
70+ HorizontalLayout {
71+ spacing: 5px ;
72+ vertical-stretch: 1 ;
73+ VirtualKeyboardButton { key: "7" ; key-pressed => { add (7 ) } }
74+ VirtualKeyboardButton { key: "8" ; key-pressed => { add (8 ) } }
75+ VirtualKeyboardButton { key: "9" ; key-pressed => { add (9 ) } }
76+ VirtualKeyboardButton { key: "0" ; key-pressed => { add (0 ) } }
77+ }
78+ }
79+ }
80+
81+ export component TemperatureEntry
82+ {
83+ out property <bool> is_keyboard_open: false ;
84+ property <string> internal_temp_device_name;
85+ property <string> friendly_temp_device_name;
86+
87+ public function open_keyboard (internal_name: string, friendly_name: string) {
88+ internal_temp_device_name = internal_name;
89+ friendly_temp_device_name = friendly_name;
90+ is_keyboard_open = true ;
91+ }
92+
93+ width: 100% ;
94+ height: 100% ;
95+
96+ if is_keyboard_open: GridLayout {
97+ padding-left: StyleMetrics.layout-padding / 2 ;
98+ padding-right: StyleMetrics.layout-padding / 2 ;
99+ NumberPad {
100+ name: friendly_temp_device_name;
101+ accept (number) => {
102+ TemperatureSensors.set_new_target_temperature (internal_temp_device_name, number);
103+ is_keyboard_open = false ;
104+ }
105+ cancel () => {
106+ is_keyboard_open = false ;
107+ }
108+ }
109+ }
110+ }
0 commit comments