Skip to content

Commit 3c53ebb

Browse files
committed
fixed flow layout
1 parent 744d53c commit 3c53ebb

4 files changed

Lines changed: 117 additions & 48 deletions

File tree

lib/libgui/gui.c

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -107,32 +107,37 @@ typedef struct {
107107

108108

109109
typedef struct _edit_t {
110-
char *prompt;
111-
char *input;
112-
size_t max_input;
113-
size_t cursor;
114-
size_t cursor_total;
115-
vec4 bound;
116-
vec2 pen;
117-
int shader;
118-
mat4 model;
119-
mat4 view;
120-
mat4 projection;
121-
int editable;
122-
123-
struct sth_stash *stash;
124-
unsigned char *data;
125-
int font;
126-
float font_size;
127-
128-
float window_width;
129-
float window_height;
130-
131-
void *colors;
110+
char *prompt;
111+
char *input;
112+
size_t max_input;
113+
size_t cursor;
114+
size_t cursor_total;
115+
vec4 bound;
116+
vec2 pen;
117+
int shader;
118+
mat4 model;
119+
mat4 view;
120+
mat4 projection;
121+
int editable;
122+
123+
struct sth_stash *stash;
124+
unsigned char *data;
125+
int font;
126+
float font_size;
127+
int color;
128+
129+
float window_width;
130+
float window_height;
131+
132+
void *colors;
132133

133134
} edit_t;
134135

135136

137+
void gl_edit_set_color(edit_t * self,int color){
138+
self->color=color;
139+
}
140+
136141
void gl_edit_set_markup(edit_t *self, void *m, int index) {
137142
//printf("gl_edit_set_marku\n");
138143
//m->font = texture_font_new_from_file( self->atlas, m->size,m->family);
@@ -198,6 +203,7 @@ edit_t *gl_new_edit(int shader, float w, float h, float width, float height) {
198203
self->window_width = width;
199204
self->window_height = height;
200205
self->colors=NULL;
206+
self->color=0xffffff;
201207

202208
char *font_name = "Roboto-Regular.ttf";
203209

@@ -576,7 +582,7 @@ void gl_render_string_colors(
576582

577583
}
578584

579-
void gl_render_params(edit_t *self) {
585+
void gl_render_params(edit_t *self,void* pcolor) {
580586

581587
//printf("shader->%d\n",self->shader);
582588

@@ -596,11 +602,30 @@ void gl_render_params(edit_t *self) {
596602

597603
if(self->colors==NULL){
598604
float dx = 0, dy = 0;
605+
float r,g,b,a;
606+
if(pcolor==NULL){
607+
b=(self->color&0xff)/255.0;
608+
g=(self->color>>8&0xff)/255.0;
609+
r=(self->color>>16&0xff)/255.0;
610+
a=(self->color>>24&0xff)/255.0;
611+
if(a==0){
612+
a=1.0;
613+
}
614+
}else{
615+
int color=*(int*)pcolor;
616+
b=(color&0xff)/255.0;
617+
g=(color>>8&0xff)/255.0;
618+
r=(color>>16&0xff)/255.0;
619+
a=(color>>24&0xff)/255.0;
620+
if(a==0){
621+
a=1.0;
622+
}
623+
}
599624
sth_begin_draw(self->stash);
600625
sth_draw_text(self->stash, self->font, self->font_size,
601626
self->pen.x, self->pen.y,
602627
self->bound.width, self->bound.height,
603-
self->input, 1.0, 1.0, 1.0, 1.0, &dx, &dy);
628+
self->input, r, g, b, a, &dx, &dy);
604629
//printf("%f %f %f %f\n",self->pen.x,self->pen.y,self->bound.width,self->bound.height);
605630
sth_end_draw(self->stash);
606631
}else{
@@ -621,7 +646,7 @@ void gl_render_params(edit_t *self) {
621646
}
622647

623648

624-
void gl_render_edit_once(edit_t *self, float x, float y, char *text, void *markup) {
649+
void gl_render_edit_once(edit_t *self, float x, float y, char *text,int color) {
625650

626651
self->cursor = 0;
627652
if (self->input != NULL) {
@@ -635,7 +660,7 @@ void gl_render_edit_once(edit_t *self, float x, float y, char *text, void *marku
635660
self->pen.y = y * 2;
636661

637662

638-
gl_render_params(self);
663+
gl_render_params(self,&color);
639664

640665

641666
if (self->editable == 1) {
@@ -653,7 +678,7 @@ void gl_render_edit(edit_t *self, float x, float y) {
653678
self->pen.x = x * 2;
654679
self->pen.y = y * 2;
655680

656-
gl_render_params(self);
681+
gl_render_params(self,NULL);
657682

658683

659684
if (self->editable == 1) {

packages/gui/duck.ss

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,31 @@
5454
(graphic-draw-text (+ x 30) (+ y 0) title)
5555
)
5656

57-
(define (draw-panel x y w h text)
58-
(graphic-draw-solid-quad x y
57+
(define draw-panel
58+
(case-lambda
59+
[(x y w h text)
60+
(graphic-draw-solid-quad x y
5961
(+ x w) (+ y h)
6062
81.0 81.0 90.0 1.0)
61-
(if (not (null? text))
62-
(graphic-draw-text (+ x 30) (+ y 0) text)))
63+
(if (not (null? text))
64+
(graphic-draw-text (+ x 30) (+ y 0) text))]
65+
[(x y w h text color)
66+
67+
;;(printf "color ~x\n" (bitwise-bit-field color 24 32))
68+
(graphic-draw-solid-quad x y
69+
(+ x w) (+ y h)
70+
(fixnum->flonum (bitwise-bit-field color 16 24))
71+
(fixnum->flonum (bitwise-bit-field color 8 16))
72+
(fixnum->flonum (bitwise-bit-field color 0 8))
73+
(/ (fixnum->flonum (if (= 0 (bitwise-bit-field color 24 32))
74+
255
75+
(bitwise-bit-field color 24 32)
76+
)) 255.0)
77+
)
78+
(if (not (null? text))
79+
(graphic-draw-text (+ x 30) (+ y 0) text))]
80+
))
81+
6382

6483
(define (draw-button x y w h text)
6584
(graphic-draw-solid-quad x y
@@ -76,8 +95,13 @@
7695
(+ x w) (+ y h)
7796
0.0 0.0 1.0 1.0 src))
7897

79-
(define (draw-text x y text)
80-
(graphic-draw-text x y text )
98+
(define draw-text
99+
(case-lambda
100+
[(x y text)
101+
(graphic-draw-text x y text )]
102+
[(x y text color)
103+
(graphic-draw-text x y text color)
104+
])
81105
)
82106

83107
(define (draw-rect x y w h)
@@ -864,20 +888,30 @@
864888

865889
(if (null? parent)
866890
(let ((gx (+ (vector-ref widget %x)))
867-
(gy (+ (vector-ref widget %y))))
891+
(gy (+ (vector-ref widget %y)))
892+
(background (widget-get-attrs widget 'background ))
893+
)
868894
(vector-set! widget %gx gx)
869895
(vector-set! widget %gy gy)
870896
(graphic-sissor-begin gx gy w h)
871897

872-
(draw-panel gx gy w h '())
898+
(if (equal? '() background)
899+
(draw-panel gx gy w h '())
900+
(draw-panel gx gy w h '() background))
901+
873902
)
874903
(let ((gx (+ (vector-ref parent %gx) (vector-ref widget %x)))
875-
(gy (+ (vector-ref parent %gy) (vector-ref widget %y))))
904+
(gy (+ (vector-ref parent %gy) (vector-ref widget %y)))
905+
(background (widget-get-attrs widget 'background ))
906+
)
876907
(vector-set! widget %gx gx)
877908
(vector-set! widget %gy gy)
878909
(graphic-sissor-begin gx gy w h)
879910

880-
(draw-panel gx gy w h '())
911+
(if (equal? '() background)
912+
(draw-panel gx gy w h '())
913+
(draw-panel gx gy w h '() background))
914+
881915
;; (draw-button gx
882916
;; gy
883917
;; w h text)

packages/gui/graphic.ss

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
graphic-draw-string-prepare
2727
graphic-draw-string-end
2828
graphic-draw-string-colors
29-
29+
graphic-edit-set-color
3030

3131
gl-markup-set-foreground
3232
gl-markup-set-background
@@ -60,15 +60,16 @@
6060

6161
(def-function gl-edit-set-editable "gl_edit_set_editable" (void* int) void)
6262

63-
63+
(def-function gl-edit-set-color "gl_edit_set_color" (void* int) void)
64+
6465
(def-function gl-edit-set-markup "gl_edit_set_markup" (void* void* int) void)
6566
(def-function gl-new-edit "gl_new_edit" (int float float float float) void*)
6667
(def-function gl-edit-add-text "gl_add_edit_text" (void* string ) void)
6768
(def-function gl-edit-set-text "gl_set_edit_text" (void* string ) void)
6869

6970

7071
(def-function gl-render-edit "gl_render_edit" ( void* float float) void)
71-
(def-function gl-render-edit-once "gl_render_edit_once" ( void* float float string void*) void)
72+
(def-function gl-render-edit-once "gl_render_edit_once" ( void* float float string int) void)
7273

7374

7475
(def-function gl-edit-key-event "gl_edit_key_event" ( void* int int int int) void)
@@ -320,12 +321,19 @@
320321
(define (graphic-edit-set-text edit text)
321322
(gl-edit-set-text edit text))
322323

324+
(define (graphic-edit-set-color edit color)
325+
(gl-edit-set-color edit color))
326+
323327
(define (graphic-new-markup name size)
324328
(gl-new-markup name size))
325329

326-
(define (graphic-draw-text x y text)
327-
(gl-render-edit-once gtext x (- my-height y) text 0)
328-
)
330+
(define graphic-draw-text
331+
(case-lambda
332+
[(x y text)
333+
(gl-render-edit-once gtext x (- my-height y) text #xffffff)]
334+
[(x y text color)
335+
(gl-render-edit-once gtext x (- my-height y) text color)]
336+
))
329337

330338
(define (graphic-get-font name)
331339
(let ((font (hashtable-ref all-font-cache name '())))

packages/gui/layout.ss

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,25 @@
252252
(begin
253253
(vector-set! (car c) %status 1);;force visible may change
254254
(process-match-parent (car c))
255-
(vector-set! (car c) %x sx)
256-
(vector-set! (car c) %y sy)
255+
(vector-set! (car c) %x (+ sx (vector-ref (car c) %margin-left)))
256+
(vector-set! (car c) %y (+ sy (vector-ref (car c) %margin-top)))
257257

258258
(if (pair? (cdr c))
259259
(set! ww (vector-ref (car (cdr c)) %w)))
260260

261-
(if (> (+ sx (vector-ref (car c) %w) ww ) (- w right) )
261+
(if (> (+ sx (vector-ref (car c) %w) ww ) (- w right
262+
(vector-ref (car c) %margin-right)
263+
(vector-ref (car c) %margin-left) ) )
262264
(begin
263265
(set! sx left)
264266
(set! sy (+ sy (vector-ref (car c) %h)
265-
(vector-ref (car c) %margin-top)
267+
;;(vector-ref (car c) %margin-top)
266268
(vector-ref (car c) %margin-bottom)
267269
))
268270
)
269271
(begin
270272
(set! sx (+ sx (vector-ref (car c) %w)
271-
(vector-ref (car c) %margin-left)
273+
;;(vector-ref (car c) %margin-left)
272274
(vector-ref (car c) %margin-right)
273275
))
274276
)

0 commit comments

Comments
 (0)