91 lines
No EOL
3.5 KiB
Text
91 lines
No EOL
3.5 KiB
Text
import { Button, VerticalBox , HorizontalBox, TabWidget, ListView, StandardListView, StandardTableView, CheckBox} from "std-widgets.slint";
|
|
|
|
export component SelectableTableView inherits Rectangle {
|
|
in property <[string]> columns;
|
|
in property <[{checked: bool, selected_row: bool, header_row: bool, val:[string]}]> values;
|
|
|
|
private property <[length]> column_sizes: [30px, 100px, 100px, 100px];
|
|
private property <int> column_number: 4;
|
|
|
|
VerticalBox {
|
|
padding: 5px;
|
|
// Widgets
|
|
HorizontalLayout {
|
|
padding: 5px;
|
|
spacing: 5px;
|
|
vertical-stretch: 0;
|
|
for title[idx] in root.columns : HorizontalLayout {
|
|
width: root.column_sizes[idx];
|
|
Text { overflow: elide; text: title; }
|
|
Rectangle {
|
|
width: 1px;
|
|
background: gray;
|
|
|
|
TouchArea {
|
|
width: 5px;
|
|
x: (parent.width - self.width) / 2;
|
|
property <length> cached;
|
|
pointer-event(event) => {
|
|
if (event.button == PointerEventButton.left && event.kind == PointerEventKind.down) {
|
|
self.cached = root.column_sizes[idx];
|
|
}
|
|
}
|
|
moved => {
|
|
if (self.pressed) {
|
|
root.column_sizes[idx] += (self.mouse-x - self.pressed-x);
|
|
if (root.column_sizes[idx] < 20px) {
|
|
root.column_sizes[idx] = 20px;
|
|
}
|
|
}
|
|
}
|
|
mouse-cursor: ew-resize;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
list_view:= ListView {
|
|
min-width: 100px;
|
|
for r[idx] in root.values : Rectangle {
|
|
background: r.header-row ? #888888 : (touch-area.has-hover ? (r.selected_row ? #cccccc : #dddddd) : (r.selected_row ? #cccccc: #dddddd));
|
|
// background: touch-area.has-hover ? (selected ? #333333 : #222222) : (selected ? #333333: #222222);
|
|
|
|
touch_area:= TouchArea {
|
|
clicked => {
|
|
if (!r.header_row) {
|
|
r.selected_row = !r.selected_row
|
|
}
|
|
}
|
|
}
|
|
|
|
HorizontalLayout {
|
|
padding: 5px;
|
|
spacing: 5px;
|
|
//width: root.column_sizes[idx];
|
|
|
|
CheckBox {
|
|
//min-width: 200px;
|
|
visible: !r.header-row;
|
|
checked: r.checked && !r.header-row;
|
|
width: root.column-sizes[0];
|
|
toggled => {
|
|
r.checked = self.checked;
|
|
}
|
|
// preferred-width: root.column-sizes[0];
|
|
}
|
|
|
|
HorizontalLayout {
|
|
padding: 5px;
|
|
spacing: 5px;
|
|
for f[idx] in r.val : Text {
|
|
width: root.column-sizes[idx + 1];
|
|
text: f;
|
|
vertical-alignment: center;
|
|
|
|
overflow: elide;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |