Add selection-required? slot to table gadget, which if set ensures that some item is always selected if the model is not empty
parent
a60bf8065a
commit
9a5b7d44fd
|
@ -20,7 +20,7 @@ TUPLE: table < gadget
|
||||||
renderer filled-column column-alignment action
|
renderer filled-column column-alignment action
|
||||||
column-widths total-width
|
column-widths total-width
|
||||||
font text-color selection-color focus-border-color
|
font text-color selection-color focus-border-color
|
||||||
mouse-color column-line-color
|
mouse-color column-line-color selection-required?
|
||||||
selected-index selected-value
|
selected-index selected-value
|
||||||
mouse-index
|
mouse-index
|
||||||
focused? ;
|
focused? ;
|
||||||
|
@ -206,11 +206,12 @@ PRIVATE>
|
||||||
: update-selected-value ( table -- )
|
: update-selected-value ( table -- )
|
||||||
[ selected-row drop ] [ selected-value>> ] bi set-model ;
|
[ selected-row drop ] [ selected-value>> ] bi set-model ;
|
||||||
|
|
||||||
|
: initial-selected-index ( model table -- n/f )
|
||||||
|
[ value>> length 1 >= ] [ selection-required?>> ] bi* and 0 f ? ;
|
||||||
|
|
||||||
M: table model-changed
|
M: table model-changed
|
||||||
nip
|
tuck initial-selected-index >>selected-index
|
||||||
[ f >>selected-index update-selected-value ]
|
[ update-selected-value ] [ relayout ] bi ;
|
||||||
[ relayout ]
|
|
||||||
bi ;
|
|
||||||
|
|
||||||
: thin-row-rect ( table row -- rect )
|
: thin-row-rect ( table row -- rect )
|
||||||
row-rect [ { 0 1 } v* ] change-dim ;
|
row-rect [ { 0 1 } v* ] change-dim ;
|
||||||
|
|
Loading…
Reference in New Issue