From 68f4f2859c5cac3e84b013dc2451c81b2455bb7b Mon Sep 17 00:00:00 2001 From: griffi-gh <prasol258@gmail.com> Date: Tue, 11 Mar 2025 14:58:19 +0100 Subject: [PATCH] fix some warnings --- hui-examples/examples/mom_downloader.rs | 4 +- hui-examples/examples/text_weird.rs | 2 +- hui-examples/examples/ui_test_2_loading.rs | 4 +- hui-examples/examples/ui_test_3_transform.rs | 4 +- hui-examples/examples/ui_test_5_input.rs | 5 +- hui-examples/examples/ui_test_6_slider.rs | 2 +- hui-examples/examples/ui_test_7_9patch.rs | 5 +- hui-examples/examples/vscode_layout.rs | 10 ++- hui-glium/src/lib.rs | 2 +- hui-painter/src/paint/command/text.rs | 2 +- hui-shared/src/rect/corners.rs | 2 - hui/src/element/builtin/text.rs | 8 +-- hui/src/frame/impls.rs | 2 +- hui/src/instance.rs | 75 +++++++++----------- 14 files changed, 62 insertions(+), 65 deletions(-) diff --git a/hui-examples/examples/mom_downloader.rs b/hui-examples/examples/mom_downloader.rs index cbbe307..7ef489e 100644 --- a/hui-examples/examples/mom_downloader.rs +++ b/hui-examples/examples/mom_downloader.rs @@ -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| { diff --git a/hui-examples/examples/text_weird.rs b/hui-examples/examples/text_weird.rs index 5d6ec2f..872a45f 100644 --- a/hui-examples/examples/text_weird.rs +++ b/hui-examples/examples/text_weird.rs @@ -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| { diff --git a/hui-examples/examples/ui_test_2_loading.rs b/hui-examples/examples/ui_test_2_loading.rs index aa0e6c9..5d0764d 100644 --- a/hui-examples/examples/ui_test_2_loading.rs +++ b/hui-examples/examples/ui_test_2_loading.rs @@ -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,)| { diff --git a/hui-examples/examples/ui_test_3_transform.rs b/hui-examples/examples/ui_test_3_transform.rs index aa20bc6..bc42caf 100644 --- a/hui-examples/examples/ui_test_3_transform.rs +++ b/hui-examples/examples/ui_test_3_transform.rs @@ -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,)| { diff --git a/hui-examples/examples/ui_test_5_input.rs b/hui-examples/examples/ui_test_5_input.rs index de8cc14..4846c32 100644 --- a/hui-examples/examples/ui_test_5_input.rs +++ b/hui-examples/examples/ui_test_5_input.rs @@ -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)| { diff --git a/hui-examples/examples/ui_test_6_slider.rs b/hui-examples/examples/ui_test_6_slider.rs index 283cb33..b3d44e4 100644 --- a/hui-examples/examples/ui_test_6_slider.rs +++ b/hui-examples/examples/ui_test_6_slider.rs @@ -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)| { diff --git a/hui-examples/examples/ui_test_7_9patch.rs b/hui-examples/examples/ui_test_7_9patch.rs index 9ba9578..1d37c92 100644 --- a/hui-examples/examples/ui_test_7_9patch.rs +++ b/hui-examples/examples/ui_test_7_9patch.rs @@ -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.), diff --git a/hui-examples/examples/vscode_layout.rs b/hui-examples/examples/vscode_layout.rs index 8e5f93a..3f1d7fc 100644 --- a/hui-examples/examples/vscode_layout.rs +++ b/hui-examples/examples/vscode_layout.rs @@ -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| { diff --git a/hui-glium/src/lib.rs b/hui-glium/src/lib.rs index 323889d..2f0b53b 100644 --- a/hui-glium/src/lib.rs +++ b/hui-glium/src/lib.rs @@ -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(), diff --git a/hui-painter/src/paint/command/text.rs b/hui-painter/src/paint/command/text.rs index bd20bfc..5ca00c8 100644 --- a/hui-painter/src/paint/command/text.rs +++ b/hui-painter/src/paint/command/text.rs @@ -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::{ diff --git a/hui-shared/src/rect/corners.rs b/hui-shared/src/rect/corners.rs index 0ac8f2b..c5e1f7a 100644 --- a/hui-shared/src/rect/corners.rs +++ b/hui-shared/src/rect/corners.rs @@ -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> { diff --git a/hui/src/element/builtin/text.rs b/hui/src/element/builtin/text.rs index 8c5e2a0..4154dd8 100644 --- a/hui/src/element/builtin/text.rs +++ b/hui/src/element/builtin/text.rs @@ -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, } } } diff --git a/hui/src/frame/impls.rs b/hui/src/frame/impls.rs index c38a78b..70a85d2 100644 --- a/hui/src/frame/impls.rs +++ b/hui/src/frame/impls.rs @@ -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() diff --git a/hui/src/instance.rs b/hui/src/instance.rs index 6a9d2fa..f79f87d 100644 --- a/hui/src/instance.rs +++ b/hui/src/instance.rs @@ -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(); }