mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gg: allow fonts loaded with $embed_file() to be used (#8263)
This commit is contained in:
@ -3,7 +3,6 @@ import gx
|
||||
import sokol.sapp
|
||||
import time
|
||||
import rand
|
||||
import os
|
||||
|
||||
// constants
|
||||
const (
|
||||
@ -37,11 +36,11 @@ enum Direction {
|
||||
|
||||
struct App {
|
||||
mut:
|
||||
gg &gg.Context
|
||||
score int
|
||||
snake []Pos
|
||||
dir Direction
|
||||
food Pos
|
||||
gg &gg.Context
|
||||
score int
|
||||
snake []Pos
|
||||
dir Direction
|
||||
food Pos
|
||||
start_time i64
|
||||
last_tick i64
|
||||
}
|
||||
@ -166,6 +165,8 @@ fn on_frame(mut app App) {
|
||||
app.gg.end()
|
||||
}
|
||||
|
||||
const font = $embed_file('../assets/fonts/RobotoMono-Regular.ttf')
|
||||
|
||||
// setup
|
||||
fn main() {
|
||||
mut app := App{
|
||||
@ -173,6 +174,11 @@ fn main() {
|
||||
}
|
||||
app.reset_game()
|
||||
|
||||
mut font_copy := font
|
||||
font_bytes := unsafe {
|
||||
font_copy.data().vbytes(font_copy.len)
|
||||
}
|
||||
|
||||
app.gg = gg.new_context(
|
||||
bg_color: gx.white
|
||||
frame_fn: on_frame
|
||||
@ -184,7 +190,7 @@ fn main() {
|
||||
create_window: true
|
||||
resizable: false
|
||||
window_title: 'snek'
|
||||
font_path: os.resource_abs_path(os.join_path('../assets/fonts/', 'RobotoMono-Regular.ttf'))
|
||||
font_bytes_normal: font_bytes
|
||||
)
|
||||
|
||||
app.gg.run()
|
||||
|
Reference in New Issue
Block a user