vlang / ui

A cross-platform UI library written in V
MIT License
2.33k stars 153 forks source link

Unable to display text #412

Closed QuentinWidlocher closed 2 years ago

QuentinWidlocher commented 2 years ago
v doctor output ``` OS: linux, Ubuntu 20.04.3 LTS Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz CC version: cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 getwd: /mnt/809EB2A59EB292E0/Perso/v/test-ui-2 vmodules: /home/quentin/.vmodules vroot: /mnt/809EB2A59EB292E0/Perso/v/v vexe: /mnt/809EB2A59EB292E0/Perso/v/v/v vexe mtime: 2022-01-13 12:54:47 is vroot writable: true is vmodules writable: true V full version: V 0.2.4 7882915.7fbd856 Git version: git version 2.25.1 Git vroot status: weekly.2021.46-534-g7fbd856b .git/config present: true thirdparty/tcc status: thirdparty-linux-amd64 3654d6a8 ```

What did you do?

Executed v run app.v on this file :

app.v ```v import ui const ( win_width = 208 win_height = 46 ) struct App { mut: counter string = '0' window &ui.Window = 0 } fn main() { mut app := &App{} app.window = ui.window( width: win_width height: win_height title: 'Counter' state: app children: [ ui.row( spacing: 5 margin: ui.Margin{5, 5, 5, 5} children: [ ui.textbox( max_len: 20 read_only: true is_numeric: true text: &app.counter ), ui.button( width: 24 height: 24 text: 'Alt' onclick: btn_count_click ), ] ), ] ) ui.run(app.window) } fn btn_count_click(mut app App, btn &ui.Button) { app.counter = (app.counter.int() + 1).str() } ```

What did you expect to see?

A nice counter example

What did you see instead?

An ugly counter example without text, and the console logging gg: draw_text(): font not initialized repeatedly

ghost commented 2 years ago

Counter_001

No problem on my ArchLinux.

what is your result of fc-match -s? or

import os.font
font.default()

or you can set font_path: '/path/to/your/favorite_font.ttf' to app.window

tzSharing commented 2 years ago

Counter_001

No problem on my ArchLinux.

what is your result of fc-match -s? or

import os.font
font.default()

or you can set font_path: '/path/to/your/favorite_font.ttf' to app.window

Why I set font_path, still can not display Chinese fonts normally?

20220118022009 20220118021850

ghost commented 2 years ago

Is that /fonts/font.ttf an absolute path? Seems a relative path to me.

Or you can use https://modules.vlang.io/os.html#resource_abs_path like fp := os.resource_abs_path(os.join_path('assets/fonts/', 'RobotoMono-Regular.ttf'))

And I don't have Windows, so I could be wrong, but The way to specify the path is like this. https://github.com/vlang/v/blob/d8263171ff21809b6d5514dab481928ee2f3af22/vlib/os/font/font.v#L25

ghost commented 2 years ago

Currently, there are a lot of hard-coded places like this in vlib. If you can figure out how to get the system's default fonts on Windows programmatically, please PR it.

ghost commented 2 years ago

If you're using vscode, I'd recommend adding v and .vmodules folders to your workspace, like this. That way you'll be able to find plenty of examples of vlib with Search: Find in Files, ctrl+shift+F. 範囲を選択_033

tzSharing commented 2 years ago

Is that /fonts/font.ttf an absolute path? Seems a relative path to me.

Or you can use https://modules.vlang.io/os.html#resource_abs_path like fp := os.resource_abs_path(os.join_path('assets/fonts/', 'RobotoMono-Regular.ttf'))

And I don't have Windows, so I could be wrong, but The way to specify the path is like this. https://github.com/vlang/v/blob/d8263171ff21809b6d5514dab481928ee2f3af22/vlib/os/font/font.v#L25

I'm using Windows 10, I've tried many ways but all failed.But the absolute path of font_path printed out is correct. 20220118185944

QuentinWidlocher commented 2 years ago

what is your result of fc-match -s?

fc-match -s ``` DejaVuSans.ttf: "DejaVu Sans" "Book" DejaVuSans-Bold.ttf: "DejaVu Sans" "Bold" DejaVuSans-Oblique.ttf: "DejaVu Sans" "Oblique" DejaVuSans-BoldOblique.ttf: "DejaVu Sans" "Bold Oblique" n019003l.pfb: "Nimbus Sans L" "Regular" NimbusSans-Regular.otf: "Nimbus Sans" "Regular" Loma.ttf: "Loma" "Regular" Waree.ttf: "Waree" "Regular" Umpush-Bold.ttf: "Umpush" "Bold" Laksaman.ttf: "Laksaman" "Regular" NotoSansCJK-Regular.ttc: "Noto Sans CJK JP" "Regular" Lohit-Devanagari.ttf: "Lohit Devanagari" "Regular" DroidSansFallbackFull.ttf: "Droid Sans Fallback" "Regular" KhmerOS.ttf: "Khmer OS" "Regular" MuktiNarrow.ttf: "Mukti Narrow" "Regular" padmaa-Medium-0.5.ttf: "padmaa" "regular" padmaa.ttf: "padmaa" "Normal" padmaa-Bold.1.1.ttf: "padmaa-Bold.1.1" "Bold.1.1" Lohit-Bengali.ttf: "Lohit Bengali" "Regular" Lohit-Gujarati.ttf: "Lohit Gujarati" "Regular" Lohit-Tamil.ttf: "Lohit Tamil" "Regular" Meera-Regular.ttf: "Meera" "Regular" Lohit-Kannada.ttf: "Lohit Kannada" "Regular" Lohit-Telugu.ttf: "Lohit Telugu" "Regular" lklug.ttf: "LKLUG" "Regular" FreeSans.ttf: "FreeSans" "Regular" FreeMono.ttf: "FreeMono" "Regular" FreeSerif.ttf: "FreeSerif" "Regular" opens___.ttf: "OpenSymbol" "Regular" Norasi.ttf: "Norasi" "Regular" Rachana-Regular.ttf: "Rachana" "Regular" KacstOne.ttf: "KacstOne" "Regular" Purisa.ttf: "Purisa" "Regular" Padauk-Regular.ttf: "Padauk" "Regular" Nunito-Regular.ttf: "Nunito" "Regular" Sawasdee.ttf: "Sawasdee" "Regular" DejaVuMathTeXGyre.ttf: "DejaVu Math TeX Gyre" "Regular" DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book" DejaVuSerif.ttf: "DejaVu Serif" "Book" LiberationMono-Regular.ttf: "Liberation Mono" "Regular" Lato-Regular.ttf: "Lato" "Regular" AbyssinicaSIL-Regular.ttf: "Abyssinica SIL" "Regular" D050000L.otf: "D050000L" "Regular" TibetanMachineUni.ttf: "Tibetan Machine Uni" "Regular" Manjari-Regular.otf: "Manjari" "Regular" Pothana2000.ttf: "Pothana2000" "Regular" chandas1-2.ttf: "Chandas" "Regular" Pagul.ttf: "Pagul" "猀 愀瀀瀀氀" mry_KacstQurn.ttf: "mry_KacstQurn" "Regular" Rasa-Regular.ttf: "Rasa" "Regular" Phetsarath_OT.ttf: "Phetsarath OT" "Phetsarath OT" Ubuntu-C.ttf: "Ubuntu Condensed" "Regular" Ubuntu-R.ttf: "Ubuntu" "Regular" s050000l.pfb: "Standard Symbols L" "Regular" FiraCode-Retina.otf: "Fira Code" "Retina" Samyak-Devanagari.ttf: "Samyak Devanagari" "Regular" Rekha.ttf: "Rekha" "Medium" utkal.ttf: "ori1Uni" "Medium" LiberationSerif-Italic.ttf: "Liberation Serif" "Italic" Apple Color Emoji.ttf: "Apple Color Emoji" "Regular" joypixels-android.ttf: "JoyPixels" "Regular" NotoColorEmoji.ttf: "Noto Color Emoji" "Regular" ```

font.default() returns /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf

or you can set font_path: '/path/to/your/favorite_font.ttf' to app.window

This works when setting the font.default() to app.window, so thanks !

ghost commented 2 years ago

@tzSharing hmm.. try and see again change this path to your path and remove app.window.font_path. https://github.com/vlang/v/blob/d8263171ff21809b6d5514dab481928ee2f3af22/vlib/os/font/font.v#L32

Are you living in China and discord is banned? https://discord.com/channels/592103645835821068/665558664949530644

tzSharing commented 2 years ago

@tzSharing hmm.. try and see again change this path to your path and remove app.window.font_path. https://github.com/vlang/v/blob/d8263171ff21809b6d5514dab481928ee2f3af22/vlib/os/font/font.v#L32

Are you living in China and discord is banned? https://discord.com/channels/592103645835821068/665558664949530644

Wow, with this method, I modified the default() source code in v/vlib/os/font/font.v, it was successfully repaired, I didn't even think of this method. thanks. In addition, regarding discord, my network is completely inaccessible, and GitHub can be accessed normally most of the time, but the speed is very slow.

I feel like this is a bug that needs to be fixed.

20220118203851 20220118211227

20220118203701

ghost commented 2 years ago

Yeah, I almost confirmed that the bug belongs to ui not vlib via both of yours. I don't have time to fix it right now, so I recommend leaving the default() one as it is.

spytheman commented 2 years ago

The VUI_FONT env variable, exists exactly for easy experimentation / overriding of the default font path.

spytheman commented 2 years ago

You can call os.setenv('VUI_FONT', 'C:\\Windows\Fonts\\simfang.ttf', true), before your font.default() and/or gg calls, and then font.default() will return 'C:\\Windows\Fonts\\simfang.ttf' without the need for patching the vlib source code.

tzSharing commented 2 years ago

You can call os.setenv('VUI_FONT', 'C:\\Windows\Fonts\\simfang.ttf', true), before your font.default() and/or gg calls, and then font.default() will return 'C:\\Windows\Fonts\\simfang.ttf' without the need for patching the vlib source code.

I just tried the method you said, and it works. I not only loaded the system fonts, but also successfully loaded the relative path fonts in the project.Thanks! 20220122165344 20220122165040 20220122165130