1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: MIT |
3 | |
4 | import { LineEdit, ScrollView} from "std-widgets.slint" ; |
5 | |
6 | struct CellContent { value: float, formula: string } |
7 | |
8 | export component MainWindow inherits Window { |
9 | in property <[[CellContent]]> cells; |
10 | |
11 | private property <length> cell-height: 32px; |
12 | private property <length> cell-width: 100px; |
13 | private property <{r: int, c: int}> active-cell: { r: -1, c: -1 }; |
14 | |
15 | ScrollView { |
16 | width: 100%; |
17 | height: 100%; |
18 | viewport-width: 20px + 26 * root.cell-width; |
19 | viewport-height: 100 * root.cell-height; |
20 | |
21 | for letter[idx] in ["A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" , "L" , "M" , "N" , "O" , "P" , "Q" , "R" , "S" , "T" , "U" , "V" , "W" , "X" , "Y" , "Z" ] : Rectangle { |
22 | y:0; |
23 | x: 20px + idx * root.cell-width; |
24 | height: root.cell-height; |
25 | width: root.cell-width; |
26 | Text { x:0;y:0; text: letter; } |
27 | } |
28 | for row[row-idx] in root.cells : Rectangle { |
29 | y: root.cell-height + row-idx * root.cell-height; |
30 | height: root.cell-height; |
31 | |
32 | Text { x:0;y:0; text: row_idx; } |
33 | |
34 | for cell[col-idx] in row: Rectangle { |
35 | property <bool> is-active: root.active-cell.r == row-idx && root.active-cell.c == col-idx; |
36 | |
37 | y:0; |
38 | height: root.cell-height; |
39 | width: root.cell-width; |
40 | border-color: gray; |
41 | border-width: 1px; |
42 | x: 20px + col-idx * root.cell-width; |
43 | |
44 | Text { |
45 | visible: !is-active && cell.formula != "" ; |
46 | text: " " + cell.value; |
47 | vertical-alignment: center; |
48 | width: 100%; |
49 | height: 100%; |
50 | } |
51 | |
52 | TouchArea { |
53 | clicked => { |
54 | l.text = cell.formula; |
55 | root.active-cell = {r: row-idx, c: col-idx}; |
56 | l.focus(); |
57 | } |
58 | } |
59 | |
60 | l := LineEdit { |
61 | edited => { |
62 | cell = { value: self.text.to-float(), formula: self.text }; |
63 | } |
64 | accepted => { |
65 | root.active-cell = { r: -1, c: -1}; |
66 | } |
67 | |
68 | visible: is-active; |
69 | width: 100%; |
70 | height: 100%; |
71 | } |
72 | } |
73 | } |
74 | } |
75 | } |
76 | |
77 | component Cell inherits MainWindow { |
78 | // initialize the cells with demy value to be viewed in the preview |
79 | in-out property <[CellContent]> _row: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]; |
80 | cells: [ |
81 | root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, |
82 | root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, |
83 | root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, |
84 | root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, |
85 | root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, root._row, |
86 | ]; |
87 | } |
88 | |