import { Button, VerticalBox , HorizontalBox, TabWidget, ListView, StandardListView, StandardTableView, CheckBox} from "std-widgets.slint"; export component SelectableTableView inherits Rectangle { in property <[string]> columns; in property last_column; in-out property <[{checked: bool, header_row: bool, selected_row: bool, val:[string]}]> values; in-out property <[length]> column_sizes: [200px, 100px, 100px, 100px]; private property <[length]> real_sizes: [0px,0px,0px,0px,0px,0px,0px,0px,0px,0px,0px,0px,0px,0px,0px,0px,0px,0px]; private property column_number: 4; in-out property selected_item: -1; 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 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; } } } Text { overflow: elide; text: last-column; } } list_view := ListView { min-width: 100px; for r[idx] in root.values : Rectangle { height: 30px; 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; if (root.selected-item == -1) { root.selected-item = idx; } else { if (r.selected_row == true) { root.values[root.selected-item].selected_row = false; root.selected-item = idx; } else { root.selected-item = -1; } } } } } HorizontalLayout { padding: 5px; spacing: 5px; 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 { spacing: 5px; for f[idx] in r.val : Text { width: root.column-sizes[idx + 1]; text: f; font-size: 12px; vertical-alignment: center; overflow: elide; } } } } } } }