fix text string sizing in UI

cvs
Slava Pestov 2005-05-06 03:58:45 +00:00
parent a344c65cca
commit 958f20e97c
6 changed files with 24 additions and 24 deletions

View File

@ -90,11 +90,11 @@ M: editor user-input* ( ch editor -- ? )
scroll>bottom t ;
M: editor pref-size ( editor -- w h )
editor-text shape-size >r 1 + r> ;
dup editor-text label-size >r 1 + r> ;
M: editor layout* ( editor -- )
dup editor-caret over caret-size rot resize-gadget
dup editor-caret swap caret-pos rot move-gadget ;
M: editor draw-shape ( editor -- )
dup [ editor-text draw-shape ] with-trans ;
[ editor-text ] keep [ draw-string ] with-trans ;

View File

@ -59,7 +59,15 @@ C: gadget ( shape -- gadget )
[ [ resize-shape ] keep relayout ] ?resize ;
: paint-prop ( gadget key -- value )
swap gadget-paint hash ;
over [
dup pick gadget-paint hash* dup [
2nip cdr
] [
drop >r gadget-parent r> paint-prop
] ?ifte
] [
2drop f
] ifte ;
: set-paint-prop ( gadget value key -- )
rot gadget-paint set-hash ;

View File

@ -9,8 +9,11 @@ TUPLE: label text ;
C: label ( text -- label )
<empty-gadget> over set-delegate [ set-label-text ] keep ;
M: label pref-size label-text shape-size ;
: label-size ( gadget text -- w h )
>r font paint-prop r> size-string ;
M: label pref-size ( label -- w h )
dup label-text label-size ;
M: label draw-shape ( label -- )
dup delegate draw-shape
dup shape-pos [ label-text draw-shape ] with-trans ;
[ label-text ] keep [ draw-string ] with-trans ;

View File

@ -53,7 +53,7 @@ SYMBOL: clip
: with-clip ( shape quot -- )
#! All drawing done inside the quotation is clipped to the
#! shape's bounds. The quotation is called with a boolean
#! that is set to false if
#! that is set to false if the gadget is entirely clipped.
[
>r screen-bounds clip [ intersect dup ] change set-clip
r> call
@ -65,7 +65,7 @@ SYMBOL: clip
#! paint, just call the quotation.
f over set-gadget-redraw?
dup gadget-paint [
dup dup [
dup [
[
drop
] [
@ -74,5 +74,4 @@ SYMBOL: clip
] with-trans
] ifte
] with-clip
surface get swap [ shape-x x get + ] keep [ shape-y y get + ] keep [ shape-w pick + 1 - ] keep shape-h pick + 1 - red rgb rectangleColor
] bind ;

View File

@ -63,18 +63,7 @@ global [
swap *int swap *int
] ifte ;
global [ <namespace> fonts set ] bind
M: string shape-x drop 0 ;
M: string shape-y drop 0 ;
M: string shape-w
font get swap size-string ( h -) drop ;
M: string shape-h ( text -- h )
#! This is just the height of the current font.
drop font get lookup-font TTF_FontHeight ;
M: string draw-shape ( text -- )
: draw-string ( text -- )
dup empty? [
drop
] [
@ -85,3 +74,5 @@ M: string draw-shape ( text -- )
[ >r x get y get r> draw-surface ] keep
SDL_FreeSurface
] ifte ;
global [ <namespace> fonts set ] bind

View File

@ -70,11 +70,10 @@ TUPLE: tile original ;
C: tile ( child caption -- tile )
[ f line-border swap set-delegate ] keep
[ >r tile-content r> add-gadget ] keep
[ tile-actions ] keep
dup delegate pref-size pick resize-gadget ;
[ tile-actions ] keep ;
M: tile pref-size shape-size ;
: tile ( gadget title -- )
#! Show the gadget in a new tile.
<tile> world get add-gadget ;
<tile> [ world get add-gadget ] keep prefer ;