From 3ac409e43246a19e409c1822e735edcb9474851e Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 9 Feb 2009 00:23:47 -0600 Subject: [PATCH] ui.gadgets.tables: clean up selected row rendering, add single-click mode --- basis/ui/gadgets/tables/tables.factor | 45 ++++++++++++++++----------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/basis/ui/gadgets/tables/tables.factor b/basis/ui/gadgets/tables/tables.factor index ef509e2e13..e89321c542 100644 --- a/basis/ui/gadgets/tables/tables.factor +++ b/basis/ui/gadgets/tables/tables.factor @@ -20,7 +20,7 @@ M: object row-value drop ; M: object row-color 2drop f ; TUPLE: table < gadget -renderer filled-column column-alignment action hook +renderer filled-column column-alignment action single-click? hook column-widths total-width font selection-color focus-border-color mouse-color column-line-color selection-required? @@ -84,21 +84,26 @@ M: table layout* [ [ row-rect rect-bounds ] dip gl-color ] dip '[ _ @ ] with-translation ; inline -: draw-selected-row ( table row -- ) - over selection-color>> [ gl-fill-rect ] highlight-row ; +: draw-selected-row ( table -- ) + { + { [ dup selected-index>> not ] [ drop ] } + [ + [ ] [ selected-index>> ] [ selection-color>> ] tri + [ gl-fill-rect ] highlight-row + ] + } cond ; -: draw-focused-row ( table row -- ) - over focused?>> [ - over focus-border-color>> [ gl-rect ] highlight-row - ] [ 2drop ] if ; +: draw-focused-row ( table -- ) + { + { [ dup focused?>> not ] [ drop ] } + { [ dup selected-index>> not ] [ drop ] } + [ + [ ] [ selected-index>> ] [ focus-border-color>> ] tri + [ gl-rect ] highlight-row + ] + } cond ; -: draw-selected ( table -- ) - dup selected-index>> dup - [ [ draw-selected-row ] [ draw-focused-row ] 2bi ] - [ 2drop ] - if ; - -: draw-moused ( table -- ) +: draw-moused-row ( table -- ) dup mouse-index>> dup [ over mouse-color>> [ gl-rect ] highlight-row ] [ 2drop ] if ; @@ -149,10 +154,11 @@ M: table draw-gadget* dup control-value empty? [ drop ] [ origin get [ { - [ draw-selected ] + [ draw-selected-row ] [ draw-columns ] [ draw-lines ] - [ draw-moused ] + [ draw-focused-row ] + [ draw-moused-row ] } cleave ] with-translation ] if ; @@ -218,12 +224,15 @@ M: table model-changed PRIVATE> : row-action ( table -- ) - dup selected-row [ swap action>> call ] [ 2drop ] if ; + dup selected-row + [ swap [ action>> call ] [ hook>> call ] bi ] + [ 2drop ] + if ; > hand-click# get 2 = or [ row-action ] [ update-selected-value ] if ; : select-row ( table n -- )