From d31b902f96cd69b4eb6e6e9ee29839302eb3622b Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 2 Feb 2009 00:02:55 -0600 Subject: [PATCH] Add horizontal and vertical orientation constants, working on baseline alignment --- basis/ui/gadgets/buttons/buttons.factor | 15 +--- basis/ui/gadgets/editors/editors.factor | 5 +- basis/ui/gadgets/gadgets.factor | 8 +- basis/ui/gadgets/grid-lines/grid-lines.factor | 4 +- basis/ui/gadgets/grids/grids.factor | 4 +- .../ui/gadgets/incremental/incremental.factor | 2 +- basis/ui/gadgets/labelled/labelled.factor | 2 +- basis/ui/gadgets/labels/labels.factor | 23 ++++-- basis/ui/gadgets/packs/packs-docs.factor | 4 +- basis/ui/gadgets/packs/packs-tests.factor | 31 +++++++- basis/ui/gadgets/packs/packs.factor | 76 +++++++++++++------ basis/ui/gadgets/panes/panes.factor | 6 +- basis/ui/gadgets/paragraphs/paragraphs.factor | 2 +- basis/ui/gadgets/sliders/sliders.factor | 31 ++++---- basis/ui/gadgets/slots/slots.factor | 2 +- basis/ui/gadgets/tabbed/tabbed.factor | 2 +- basis/ui/gadgets/tracks/tracks-docs.factor | 2 +- basis/ui/gadgets/tracks/tracks-tests.factor | 10 +-- basis/ui/gadgets/worlds/worlds.factor | 2 +- basis/ui/gadgets/wrappers/wrappers.factor | 8 +- basis/ui/tools/browser/browser.factor | 6 +- basis/ui/tools/debugger/debugger.factor | 2 +- basis/ui/tools/inspector/inspector.factor | 2 +- basis/ui/tools/listener/listener.factor | 2 +- basis/ui/tools/profiler/profiler.factor | 10 +-- basis/ui/tools/traceback/traceback.factor | 4 +- basis/ui/tools/walker/walker.factor | 2 +- basis/ui/traverse/traverse.factor | 2 +- basis/ui/ui-docs.factor | 2 +- 29 files changed, 167 insertions(+), 104 deletions(-) diff --git a/basis/ui/gadgets/buttons/buttons.factor b/basis/ui/gadgets/buttons/buttons.factor index 86ba579e7e..43cdab5321 100644 --- a/basis/ui/gadgets/buttons/buttons.factor +++ b/basis/ui/gadgets/buttons/buttons.factor @@ -150,15 +150,10 @@ M: checkmark-paint draw-interior : toggle-model ( model -- ) [ not ] change-model ; -: checkbox-theme ( gadget -- gadget ) - f >>interior - { 5 5 } >>gap - 1/2 >>align ; inline - TUPLE: checkbox < button ; : ( model label -- checkbox ) - label-on-right checkbox-theme + label-on-right [ model>> toggle-model ] checkbox new-button swap >>model @@ -173,7 +168,7 @@ TUPLE: radio-paint < caching-pen color interior-vertices boundary-vertices ; @@ -223,12 +218,8 @@ M: radio-control model-changed :: ( parent model assoc quot: ( value model label -- gadget ) -- parent ) assoc model [ parent swap quot call add-gadget ] assoc-each ; inline -: radio-button-theme ( gadget -- gadget ) - { 5 5 } >>gap - 1/2 >>align ; inline - : ( value model label -- gadget ) - label-on-right radio-button-theme ; + label-on-right ; : ( model assoc -- gadget ) diff --git a/basis/ui/gadgets/editors/editors.factor b/basis/ui/gadgets/editors/editors.factor index 25a92a6852..867158df4f 100755 --- a/basis/ui/gadgets/editors/editors.factor +++ b/basis/ui/gadgets/editors/editors.factor @@ -242,6 +242,9 @@ M: editor draw-gadget* M: editor pref-dim* [ font>> ] [ control-value ] bi text-dim ; +M: editor baseline + font>> "" line-metrics ascent>> ; + : contents-changed ( model editor -- ) swap over caret>> [ over validate-loc ] (change-model) @@ -585,7 +588,7 @@ TUPLE: field < wrapper editor min-width max-width ; gray >>boundary ; inline : ( gadget -- border ) - 2 + { 2 2 } { 1 0 } >>fill field-theme ; diff --git a/basis/ui/gadgets/gadgets.factor b/basis/ui/gadgets/gadgets.factor index f9cad95251..34a0d5c92f 100644 --- a/basis/ui/gadgets/gadgets.factor +++ b/basis/ui/gadgets/gadgets.factor @@ -6,6 +6,10 @@ binary-search vectors dlists deques models threads concurrency.flags math.order math.geometry.rect fry ; IN: ui.gadgets +! Values for orientation slot +CONSTANT: horizontal { 1 0 } +CONSTANT: vertical { 0 1 } + TUPLE: gadget < rect pref-dim parent children orientation focus visible? root? clipped? layout-state graft-state graft-node interior boundary model ; @@ -103,14 +107,14 @@ GENERIC: gadget-text* ( gadget -- ) GENERIC: gadget-text-separator ( gadget -- str ) M: gadget gadget-text-separator - orientation>> { 0 1 } = "\n" "" ? ; + orientation>> vertical = "\n" "" ? ; : gadget-seq-text ( seq gadget -- ) gadget-text-separator swap [ dup % ] [ gadget-text* ] interleave drop ; M: gadget gadget-text* - dup children>> swap gadget-seq-text ; + [ children>> ] keep gadget-seq-text ; M: array gadget-text* [ gadget-text* ] each ; diff --git a/basis/ui/gadgets/grid-lines/grid-lines.factor b/basis/ui/gadgets/grid-lines/grid-lines.factor index a28f21c3ad..fd18479662 100755 --- a/basis/ui/gadgets/grid-lines/grid-lines.factor +++ b/basis/ui/gadgets/grid-lines/grid-lines.factor @@ -28,7 +28,7 @@ M: grid-lines draw-boundary [ grid set ] [ dim>> half-gap v- grid-dim set ] [ compute-grid ] tri - [ { 1 0 } draw-grid-lines ] - [ { 0 1 } draw-grid-lines ] + [ horizontal draw-grid-lines ] + [ vertical draw-grid-lines ] bi* ] with-scope ; diff --git a/basis/ui/gadgets/grids/grids.factor b/basis/ui/gadgets/grids/grids.factor index 83542998e2..8a448fddf1 100644 --- a/basis/ui/gadgets/grids/grids.factor +++ b/basis/ui/gadgets/grids/grids.factor @@ -48,8 +48,8 @@ grid dupd add-gaps dim-sum v+ ; M: grid pref-dim* - dup gap>> swap compute-grid [ over ] dip - [ gap-sum ] 2bi@ (pair-up) ; + [ gap>> ] [ compute-grid ] bi + [ over ] dip [ gap-sum ] 2bi@ (pair-up) ; : do-grid ( dims grid quot -- ) [ grid>> ] dip '[ _ 2each ] 2each ; inline diff --git a/basis/ui/gadgets/incremental/incremental.factor b/basis/ui/gadgets/incremental/incremental.factor index 81c980afbc..29d8f8ab03 100644 --- a/basis/ui/gadgets/incremental/incremental.factor +++ b/basis/ui/gadgets/incremental/incremental.factor @@ -9,7 +9,7 @@ TUPLE: incremental < pack cursor ; : ( -- incremental ) incremental new-gadget - { 0 1 } >>orientation + vertical >>orientation { 0 0 } >>cursor ; M: incremental pref-dim* diff --git a/basis/ui/gadgets/labelled/labelled.factor b/basis/ui/gadgets/labelled/labelled.factor index 636e25cea5..6bcea200f3 100644 --- a/basis/ui/gadgets/labelled/labelled.factor +++ b/basis/ui/gadgets/labelled/labelled.factor @@ -11,7 +11,7 @@ IN: ui.gadgets.labelled TUPLE: labelled-gadget < track content ; : ( gadget title -- newgadget ) - { 0 1 } labelled-gadget new-track + vertical labelled-gadget new-track swap