gfx: Text: cache loaded font at least
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
bd655828e3
commit
e041bc65ea
1 changed files with 8 additions and 3 deletions
|
|
@ -75,6 +75,8 @@ fn update(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var font_once: ?gfx.Font = null;
|
||||||
|
|
||||||
fn updatePipeline(
|
fn updatePipeline(
|
||||||
entities: *mach.Entities.Mod,
|
entities: *mach.Entities.Mod,
|
||||||
text: *Mod,
|
text: *Mod,
|
||||||
|
|
@ -143,13 +145,16 @@ fn updatePipeline(
|
||||||
|
|
||||||
for (segments, styles) |segment, style| {
|
for (segments, styles) |segment, style| {
|
||||||
// Load the font
|
// Load the font
|
||||||
// TODO(text): allow specifying a font
|
// TODO(text): allow specifying a custom font
|
||||||
// TODO(text): keep fonts around for reuse later
|
// TODO(text): keep fonts around for reuse later
|
||||||
const font_name = core.__entities.getComponent(style, .mach_gfx_text_style, .font_name).?;
|
const font_name = core.__entities.getComponent(style, .mach_gfx_text_style, .font_name).?;
|
||||||
_ = font_name; // TODO: actually use font name
|
_ = font_name; // TODO: actually use font name
|
||||||
const font_bytes = @import("font-assets").fira_sans_regular_ttf;
|
const font_bytes = @import("font-assets").fira_sans_regular_ttf;
|
||||||
var font = try gfx.Font.initBytes(font_bytes);
|
var font = if (font_once) |f| f else blk: {
|
||||||
defer font.deinit(allocator);
|
font_once = try gfx.Font.initBytes(font_bytes);
|
||||||
|
break :blk font_once.?;
|
||||||
|
};
|
||||||
|
// defer font.deinit(allocator);
|
||||||
|
|
||||||
// TODO(text): respect these style parameters
|
// TODO(text): respect these style parameters
|
||||||
const font_size = core.__entities.getComponent(style, .mach_gfx_text_style, .font_size).?;
|
const font_size = core.__entities.getComponent(style, .mach_gfx_text_style, .font_size).?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue