1
1
Fork 0
mirror of https://github.com/griffi-gh/hUI.git synced 2025-03-31 21:16:28 -05:00

fix some warnings

This commit is contained in:
griffi-gh 2025-03-11 14:58:19 +01:00
parent 7b41ac24b6
commit 68f4f2859c
14 changed files with 62 additions and 65 deletions

View file

@ -19,8 +19,8 @@ mod boilerplate;
ui_main!{
"Mom downloader 2000",
init: |ui| {
let font_handle = ui.add_font(include_bytes!("../assets/roboto/Roboto-Regular.ttf"));
ui.push_font_stack(font_handle);
let font_handle = ui.fonts_mut().add(include_bytes!("../assets/roboto/Roboto-Regular.ttf"));
ui.font_stack_push(font_handle);
Instant::now()
},
run: |ui, max_size, instant| {

View file

@ -30,7 +30,7 @@ fn main() {
let mut hui = UiInstance::new();
let mut backend = GliumUiRenderer::new(&display);
let font_handle = hui.add_font(include_bytes!("../assets/roboto/Roboto-Regular.ttf"));
let font_handle = hui.fonts_mut().add(include_bytes!("../assets/roboto/Roboto-Regular.ttf"));
let instant = Instant::now();
event_loop.run(|event, window_target| {

View file

@ -20,8 +20,8 @@ mod boilerplate;
ui_main!(
"hUI: Loading screen demo",
init: |ui| {
let font = ui.add_font(include_bytes!("../assets/blink/Blink-ynYZ.otf"));
ui.push_font_stack(font);
let font = ui.fonts_mut().add(include_bytes!("../assets/blink/Blink-ynYZ.otf"));
ui.font_stack_push(font);
(std::time::Instant::now(),)
},
run: |ui, size, (instant,)| {

View file

@ -22,8 +22,8 @@ mod boilerplate;
ui_main!(
"hUI: Transform API demo",
init: |ui| {
let font = ui.add_font(include_bytes!("../assets/blink/Blink-ynYZ.otf"));
ui.push_font_stack(font);
let font = ui.fonts_mut().add(include_bytes!("../assets/blink/Blink-ynYZ.otf"));
ui.font_stack_push(font);
(std::time::Instant::now(),)
},
run: |ui, size, (instant,)| {

View file

@ -28,7 +28,10 @@ const IMAGE_DATA: &[u8] = include_bytes!("../assets/icons/visual-studio-code-ico
ui_main!(
"hUI: Internal input test",
init: |ui| {
let image = ui.add_image(SourceTextureFormat::RGBA8, IMAGE_DATA, 32);
let image = ui.textures_mut().add_with_data(
SourceTextureFormat::RGBA8,
IMAGE_DATA, 32,
);
(0, image)
},
run: |ui, size, &mut (ref mut counter, image)| {

View file

@ -27,7 +27,7 @@ const IMAGE_DATA: &[u8] = include_bytes!("../assets/icons/visual-studio-code-ico
ui_main!(
"hUI: Internal input test",
init: |ui| {
let image = ui.add_image(SourceTextureFormat::RGBA8, IMAGE_DATA, 32);
let image = ui.textures_mut().add_with_data(SourceTextureFormat::RGBA8, IMAGE_DATA, 32);
(0, image)
},
run: |ui, size, &mut (ref mut counter, image)| {

View file

@ -24,10 +24,11 @@ struct SetValue(f32);
ui_main!(
"hUI: 9-Patch demo",
init: |ui| {
init: |_ui| {
(
NinePatchAsset {
image: todo!(), //ui.add_image_file_path("./hui-examples/assets/ninepatch_button.png").unwrap(),
// FIXME add image loader here
image: todo!("FIXME add image loader here"), //ui.add_image_file_path("./hui-examples/assets/ninepatch_button.png").unwrap(),
size: (190, 49),
scalable_region: Rect {
position: vec2(8. / 190., 8. / 49.),

View file

@ -24,10 +24,14 @@ struct Stuff {
ui_main!(
"hUI: vscode demo",
init: |ui| {
let handle = ui.add_font(include_bytes!("../assets/fira/FiraSans-Light.ttf"));
ui.push_font_stack(handle);
let handle = ui.fonts_mut().add(include_bytes!("../assets/fira/FiraSans-Light.ttf"));
ui.font_stack_push(handle);
Stuff {
vscode_icon: ui.add_image(SourceTextureFormat::RGBA8, include_bytes!("../assets/icons/visual-studio-code-icon_32x32.rgba"), 32),
vscode_icon: ui.textures_mut().add_with_data(
SourceTextureFormat::RGBA8,
include_bytes!("../assets/icons/visual-studio-code-icon_32x32.rgba"),
32
),
}
},
run: |ui, size, stuff| {

View file

@ -57,7 +57,7 @@ struct BufferPair {
}
impl BufferPair {
pub fn new<F: Facade>(facade: &F) -> Self {
pub fn new_empty<F: Facade>(facade: &F) -> Self {
log::debug!("init ui buffers (empty)...");
Self {
vertex_buffer: VertexBuffer::empty_dynamic(facade, 1024).unwrap(),

View file

@ -1,5 +1,5 @@
use std::{borrow::Cow, hash::{Hash, Hasher}};
use fontdue::layout::{CoordinateSystem, GlyphRasterConfig, Layout};
use fontdue::layout::{CoordinateSystem, Layout};
use glam::{vec2, Vec4};
use hui_shared::rect::Rect;
use crate::{

View file

@ -1,5 +1,3 @@
use std::mem::ManuallyDrop;
/// Represents 4 corners of a rectangular shape.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub struct Corners<T> {

View file

@ -64,10 +64,6 @@ impl Text {
..Default::default()
}
}
fn font(&self, f: FontHandle) -> FontHandle {
self.font.unwrap_or(f)
}
}
impl Text {
@ -76,8 +72,8 @@ impl Text {
text: TextChunk {
text: self.text.clone(),
font: self.font.unwrap_or(current_font),
size: self.text_size as f32,
color: self.color.into(),
size: self.text_size,
color: self.color,
}
}
}

View file

@ -11,7 +11,7 @@ impl Frame for TextureHandle {
draw.add(PaintTransform {
transform: Affine2::from_translation(rect.position),
child: PaintRectangle {
size: rect.size.into(),
size: rect.size,
color: color::WHITE.into(),
texture: Some(*self),
..Default::default()

View file

@ -26,9 +26,6 @@ pub struct UiInstance {
input: UiInputState,
signal: SignalStore,
font_stack: FontStack,
/// Set to true if present has been called since the last begin_frame
frame_presented: bool,
}
impl UiInstance {
@ -45,7 +42,6 @@ impl UiInstance {
events: EventQueue::new(),
input: UiInputState::new(),
signal: SignalStore::new(),
frame_presented: false,
}
}
@ -110,52 +106,51 @@ impl UiInstance {
//TODO better error handling
/// Add an image from a file to the texture atlas\
/// (experimental, may be removed in the future)
///
/// Requires the `image` feature
///
/// # Panics:
/// - If the file exists but contains invalid image data\
/// (this will change to a soft error in the future)
///
/// Deprecated.
#[cfg(feature = "image")]
#[deprecated]
pub fn add_image_file_path(&mut self, path: impl AsRef<std::path::Path>) -> Result<TextureHandle, std::io::Error> {
use std::io::{Read, Seek};
// /// Add an image from a file to the texture atlas\
// /// (experimental, may be removed in the future)
// ///
// /// Requires the `image` feature
// ///
// /// # Panics:
// /// - If the file exists but contains invalid image data\
// /// (this will change to a soft error in the future)
// ///
// /// Deprecated.
// #[deprecated]
// pub fn add_image_file_path(&mut self, path: impl AsRef<std::path::Path>) -> Result<TextureHandle, std::io::Error> {
// use std::io::{Read, Seek};
// Open the file (and wrap it in a bufreader)
let mut file = std::io::BufReader::new(std::fs::File::open(path)?);
// // Open the file (and wrap it in a bufreader)
// let mut file = std::io::BufReader::new(std::fs::File::open(path)?);
//Guess the image format from the magic bytes
//Read like 64 bytes, which should be enough for magic byte detection
//well this would fail if the image is somehow smaller than 64 bytes, but who the fvck cares...
let mut magic = [0; 64];
file.read_exact(&mut magic)?;
let format = image::guess_format(&magic).expect("Invalid image data (FORMAT)");
file.seek(std::io::SeekFrom::Start(0))?;
// //Guess the image format from the magic bytes
// //Read like 64 bytes, which should be enough for magic byte detection
// //well this would fail if the image is somehow smaller than 64 bytes, but who the fvck cares...
// let mut magic = [0; 64];
// file.read_exact(&mut magic)?;
// let format = image::guess_format(&magic).expect("Invalid image data (FORMAT)");
// file.seek(std::io::SeekFrom::Start(0))?;
//Parse the image and read the raw uncompressed rgba data
let image = image::load(file, format).expect("Invalid image data");
let image_rgba = image.as_rgba8().unwrap();
// //Parse the image and read the raw uncompressed rgba data
// let image = image::load(file, format).expect("Invalid image data");
// let image_rgba = image.as_rgba8().unwrap();
//Add the image to the atlas
let handle = self.add_image(
SourceTextureFormat::RGBA8,
image_rgba,
image.width() as usize
);
// //Add the image to the atlas
// let handle = self.add_image(
// SourceTextureFormat::RGBA8,
// image_rgba,
// image.width() as usize
// );
Ok(handle)
}
// Ok(handle)
// }
/// Push a font to the font stack\
/// The font will be used for all text rendering until it is popped
///
/// This function is useful for replacing the default font, use sparingly\
/// (This library attempts to be stateless, however passing the font to every text element is not very practical)
pub fn push_font_stack(&mut self, font: FontHandle) {
pub fn font_stack_push(&mut self, font: FontHandle) {
self.font_stack.push(font);
}
@ -163,7 +158,7 @@ impl UiInstance {
///
/// ## Panics:
/// If the font stack is empty
pub fn pop_font_stack(&mut self) {
pub fn font_stack_pop(&mut self) {
self.font_stack.pop();
}