Check-in [5bd0eda37c]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:A bit more work on widgets
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5bd0eda37ca37b9987491f1ac1a2a75587b6f5a6
User & Date: bernd 2014-03-23 16:25:20
Context
2014-03-23
22:58
A bit more work on widgets check-in: 54488cc3f0 user: bernd tags: trunk
16:25
A bit more work on widgets check-in: 5bd0eda37c user: bernd tags: trunk
2014-03-22
21:01
More work on boxes&glues check-in: 0d5c34deb0 user: bernd tags: trunk
Changes

Changes to gles2/widgets-test.fs.

    11     11   frame new value f5
    12     12   frame new value f6
    13     13   text new value f7
    14     14   text new value f8
    15     15   
    16     16   
    17     17   : !f1 ( -- ) f1 >o
    18         -    0 x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
           18  +    0 0  dpy-w @ 4 /  0  dpy-h @ 2/ resize
    19     19       32 border ! $FFFFFFFF frame-color !
    20     20       button2 o> ;
    21     21   
    22     22   : !f2 ( -- ) f2 >o
    23         -    dpy-w @ 2/ x ! 0 y ! dpy-w @ 2/ w ! dpy-h @ 19 20 */ d !
           23  +    dpy-w @ 2/  0  dpy-w @ 2/  0  dpy-h @ 19 20 */ resize
    24     24       32 border ! $FF7FFFFF frame-color !
    25     25       button3 o> ;
    26     26   
    27     27   : !f3 ( -- ) f3 >o
    28         -    0 x ! dpy-h @ 2/ y ! dpy-w @ 2/ w ! dpy-h @ 2/ 2/ d !
           28  +    0  dpy-h @ 2/  dpy-w @ 2/  0  dpy-h @ 2/ 2/ resize
    29     29       16 border ! $FFFF7FFF frame-color !
    30     30       button1 o> ;
    31     31   
    32     32   : !f4 ( -- ) f4 >o
    33         -    0 x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
           33  +    0  dpy-h @ 3 4 */  dpy-w @ 4 /  0  dpy-h @ 5 / resize
    34     34       32 border ! $FF7F7FFF frame-color !
    35     35       button1 o> ;
    36     36   
    37     37   : !f5 ( -- ) f5 >o
    38         -    dpy-w @ 4 / x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
           38  +    dpy-w @ 4 /  dpy-h @ 3 4 */  dpy-w @ 4 /  0  dpy-h @ 5 / resize
    39     39       8 border ! $7FFF7FFF frame-color !
    40     40       button1 o> ;
    41     41   
    42     42   : !f6 ( -- ) f6 >o
    43         -    dpy-w @ 4 / x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
           43  +    dpy-w @ 4 /  0  dpy-w @ 4 /  0  dpy-h @ 2/ resize
    44     44       16 border ! $7FFFFFFF frame-color !
    45     45       button2 o> ;
    46     46   
    47     47   also freetype-gl
    48     48   48e FConstant fontsize#
    49     49   atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
    50     50   [ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 

Changes to gles2/widgets.fs.

    44     44       method dglue ( -- typ sub add )
    45     45       method vglue ( -- typ sub add )
    46     46       method hglue@ ( -- typ sub add ) \ cached variant
    47     47       method dglue@ ( -- typ sub add ) \ cached variant
    48     48       method vglue@ ( -- typ sub add ) \ cached variant
    49     49       method xywh ( -- x0 y0 w h )
    50     50       method xywhd ( -- x y w h d )
           51  +    method resize ( x y w h d -- )
    51     52       method !size \ set your own size
    52     53   end-class widget
    53     54   
    54     55   :noname x @ y @ h @ - w @ h @ d @ + ; widget to xywh
    55     56   :noname x @ y @ w @ h @ d @ ; widget to xywhd
    56     57   ' noop widget to !size
    57     58   :noname w @ 0 0 ; widget to hglue
    58     59   :noname h @ 0 0 ; widget to vglue
    59     60   :noname d @ 0 0 ; widget to dglue
           61  +:noname d ! h ! w ! y ! x ! ; widget to resize
    60     62   ' hglue widget to hglue@
    61     63   ' vglue widget to vglue@
    62     64   ' dglue widget to dglue@
    63     65   
    64     66   tex: style-tex \ 8 x 8 subimages, each sized 128x128
    65     67   style-tex 1024 dup rgba-newtex
    66     68   
................................................................................
   217    219   :noname ( -- ) ['] draw do-childs ; box to draw
   218    220   
   219    221   : +child ( o -- ) child-w @ over >o next-w ! o> child-w ! ;
   220    222   : +childs ( o1 .. on n -- ) 0 +DO  +child  LOOP ;
   221    223   
   222    224   \ glue arithmetics
   223    225   
          226  +box class end-class hbox \ horizontal alignment
          227  +box class
          228  +    field: baseline \ minimun skip per line
          229  +end-class vbox \ vertical alignment
          230  +box class end-class zbox \ overlay alignment
          231  +
   224    232   : 0glue ( -- t s a ) 0 0 0 ;
   225    233   : 1glue ( -- t s a ) 0 0 [ -1 1 rshift ]L ;
   226    234   
   227    235   : g3>2 ( t s a -- min a ) over + >r - r> ;
   228    236   
   229    237   : glue+ { t1 s1 a1 t2 s2 a2 -- t3 s3 a3 }
   230    238       t1 t2 + s1 s2 + a1 a2 + ;
................................................................................
   241    249   : vglue+ 0glue 0glue [: vglue@ glue+ baseglue glue* glue+ dglue@ ;] do-childs
   242    250       glue-drop ;
   243    251   
   244    252   : hglue* 1glue [: hglue@ glue* ;] do-childs ;
   245    253   : dglue* 1glue [: dglue@ glue* ;] do-childs ;
   246    254   : vglue* 1glue [: vglue@ glue* ;] do-childs ;
   247    255   
   248         -box class end-class hbox \ horizontal alignment
   249         -box class
   250         -    field: baseline \ minimun skip per line
   251         -end-class vbox \ vertical alignment
   252         -box class end-class zbox \ overlay alignment
   253         -
   254    256   ' hglue+ hbox is hglue
   255    257   ' dglue* hbox is dglue
   256    258   ' vglue* hbox is vglue
   257    259   
   258    260   ' hglue* vbox is hglue
   259    261   ' dglue+ vbox is dglue
   260    262   ' vglue+ vbox is vglue

Changes to widgets-test.fs.

    11     11   frame new value f5
    12     12   frame new value f6
    13     13   text new value f7
    14     14   text new value f8
    15     15   
    16     16   
    17     17   : !f1 ( -- ) f1 >o
    18         -    0 x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
           18  +    0 0  dpy-w @ 4 /  0  dpy-h @ 2/ resize
    19     19       32 border ! $FFFFFFFF frame-color !
    20     20       button2 o> ;
    21     21   
    22     22   : !f2 ( -- ) f2 >o
    23         -    dpy-w @ 2/ x ! 0 y ! dpy-w @ 2/ w ! dpy-h @ 19 20 */ d !
           23  +    dpy-w @ 2/  0  dpy-w @ 2/  0  dpy-h @ 19 20 */ resize
    24     24       32 border ! $FF7FFFFF frame-color !
    25     25       button3 o> ;
    26     26   
    27     27   : !f3 ( -- ) f3 >o
    28         -    0 x ! dpy-h @ 2/ y ! dpy-w @ 2/ w ! dpy-h @ 2/ 2/ d !
           28  +    0  dpy-h @ 2/  dpy-w @ 2/  0  dpy-h @ 2/ 2/ resize
    29     29       16 border ! $FFFF7FFF frame-color !
    30     30       button1 o> ;
    31     31   
    32     32   : !f4 ( -- ) f4 >o
    33         -    0 x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
           33  +    0  dpy-h @ 3 4 */  dpy-w @ 4 /  0  dpy-h @ 5 / resize
    34     34       32 border ! $FF7F7FFF frame-color !
    35     35       button1 o> ;
    36     36   
    37     37   : !f5 ( -- ) f5 >o
    38         -    dpy-w @ 4 / x ! dpy-h @ 3 4 */ y ! dpy-w @ 4 / w ! dpy-h @ 5 / d !
           38  +    dpy-w @ 4 /  dpy-h @ 3 4 */  dpy-w @ 4 /  0  dpy-h @ 5 / resize
    39     39       8 border ! $7FFF7FFF frame-color !
    40     40       button1 o> ;
    41     41   
    42     42   : !f6 ( -- ) f6 >o
    43         -    dpy-w @ 4 / x ! 0 y ! dpy-w @ 4 / w ! dpy-h @ 2/ d !
           43  +    dpy-w @ 4 /  0  dpy-w @ 4 /  0  dpy-h @ 2/ resize
    44     44       16 border ! $7FFFFFFF frame-color !
    45     45       button2 o> ;
    46     46   
    47     47   also freetype-gl
    48     48   48e FConstant fontsize#
    49     49   atlas [IFDEF] android  "/system/fonts/DroidSans.ttf\0" drop
    50     50   [ELSE] "/usr/share/fonts/truetype/LiberationSans-Regular.ttf\0" drop 

Changes to widgets.fs.

    44     44       method dglue ( -- typ sub add )
    45     45       method vglue ( -- typ sub add )
    46     46       method hglue@ ( -- typ sub add ) \ cached variant
    47     47       method dglue@ ( -- typ sub add ) \ cached variant
    48     48       method vglue@ ( -- typ sub add ) \ cached variant
    49     49       method xywh ( -- x0 y0 w h )
    50     50       method xywhd ( -- x y w h d )
           51  +    method resize ( x y w h d -- )
    51     52       method !size \ set your own size
    52     53   end-class widget
    53     54   
    54     55   :noname x @ y @ h @ - w @ h @ d @ + ; widget to xywh
    55     56   :noname x @ y @ w @ h @ d @ ; widget to xywhd
    56     57   ' noop widget to !size
    57     58   :noname w @ 0 0 ; widget to hglue
    58     59   :noname h @ 0 0 ; widget to vglue
    59     60   :noname d @ 0 0 ; widget to dglue
           61  +:noname d ! h ! w ! y ! x ! ; widget to resize
    60     62   ' hglue widget to hglue@
    61     63   ' vglue widget to vglue@
    62     64   ' dglue widget to dglue@
    63     65   
    64     66   tex: style-tex \ 8 x 8 subimages, each sized 128x128
    65     67   style-tex 1024 dup rgba-newtex
    66     68   
................................................................................
   217    219   :noname ( -- ) ['] draw do-childs ; box to draw
   218    220   
   219    221   : +child ( o -- ) child-w @ over >o next-w ! o> child-w ! ;
   220    222   : +childs ( o1 .. on n -- ) 0 +DO  +child  LOOP ;
   221    223   
   222    224   \ glue arithmetics
   223    225   
          226  +box class end-class hbox \ horizontal alignment
          227  +box class
          228  +    field: baseline \ minimun skip per line
          229  +end-class vbox \ vertical alignment
          230  +box class end-class zbox \ overlay alignment
          231  +
   224    232   : 0glue ( -- t s a ) 0 0 0 ;
   225    233   : 1glue ( -- t s a ) 0 0 [ -1 1 rshift ]L ;
   226    234   
   227    235   : g3>2 ( t s a -- min a ) over + >r - r> ;
   228    236   
   229    237   : glue+ { t1 s1 a1 t2 s2 a2 -- t3 s3 a3 }
   230    238       t1 t2 + s1 s2 + a1 a2 + ;
................................................................................
   241    249   : vglue+ 0glue 0glue [: vglue@ glue+ baseglue glue* glue+ dglue@ ;] do-childs
   242    250       glue-drop ;
   243    251   
   244    252   : hglue* 1glue [: hglue@ glue* ;] do-childs ;
   245    253   : dglue* 1glue [: dglue@ glue* ;] do-childs ;
   246    254   : vglue* 1glue [: vglue@ glue* ;] do-childs ;
   247    255   
   248         -box class end-class hbox \ horizontal alignment
   249         -box class
   250         -    field: baseline \ minimun skip per line
   251         -end-class vbox \ vertical alignment
   252         -box class end-class zbox \ overlay alignment
   253         -
   254    256   ' hglue+ hbox is hglue
   255    257   ' dglue* hbox is dglue
   256    258   ' vglue* hbox is vglue
   257    259   
   258    260   ' hglue* vbox is hglue
   259    261   ' dglue+ vbox is dglue
   260    262   ' vglue+ vbox is vglue