@@ -27,8 +27,8 @@ pub struct ViewConfig {
27
27
scrollview bool
28
28
width int
29
29
height int
30
- full_width int
31
- full_height int
30
+ full_width int = - 1
31
+ full_height int = - 1
32
32
z_index int
33
33
texts []TextBlock
34
34
cut_lines bool = true
@@ -45,6 +45,7 @@ pub fn view(c ViewConfig) &ui.CanvasLayout {
45
45
full_width: c.full_width
46
46
full_height: c.full_height
47
47
z_index: c.z_index
48
+ full_size_fn: view_full_size
48
49
})
49
50
mut view := & View{
50
51
layout: layout
@@ -65,7 +66,7 @@ pub fn view(c ViewConfig) &ui.CanvasLayout {
65
66
}
66
67
67
68
fn view_init (c & ui.CanvasLayout) {
68
- println ("($c.x , $c.y )" )
69
+ println ("view init ($c.x , $c.y )" )
69
70
mut v := component_view (c)
70
71
v.update_texts ()
71
72
}
@@ -85,14 +86,19 @@ fn view_draw(c &ui.CanvasLayout, state voidptr) {
85
86
}
86
87
}
87
88
89
+ fn view_full_size (c & ui.CanvasLayout) (int , int ) {
90
+ println ("ici" )
91
+ return 500 , 500
92
+ }
93
+
88
94
fn (mut v View) load_fonts (fps map [string ]string ) {
89
95
// load TTF fonts
90
96
for k, fp in fps {
91
97
mut tf := ttf.TTF_File{}
92
98
tf.buf = os.read_bytes (fp) or { panic (err) }
93
- println ("TrueTypeFont file [$fp ] len: ${tf.buf.len} " )
99
+ // println("TrueTypeFont file [$fp] len: ${tf.buf.len}")
94
100
tf.init ()
95
- println ("Unit per EM: $tf.units_per_em " )
101
+ // println("Unit per EM: $tf.units_per_em")
96
102
v.tf[k] = tf
97
103
}
98
104
}
141
147
max_width int
142
148
x_end int
143
149
y_end int
150
+ beside bool
144
151
// style
145
152
fontname string
146
153
fontsize int = 22
@@ -155,10 +162,10 @@ fn (mut tb TextBlock) join() string {
155
162
156
163
fn (mut v View) update_texts () {
157
164
for i, _ in v.texts {
158
- println ("i=$i " )
165
+ // println("i=$i")
159
166
v.update_text_block (i)
160
167
}
161
- println ("texts: ${v.texts} " )
168
+ // println("texts: ${v.texts}")
162
169
}
163
170
164
171
fn (mut v View) update_text_block (i int ) {
@@ -168,8 +175,7 @@ fn (mut v View) update_text_block(i int) {
168
175
169
176
mut text_block := & (v.texts[i])
170
177
text := text_block.join ()
171
- //
172
- println ("text = $text " )
178
+ // println("text = $text")
173
179
174
180
unsafe {
175
181
text_block.text.free ()
@@ -186,7 +192,7 @@ fn (mut v View) update_text_block(i int) {
186
192
mut new_y := []int {}
187
193
188
194
mut y_base := int ((bmp.tf.y_max - bmp.tf.y_min) * bmp.scale)
189
- println ('y_base: $y_base (($bmp.tf.y_max - $bmp.tf.y_min ) * $bmp.scale )' )
195
+ // println('y_base: $y_base (($bmp.tf.y_max - $bmp.tf.y_min) * $bmp.scale)')
190
196
// spaces data
191
197
mut space_cw , _ := bmp.tf.get_horizontal_metrics (u16 (` ` ))
192
198
space_cw = int (space_cw * bmp.scale)
@@ -211,11 +217,11 @@ fn (mut v View) update_text_block(i int) {
211
217
for txt in text.split_into_lines () {
212
218
bmp.space_cw = old_space_cw
213
219
mut w , _ := bmp.get_bbox (txt)
214
- println ("${bmp.get_bbox(txt)} $txt " )
220
+ // println("${bmp.get_bbox(txt)} $txt")
215
221
if w < = v.text_width || v.cut_lines == false {
216
222
// println("Solid block!")
217
223
left_offset := int ((v.text_width - w) * offset_flag)
218
- println ("left_offset: $left_offset = ($v.text_width - $w ) * $offset_flag )" )
224
+ // println("left_offset: $left_offset = ($v.text_width - $w) * $offset_flag)")
219
225
if bmp.justify && (f32 (w) / f32 (v.text_width)) > = bmp.justify_fill_ratio {
220
226
bmp.space_cw = old_space_cw + get_justify_space_cw (txt, w, v.text_width, space_cw)
221
227
}
@@ -225,7 +231,7 @@ fn (mut v View) update_text_block(i int) {
225
231
new_text << txt
226
232
end_x , _ = bmp.get_bbox (txt)
227
233
end_x + = x + left_offset
228
- println ("$new_x , $new_y , $new_text " )
234
+ // println("$new_x, $new_y, $new_text")
229
235
y + = y_base
230
236
end_y = y
231
237
} else {
@@ -259,7 +265,7 @@ fn (mut v View) update_text_block(i int) {
259
265
new_text << tmp_str
260
266
end_x , _ = bmp.get_bbox (txt)
261
267
end_x + = x + left_offset
262
- println ("22: $new_x , $new_y , $new_text " )
268
+ // println("22: $new_x, $new_y, $new_text")
263
269
y + = y_base
264
270
end_y = y
265
271
txt1 = txt1 [c..]
@@ -287,13 +293,60 @@ fn (mut v View) draw_text(i int) {
287
293
mut bmp := v.ttf_render[i].bmp
288
294
text_block := v.texts[i]
289
295
for k, txt in text_block.text {
290
- // println("k=$k (${text_block.x[k]}, ${text_block.y[k]}): $txt")
291
296
bmp.set_pos (text_block.x[k], text_block.y[k])
297
+ // if k % 2 == 0 {
298
+ // bmp.color = u32(gx.red.rgba8())
299
+ // } else {
300
+ // bmp.color = u32(gx.yellow.rgba8())
301
+ // }
302
+ // println("k=$k $bmp.color (${text_block.x[k]}, ${text_block.y[k]}): $txt")
292
303
bmp.draw_text (txt)
293
304
}
294
305
}
295
306
307
+ pub fn (mut v View) create_text_block (i int ) {
308
+ mut tf_skl := & (v.ttf_render[i])
309
+
310
+ sz := tf_skl.bmp.width * tf_skl.bmp.height * tf_skl.bmp.bp
311
+
312
+ // if true { return }
313
+
314
+ // RAM buffer
315
+ if sz > tf_skl.bmp.buf_size {
316
+ if sz > 0 {
317
+ unsafe { free (tf_skl.bmp.buf) }
318
+ }
319
+ // println('Alloc: $sz bytes')
320
+ tf_skl.bmp.buf = unsafe { malloc_noscan (sz) }
321
+ tf_skl.bmp.buf_size = sz
322
+ }
323
+
324
+ tf_skl.bmp.init_filler ()
325
+
326
+ // draw the text
327
+ mut y_base := int ((tf_skl.bmp.tf.y_max - tf_skl.bmp.tf.y_min) * tf_skl.bmp.scale)
328
+ tf_skl.bmp.set_pos (0 , y_base)
329
+ tf_skl.bmp.clear ()
330
+
331
+ v.draw_text (i)
332
+ // v.draw_text_block(i, x: 0, y: 0, w: v.text_width, h: v.text_height)
333
+ tf_skl.format_texture ()
334
+ }
335
+
336
+ fn get_justify_space_cw (txt string , w int , block_w int , space_cw int ) f32 {
337
+ num_spaces := txt.count (' ' )
338
+ if num_spaces < 1 {
339
+ return 0
340
+ }
341
+ delta := block_w - w
342
+ // println("num spc: $num_spaces")
343
+ // println("delta: ${txt} w:$w bw:$block_w space_cw:$space_cw")
344
+ res := f32 (delta) / f32 (num_spaces) / f32 (space_cw)
345
+ // println("res: $res")
346
+ return res
347
+ }
296
348
349
+ /*
297
350
pub struct DrawTextBlockConfig {
298
351
x int // x postion of the left high corner
299
352
y int // y postion of the left high corner
@@ -302,7 +355,6 @@ pub struct DrawTextBlockConfig {
302
355
cut_lines bool = true
303
356
}
304
357
305
-
306
358
pub fn (mut v View) draw_text_block(i int, block DrawTextBlockConfig) {
307
359
mut bmp := v.ttf_render[i].bmp
308
360
text := v.texts[i].join()
@@ -392,46 +444,4 @@ pub fn (mut v View) draw_text_block(i int, block DrawTextBlockConfig) {
392
444
393
445
bmp.space_cw = old_space_cw
394
446
}
395
-
396
- pub fn (mut v View) create_text_block (i int ) {
397
- mut tf_skl := & (v.ttf_render[i])
398
-
399
- sz := tf_skl.bmp.width * tf_skl.bmp.height * tf_skl.bmp.bp
400
-
401
- // if true { return }
402
-
403
- // RAM buffer
404
- if sz > tf_skl.bmp.buf_size {
405
- if sz > 0 {
406
- unsafe { free (tf_skl.bmp.buf) }
407
- }
408
- // println('Alloc: $sz bytes')
409
- tf_skl.bmp.buf = unsafe { malloc_noscan (sz) }
410
- tf_skl.bmp.buf_size = sz
411
- }
412
-
413
- tf_skl.bmp.init_filler ()
414
-
415
- // draw the text
416
- mut y_base := int ((tf_skl.bmp.tf.y_max - tf_skl.bmp.tf.y_min) * tf_skl.bmp.scale)
417
- tf_skl.bmp.set_pos (0 , y_base)
418
- tf_skl.bmp.clear ()
419
-
420
- v.draw_text (i)
421
- // v.draw_text_block(i, x: 0, y: 0, w: v.text_width, h: v.text_height)
422
- tf_skl.format_texture ()
423
- }
424
-
425
- fn get_justify_space_cw (txt string , w int , block_w int , space_cw int ) f32 {
426
- num_spaces := txt.count (' ' )
427
- if num_spaces < 1 {
428
- return 0
429
- }
430
- delta := block_w - w
431
- // println("num spc: $num_spaces")
432
- // println("delta: ${txt} w:$w bw:$block_w space_cw:$space_cw")
433
- res := f32 (delta) / f32 (num_spaces) / f32 (space_cw)
434
- // println("res: $res")
435
- return res
436
- }
437
-
447
+ */
0 commit comments