Skip to content

Commit adbae56

Browse files
committed
add hover focus
1 parent 0d7ecb9 commit adbae56

5 files changed

Lines changed: 483 additions & 198 deletions

File tree

packages/gui/draw.ss

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
draw-hover
1919
draw-item-bg
2020
draw-border
21+
draw-get-text-width
22+
draw-widget-text
2123
)
2224

2325
(import (scheme)
2426
(utils libutil)
2527
(gui graphic )
28+
(gui widget)
2629
(gui video)
2730
(gui stb))
2831

32+
(define (draw-get-text-width text)
33+
(graphic-measure-text (graphic-get-font '()) text))
34+
2935
(define (draw-button x y w h text)
3036
(graphic-draw-solid-quad x y
3137
(+ x w) (+ y h)
@@ -114,20 +120,56 @@
114120
(graphic-draw-line x1 y1 x2 y2
115121
color))
116122

123+
124+
(define (draw-widget-text widget)
125+
(let* ((color (widget-get-attrs widget 'color))
126+
(parent (widget-get-attr widget %parent))
127+
(tw (widget-get-attrs widget 'text-width))
128+
(ta (widget-get-attrs widget 'text-align))
129+
(padding-left (widget-get-attrs widget 'padding-left 0.0))
130+
(padding-right (widget-get-attrs widget 'padding-right 0.0))
131+
(gx (+ (vector-ref parent %gx) (vector-ref widget %x)))
132+
(gy (+ (vector-ref parent %gy) (vector-ref widget %y)))
133+
(w (widget-get-attr widget %w))
134+
(h (widget-get-attr widget %h))
135+
(text (widget-get-attr widget %text ))
136+
)
137+
138+
(if (null? color)
139+
(case ta
140+
['left (graphic-draw-text (+ gx padding-left)
141+
(+ gy (/ h 2.0) -12 )
142+
text)]
143+
['right (graphic-draw-text (+ gx padding-left)
144+
(+ gy (/ h 2.0) -12 )
145+
text)]
146+
['center (graphic-draw-text (+ gx padding-left)
147+
(+ gy (/ h 2.0) -12 )
148+
text)]
149+
[else (graphic-draw-text (+ gx (- w tw ) padding-left)
150+
(+ gy (/ h 2.0) -12 )
151+
text)]
152+
)
153+
(begin
154+
(draw-text gx gy w h text color)))
155+
))
156+
157+
117158
(define draw-text
118159
(case-lambda
119160
[(x y text)
120-
(graphic-draw-text x y text )]
161+
(graphic-draw-text x y text )]
121162
[(x y text color)
122-
(graphic-draw-text x y text color)
123-
]
163+
(graphic-draw-text x y text color)]
124164
[(x y w h text)
125165
(graphic-draw-text (+ x (/ w 2.0 ) -8)
126166
(+ y (/ h 2.0) -12 )
127-
text)
128-
]
129-
)
130-
)
167+
text)]
168+
[(x y w h text tw )
169+
(graphic-draw-text (+ x (/ tw 2) )
170+
(+ y (/ h 2.0) -12 )
171+
text)]
172+
))
131173
(define (draw-hover x y w h)
132174
(draw-rect x y w h))
133175

0 commit comments

Comments
 (0)