Skip to content
Snippets Groups Projects
Commit 4f936f7a authored by StarArawn's avatar StarArawn
Browse files

Fixed issues with fonts and text rendering.

parent 09b8a057
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
assets/antiquity.png

41.1 KiB

...@@ -36,4 +36,8 @@ impl FontMapping { ...@@ -36,4 +36,8 @@ impl FontMapping {
.get(&id) .get(&id)
.and_then(|item| Some(item.clone())) .and_then(|item| Some(item.clone()))
} }
pub fn get(&self, font: &Handle<KayakFont>) -> Option<u16> {
self.font_ids.get(font).and_then(|font_id| Some(*font_id))
}
} }
...@@ -86,8 +86,6 @@ pub fn extract( ...@@ -86,8 +86,6 @@ pub fn extract(
1.0 1.0
}; };
// dbg!(&render_primitives);
let mut extracted_quads = Vec::new(); let mut extracted_quads = Vec::new();
for render_primitive in render_primitives { for render_primitive in render_primitives {
match render_primitive { match render_primitive {
......
...@@ -25,9 +25,9 @@ fn BlueButton(context: KayakContext, children: Children, styles: Option<Style>) ...@@ -25,9 +25,9 @@ fn BlueButton(context: KayakContext, children: Children, styles: Option<Style>)
let (handle1, handle2) = { let (handle1, handle2) = {
let asset_server = world.get_resource::<AssetServer>().unwrap(); let asset_server = world.get_resource::<AssetServer>().unwrap();
let handle1: Handle<bevy::render::texture::Image> = let handle1: Handle<bevy::render::texture::Image> =
asset_server.load("../assets/kenny/buttonSquare_blue.png");
let handle2: Handle<bevy::render::texture::Image> =
asset_server.load("../assets/kenny/buttonSquare_blue_pressed.png"); asset_server.load("../assets/kenny/buttonSquare_blue_pressed.png");
let handle2: Handle<bevy::render::texture::Image> =
asset_server.load("../assets/kenny/buttonSquare_blue.png");
(handle1, handle2) (handle1, handle2)
}; };
...@@ -88,6 +88,8 @@ fn startup( ...@@ -88,6 +88,8 @@ fn startup(
commands.spawn_bundle(UICameraBundle::new()); commands.spawn_bundle(UICameraBundle::new());
font_mapping.add(asset_server.load("roboto.kayak_font")); font_mapping.add(asset_server.load("roboto.kayak_font"));
let main_font = asset_server.load("antiquity.kayak_font");
font_mapping.add(main_font.clone());
let handle: Handle<bevy::render::texture::Image> = asset_server.load("kenny/panel_brown.png"); let handle: Handle<bevy::render::texture::Image> = asset_server.load("kenny/panel_brown.png");
let panel_brown_handle = image_manager.get(&handle); let panel_brown_handle = image_manager.get(&handle);
...@@ -97,6 +99,7 @@ fn startup( ...@@ -97,6 +99,7 @@ fn startup(
layout_type: StyleProp::Value(LayoutType::Column), layout_type: StyleProp::Value(LayoutType::Column),
width: StyleProp::Value(Units::Pixels(512.0)), width: StyleProp::Value(Units::Pixels(512.0)),
height: StyleProp::Value(Units::Pixels(512.0)), height: StyleProp::Value(Units::Pixels(512.0)),
min_height: StyleProp::Value(Units::Pixels(0.0)),
padding_left: StyleProp::Value(Units::Stretch(1.0)), padding_left: StyleProp::Value(Units::Stretch(1.0)),
padding_right: StyleProp::Value(Units::Stretch(1.0)), padding_right: StyleProp::Value(Units::Stretch(1.0)),
padding_top: StyleProp::Value(Units::Stretch(1.0)), padding_top: StyleProp::Value(Units::Stretch(1.0)),
...@@ -113,21 +116,21 @@ fn startup( ...@@ -113,21 +116,21 @@ fn startup(
}; };
let header_styles = Style { let header_styles = Style {
width: StyleProp::Value(Units::Pixels(432.0)), width: StyleProp::Value(Units::Pixels(408.0)),
height: StyleProp::Value(Units::Pixels(64.0)), height: StyleProp::Value(Units::Pixels(42.0)),
bottom: StyleProp::Value(Units::Stretch(1.0)), bottom: StyleProp::Value(Units::Stretch(1.0)),
..Style::default() ..Style::default()
}; };
let play_button_styles = Style { let text_styles = Style {
width: StyleProp::Value(Units::Pixels(54.0)), width: StyleProp::Value(Units::Pixels(56.0)),
height: StyleProp::Value(Units::Pixels(45.0)), height: StyleProp::Value(Units::Pixels(24.0)),
..Style::default() ..Style::default()
}; };
let options_button_text_styles = Style { let options_button_text_styles = Style {
width: StyleProp::Value(Units::Pixels(102.0)), width: StyleProp::Value(Units::Pixels(94.0)),
height: StyleProp::Value(Units::Pixels(45.0)), height: StyleProp::Value(Units::Pixels(24.0)),
..Style::default() ..Style::default()
}; };
...@@ -136,6 +139,8 @@ fn startup( ...@@ -136,6 +139,8 @@ fn startup(
..Style::default() ..Style::default()
}; };
let main_font_id = font_mapping.get(&main_font);
render! { render! {
<App styles={Some(app_styles)}> <App styles={Some(app_styles)}>
<NinePatch <NinePatch
...@@ -150,17 +155,18 @@ fn startup( ...@@ -150,17 +155,18 @@ fn startup(
> >
<Text <Text
styles={Some(header_styles)} styles={Some(header_styles)}
size={50.0} size={35.0}
content={"Name My Game Plz".to_string()} content={"Name My Game Plz".to_string()}
font={main_font_id}
/> />
<BlueButton> <BlueButton>
<Text styles={Some(play_button_styles)} size={30.0} content={"Play".to_string()} /> <Text styles={Some(text_styles)} size={20.0} content={"Play".to_string()} font={main_font_id} />
</BlueButton> </BlueButton>
<BlueButton styles={Some(options_button_styles)}> <BlueButton styles={Some(options_button_styles)}>
<Text styles={Some(options_button_text_styles)} size={30.0} content={"Options".to_string()} /> <Text styles={Some(options_button_text_styles)} size={20.0} content={"Options".to_string()} font={main_font_id} />
</BlueButton> </BlueButton>
<BlueButton styles={Some(options_button_styles)}> <BlueButton styles={Some(options_button_styles)}>
<Text styles={Some(play_button_styles)} size={30.0} content={"Quit".to_string()} /> <Text styles={Some(text_styles)} size={20.0} content={"Quit".to_string()} font={main_font_id} />
</BlueButton> </BlueButton>
</NinePatch> </NinePatch>
</App> </App>
......
...@@ -42,6 +42,7 @@ impl Plugin for KayakFontPlugin { ...@@ -42,6 +42,7 @@ impl Plugin for KayakFontPlugin {
} }
pub fn init_font_texture( pub fn init_font_texture(
mut not_processed: Local<Vec<Handle<KayakFont>>>,
mut font_events: EventReader<AssetEvent<KayakFont>>, mut font_events: EventReader<AssetEvent<KayakFont>>,
mut images: ResMut<Assets<Image>>, mut images: ResMut<Assets<Image>>,
fonts: Res<Assets<KayakFont>>, fonts: Res<Assets<KayakFont>>,
...@@ -50,21 +51,28 @@ pub fn init_font_texture( ...@@ -50,21 +51,28 @@ pub fn init_font_texture(
for event in font_events.iter() { for event in font_events.iter() {
match event { match event {
AssetEvent::Created { handle } => { AssetEvent::Created { handle } => {
if let Some(font) = fonts.get(handle) { not_processed.push(handle.clone_weak());
if let Some(mut texture) = images.get_mut(&font.atlas_image) {
texture.texture_descriptor.format = TextureFormat::Rgba8Unorm;
texture.sampler_descriptor.min_filter = FilterMode::Linear;
texture.sampler_descriptor.mipmap_filter = FilterMode::Linear;
texture.sampler_descriptor.mag_filter = FilterMode::Linear;
texture.texture_descriptor.usage = TextureUsages::TEXTURE_BINDING
| TextureUsages::COPY_DST
| TextureUsages::COPY_SRC;
}
}
} }
_ => (), _ => (),
} }
} }
let not_processed_fonts = not_processed.drain(..).collect::<Vec<_>>();
for font_handle in not_processed_fonts {
if let Some(font) = fonts.get(&font_handle) {
if let Some(mut texture) = images.get_mut(&font.atlas_image) {
texture.texture_descriptor.format = TextureFormat::Rgba8Unorm;
texture.sampler_descriptor.min_filter = FilterMode::Linear;
texture.sampler_descriptor.mipmap_filter = FilterMode::Linear;
texture.sampler_descriptor.mag_filter = FilterMode::Linear;
texture.texture_descriptor.usage = TextureUsages::TEXTURE_BINDING
| TextureUsages::COPY_DST
| TextureUsages::COPY_SRC;
} else {
not_processed.push(font_handle.clone_weak());
}
}
}
} }
#[derive(Default)] #[derive(Default)]
......
...@@ -11,6 +11,8 @@ pub fn Clip(children: Children, styles: Option<Style>) { ...@@ -11,6 +11,8 @@ pub fn Clip(children: Children, styles: Option<Style>) {
render_command: StyleProp::Value(RenderCommand::Clip), render_command: StyleProp::Value(RenderCommand::Clip),
width: StyleProp::Value(Units::Stretch(1.0)), width: StyleProp::Value(Units::Stretch(1.0)),
height: StyleProp::Value(Units::Stretch(1.0)), height: StyleProp::Value(Units::Stretch(1.0)),
min_width: StyleProp::Value(Units::Stretch(1.0)),
min_height: StyleProp::Value(Units::Stretch(1.0)),
..styles.clone().unwrap_or_default() ..styles.clone().unwrap_or_default()
}); });
rsx! { rsx! {
......
...@@ -5,19 +5,14 @@ use kayak_ui::core::{ ...@@ -5,19 +5,14 @@ use kayak_ui::core::{
}; };
#[widget] #[widget]
pub fn Text(size: f32, content: String, styles: Option<Style>) { pub fn Text(size: f32, content: String, styles: Option<Style>, font: Option<u16>) {
let render_command = RenderCommand::Text { let render_command = RenderCommand::Text {
content, content,
size, size,
font: 0, // TODO: Support font passing here. Perhaps move to style? font: font.unwrap_or(0),
}; };
*styles = Some(Style { *styles = Some(Style {
render_command: StyleProp::Value(render_command), render_command: StyleProp::Value(render_command),
..styles.clone().unwrap_or_default() ..styles.clone().unwrap_or_default()
}); });
// rsx! {
// <>
// {}
// </>
// }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment