Skip to content

Commit c8303c9

Browse files
committed
fix tabs component
1 parent 2efcc80 commit c8303c9

File tree

6 files changed

+81
-74
lines changed

6 files changed

+81
-74
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.dSym
1+
*.dSym
2+
*.mov

component_tabs.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn tabs(c TabsConfig) &ui.Stack {
6161
mut layout := ui.column({
6262
id: c.id
6363
widths: [ui.compact, ui.stretch]
64-
heights: [ui.compact, ui.stretch]
64+
heights: [30., ui.stretch]
6565
}, [
6666
tab_bar,
6767
m_pages[tab_active],
@@ -149,7 +149,7 @@ fn (mut tabs Tabs) transpose() {
149149
}
150150
tabs.tab_bar.transpose(false)
151151
tabs.tab_bar.update_layout()
152-
tabs.layout.transpose(false)
152+
tabs.layout.transpose(true)
153153
tabs.layout.update_layout()
154154
}
155155
}

component_view.v

+69-59
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub struct ViewConfig {
2727
scrollview bool
2828
width int
2929
height int
30-
full_width int
31-
full_height int
30+
full_width int = -1
31+
full_height int = -1
3232
z_index int
3333
texts []TextBlock
3434
cut_lines bool = true
@@ -45,6 +45,7 @@ pub fn view(c ViewConfig) &ui.CanvasLayout {
4545
full_width: c.full_width
4646
full_height: c.full_height
4747
z_index: c.z_index
48+
full_size_fn: view_full_size
4849
})
4950
mut view := &View{
5051
layout: layout
@@ -65,7 +66,7 @@ pub fn view(c ViewConfig) &ui.CanvasLayout {
6566
}
6667

6768
fn view_init(c &ui.CanvasLayout) {
68-
println("($c.x, $c.y)")
69+
println("view init ($c.x, $c.y)")
6970
mut v := component_view(c)
7071
v.update_texts()
7172
}
@@ -85,14 +86,19 @@ fn view_draw(c &ui.CanvasLayout, state voidptr) {
8586
}
8687
}
8788

89+
fn view_full_size(c &ui.CanvasLayout) (int, int) {
90+
println("ici")
91+
return 500, 500
92+
}
93+
8894
fn (mut v View) load_fonts(fps map[string]string) {
8995
// load TTF fonts
9096
for k, fp in fps {
9197
mut tf := ttf.TTF_File{}
9298
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}")
94100
tf.init()
95-
println("Unit per EM: $tf.units_per_em")
101+
// println("Unit per EM: $tf.units_per_em")
96102
v.tf[k] = tf
97103
}
98104
}
@@ -141,6 +147,7 @@ mut:
141147
max_width int
142148
x_end int
143149
y_end int
150+
beside bool
144151
// style
145152
fontname string
146153
fontsize int = 22
@@ -155,10 +162,10 @@ fn (mut tb TextBlock) join() string {
155162

156163
fn (mut v View) update_texts() {
157164
for i, _ in v.texts {
158-
println("i=$i")
165+
// println("i=$i")
159166
v.update_text_block(i)
160167
}
161-
println("texts: ${v.texts}")
168+
// println("texts: ${v.texts}")
162169
}
163170

164171
fn (mut v View) update_text_block(i int) {
@@ -168,8 +175,7 @@ fn (mut v View) update_text_block(i int) {
168175

169176
mut text_block := &(v.texts[i])
170177
text := text_block.join()
171-
//
172-
println("text = $text")
178+
// println("text = $text")
173179

174180
unsafe{
175181
text_block.text.free()
@@ -186,7 +192,7 @@ fn (mut v View) update_text_block(i int) {
186192
mut new_y := []int{}
187193

188194
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)')
190196
// spaces data
191197
mut space_cw, _ := bmp.tf.get_horizontal_metrics(u16(` `))
192198
space_cw = int(space_cw * bmp.scale)
@@ -211,11 +217,11 @@ fn (mut v View) update_text_block(i int) {
211217
for txt in text.split_into_lines() {
212218
bmp.space_cw = old_space_cw
213219
mut w, _ := bmp.get_bbox(txt)
214-
println("${bmp.get_bbox(txt)} $txt")
220+
// println("${bmp.get_bbox(txt)} $txt")
215221
if w <= v.text_width || v.cut_lines == false {
216222
// println("Solid block!")
217223
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)")
219225
if bmp.justify && (f32(w) / f32(v.text_width)) >= bmp.justify_fill_ratio {
220226
bmp.space_cw = old_space_cw + get_justify_space_cw(txt, w, v.text_width, space_cw)
221227
}
@@ -225,7 +231,7 @@ fn (mut v View) update_text_block(i int) {
225231
new_text << txt
226232
end_x, _ = bmp.get_bbox(txt)
227233
end_x += x + left_offset
228-
println("$new_x, $new_y, $new_text")
234+
// println("$new_x, $new_y, $new_text")
229235
y += y_base
230236
end_y = y
231237
} else {
@@ -259,7 +265,7 @@ fn (mut v View) update_text_block(i int) {
259265
new_text << tmp_str
260266
end_x, _ = bmp.get_bbox(txt)
261267
end_x += x + left_offset
262-
println("22: $new_x, $new_y, $new_text")
268+
// println("22: $new_x, $new_y, $new_text")
263269
y += y_base
264270
end_y = y
265271
txt1 = txt1[c..]
@@ -287,13 +293,60 @@ fn (mut v View) draw_text(i int) {
287293
mut bmp := v.ttf_render[i].bmp
288294
text_block := v.texts[i]
289295
for k, txt in text_block.text {
290-
// println("k=$k (${text_block.x[k]}, ${text_block.y[k]}): $txt")
291296
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")
292303
bmp.draw_text(txt)
293304
}
294305
}
295306

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+
}
296348

349+
/*
297350
pub struct DrawTextBlockConfig {
298351
x int // x postion of the left high corner
299352
y int // y postion of the left high corner
@@ -302,7 +355,6 @@ pub struct DrawTextBlockConfig {
302355
cut_lines bool = true
303356
}
304357
305-
306358
pub fn (mut v View) draw_text_block(i int, block DrawTextBlockConfig) {
307359
mut bmp := v.ttf_render[i].bmp
308360
text := v.texts[i].join()
@@ -392,46 +444,4 @@ pub fn (mut v View) draw_text_block(i int, block DrawTextBlockConfig) {
392444
393445
bmp.space_cw = old_space_cw
394446
}
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+
*/

examples/demo_tabs.v

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ fn main() {
4242
tabs: ['tab1', 'tab2', 'tab3']
4343
pages: [
4444
ui.column({
45-
heights: ui.compact
46-
widths: ui.compact
47-
bg_color: gx.rgb(200, 100, 200)
48-
}, [
49-
ui.button(id: 'left1', text: 'toto', padding: .1, radius: .25),
50-
ui.button(id: 'left2', text: 'toto2'),
51-
]),
45+
heights: ui.compact
46+
widths: ui.compact
47+
bg_color: gx.rgb(200, 100, 200)
48+
}, [
49+
ui.button(id: 'left1', text: 'toto', padding: .1, radius: .25),
50+
ui.button(id: 'left2', text: 'toto2'),
51+
]),
5252
ui.column({
5353
heights: ui.compact
5454
widths: ui.compact

examples/demo_view

-1.39 MB
Binary file not shown.

examples/demo_view.v

+1-5
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ fn main() {
3030
// ui.rectangle({color: gx.white})
3131
uic.view(
3232
id: "view"
33-
// width: 300
34-
// height: 300
35-
full_width: 500
36-
full_height: 500
3733
color: gx.white
3834
font_paths: map{
3935
'imprima': "assets/Imprima-Regular.ttf"
@@ -47,7 +43,7 @@ Tommorow I'm not so sure :(
4743
But Vwill prevail for sure, V is the way!!
4844
"]
4945
color: gx.blue
50-
fontsize: 32
46+
fontsize: 14
5147
}
5248
{
5349
text: ["Todayyy it is a good day!

0 commit comments

Comments
 (0)