From 1914a57b40242a5bd6d7ce5a0c37e8acae220589 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 8 Jan 2009 00:04:44 -0600 Subject: [PATCH] Render table column separator lines --- basis/colors/colors.factor | 1 + basis/ui/gadgets/tables/tables.factor | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/basis/colors/colors.factor b/basis/colors/colors.factor index 1183c2e46c..1364f173d5 100644 --- a/basis/colors/colors.factor +++ b/basis/colors/colors.factor @@ -22,6 +22,7 @@ M: color blue>> ( color -- blue ) >rgba blue>> ; : blue T{ rgba f 0.0 0.0 1.0 1.0 } ; inline : cyan T{ rgba f 0 0.941 0.941 1 } ; inline : gray T{ rgba f 0.6 0.6 0.6 1.0 } ; inline +: dark-gray T{ rgba f 0.8 0.8 0.8 1.0 } ; inline : green T{ rgba f 0.0 1.0 0.0 1.0 } ; inline : light-gray T{ rgba f 0.95 0.95 0.95 0.95 } ; inline : light-purple T{ rgba f 0.8 0.8 1.0 1.0 } ; inline diff --git a/basis/ui/gadgets/tables/tables.factor b/basis/ui/gadgets/tables/tables.factor index a1ab6ec496..bd7becbc11 100644 --- a/basis/ui/gadgets/tables/tables.factor +++ b/basis/ui/gadgets/tables/tables.factor @@ -19,7 +19,7 @@ M: object row-value drop ; TUPLE: table < gadget renderer filled-column column-alignment action column-widths total-width -font text-color selection-color mouse-color +font text-color selection-color mouse-color column-line-color selected-index selected-value mouse-index focused? ; @@ -32,6 +32,7 @@ focused? ; f >>selected-value sans-serif-font >>font selection-color >>selection-color + dark-gray >>column-line-color black >>mouse-color black >>text-color ; @@ -100,6 +101,16 @@ M: table layout* : draw-moused ( table -- ) [ ] [ mouse-index>> ] [ mouse-color>> ] tri f highlight-row ; +: column-lines ( widths -- xs ) + 0 [ + ] accumulate nip rest-slice ; inline + +: draw-columns ( table -- ) + [ column-line-color>> gl-color ] + [ + [ column-widths>> column-lines ] [ dim>> second ] bi + '[ [ 0 2array ] [ _ 2array ] bi gl-line ] each + ] bi ; + : y>row ( y table -- n ) line-height /i ; @@ -157,10 +168,12 @@ M: table layout* M: table draw-gadget* dup control-value empty? [ drop ] [ origin get [ - [ draw-selected ] - [ draw-moused ] - [ draw-rows ] - tri + { + [ draw-selected ] + [ draw-columns ] + [ draw-moused ] + [ draw-rows ] + } cleave ] with-translation ] if ;