ui.gadgets.editors: rename min-width and max-width slots of field to min-cols and max-cols, re-use line-support code, more accurate dimension calculation that takes field border size into account

db4
Slava Pestov 2009-02-16 04:25:58 -06:00
parent d2be75b083
commit 6b672a11fa
4 changed files with 26 additions and 16 deletions
basis/ui

View File

@ -1,6 +1,6 @@
IN: ui.gadgets.borders.tests
USING: tools.test accessors namespaces kernel
ui.gadgets ui.gadgets.borders math.rectangles ;
USING: tools.test accessors namespaces kernel ui.gadgets
ui.gadgets.borders ui.gadgets.borders.private math.rectangles ;
[ { 110 210 } ] [ <gadget> { 100 200 } >>dim { 5 5 } <border> pref-dim ] unit-test

View File

@ -1,6 +1,6 @@
! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays ui.gadgets kernel math
USING: accessors arrays ui.gadgets kernel math fry
namespaces vectors sequences math.vectors math.rectangles ;
IN: ui.gadgets.borders
@ -11,7 +11,7 @@ TUPLE: border < gadget
{ min-dim initial: { 0 0 } } ;
: new-border ( child class -- border )
new-gadget swap add-gadget ; inline
new swap add-gadget ; inline
: <border> ( child gap -- border )
swap border new-border
@ -20,14 +20,18 @@ TUPLE: border < gadget
: <filled-border> ( child gap -- border )
<border> { 1 1 } >>fill ;
: border-pref-dim ( border child-dim -- pref-dim )
'[ size>> 2 v*n _ v+ ] [ min-dim>> ] bi vmax ;
M: border pref-dim*
[ [ size>> 2 v*n ] [ gadget-child pref-dim ] bi v+ ]
[ min-dim>> ] bi vmax ;
dup gadget-child pref-dim border-pref-dim ;
M: border baseline
[ size>> second ] [ gadget-child baseline ] bi
dup [ + ] [ nip ] if ;
<PRIVATE
: border-major-dim ( border -- dim )
[ dim>> ] [ size>> 2 v*n ] bi v- ;
@ -47,6 +51,8 @@ M: border baseline
: border-child-rect ( border -- rect )
dup border-dim [ border-loc ] keep <rect> ;
PRIVATE>
M: border layout*
[ border-child-rect ] [ gadget-child ] bi set-rect-bounds ;

View File

@ -555,9 +555,11 @@ TUPLE: source-editor < multiline-editor ;
'[ _ _ elt-string ] <filter> ;
! Fields wrap an editor
TUPLE: field < wrapper editor min-width max-width ;
TUPLE: field < border editor min-cols max-cols ;
: field-theme ( gadget -- gadget )
{ 2 2 } >>size
{ 1 0 } >>fill
COLOR: gray <solid> >>boundary ; inline
: <field-border> ( gadget -- border )
@ -566,16 +568,18 @@ TUPLE: field < wrapper editor min-width max-width ;
field-theme ;
: new-field ( class -- gadget )
[ <editor> dup <field-border> ] dip new-wrapper swap >>editor ; inline
[ <editor> ] dip new-border
dup gadget-child >>editor
field-theme ; inline
: column-width ( editor n -- width )
[ editor>> font>> ] [ CHAR: \s <string> ] bi* text-width ;
! For line-gadget-width
M: field font>> editor>> font>> ;
M: field pref-dim*
[ call-next-method ]
[ dup min-width>> dup [ column-width 0 2array vmax ] [ 2drop ] if ]
[ dup max-width>> dup [ column-width 1/0. 2array vmin ] [ 2drop ] if ]
tri ;
dup
[ editor>> pref-dim ] keep
[ line-gadget-width ] [ drop second ] 2bi 2array
border-pref-dim ;
TUPLE: model-field < field field-model ;

View File

@ -25,8 +25,8 @@ TUPLE: browser-gadget < tool pane scroller search-field ;
: <search-field> ( browser -- field )
'[ _ search-browser ] <action-field>
10 >>min-width
10 >>max-width ;
10 >>min-cols
10 >>max-cols ;
: <browser-toolbar> ( browser -- toolbar )
horizontal <track>