Add a way to pass font as bytes
This commit is contained in:
parent
0501a4edde
commit
e8401e0d6e
1 changed files with 21 additions and 11 deletions
|
@ -23,13 +23,20 @@ use std::{ops::Deref, sync::Weak};
|
|||
use paste::paste;
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug)]
|
||||
pub struct GuiHandlerCreateInfo {
|
||||
pub enum Font<'a> {
|
||||
Path(AssetPath),
|
||||
Bytes(&'a [u8]),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug)]
|
||||
pub struct GuiHandlerCreateInfo<'a> {
|
||||
// default button textures
|
||||
pub menu_button: AssetPath,
|
||||
pub menu_button_selected: AssetPath,
|
||||
|
||||
// path to the alphabet image
|
||||
pub font_path: AssetPath,
|
||||
#[serde(borrow)]
|
||||
pub font_path: Font<'a>,
|
||||
|
||||
// sound info
|
||||
#[cfg(feature = "audio")]
|
||||
|
@ -41,7 +48,7 @@ pub struct GuiHandlerCreateInfo {
|
|||
pub resource_directory: AssetPath,
|
||||
}
|
||||
|
||||
impl GuiHandlerCreateInfo {
|
||||
impl<'a> GuiHandlerCreateInfo<'a> {
|
||||
pub const fn default() -> Self {
|
||||
GuiHandlerCreateInfo {
|
||||
// default button textures
|
||||
|
@ -49,7 +56,7 @@ impl GuiHandlerCreateInfo {
|
|||
menu_button_selected: AssetPath::default(),
|
||||
|
||||
// path to the alphabet image
|
||||
font_path: AssetPath::default(),
|
||||
font_path: Font::Path(AssetPath::default()),
|
||||
|
||||
// sound info
|
||||
#[cfg(feature = "audio")]
|
||||
|
@ -156,7 +163,7 @@ pub struct GuiHandler {
|
|||
|
||||
impl GuiHandler {
|
||||
pub fn new(
|
||||
gui_handler_create_info: GuiHandlerCreateInfo,
|
||||
gui_handler_create_info: GuiHandlerCreateInfo<'_>,
|
||||
context: &Arc<dyn ContextInterface>,
|
||||
) -> Result<Arc<GuiHandler>> {
|
||||
let device = context.device();
|
||||
|
@ -1264,13 +1271,16 @@ impl GuiHandler {
|
|||
device: &Arc<Device>,
|
||||
queue: &Arc<Mutex<Queue>>,
|
||||
descriptor_layout: Arc<DescriptorSetLayout>,
|
||||
path: AssetPath,
|
||||
font: Font<'_>,
|
||||
) -> Result<(Arc<Image>, Arc<DescriptorPool>, Arc<DescriptorSet>)> {
|
||||
let texture = Image::from_file(path)?
|
||||
.format(VK_FORMAT_R8G8B8A8_UNORM)
|
||||
.max_mip_map_levels()
|
||||
.attach_sampler(Sampler::pretty_sampler().build(device)?)
|
||||
.build(device, queue)?;
|
||||
let texture = match font {
|
||||
Font::Path(path) => Image::from_file(path)?,
|
||||
Font::Bytes(bytes) => Image::from_slice(bytes)?,
|
||||
}
|
||||
.format(VK_FORMAT_R8G8B8A8_UNORM)
|
||||
.max_mip_map_levels()
|
||||
.attach_sampler(Sampler::pretty_sampler().build(device)?)
|
||||
.build(device, queue)?;
|
||||
|
||||
let descriptor_pool = DescriptorPool::builder()
|
||||
.set_layout(descriptor_layout)
|
||||
|
|
Loading…
Reference in a new issue