1
1
Fork 0
mirror of https://github.com/griffi-gh/hUI.git synced 2025-04-02 14:06:29 -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!{ ui_main!{
"Mom downloader 2000", "Mom downloader 2000",
init: |ui| { init: |ui| {
let font_handle = ui.add_font(include_bytes!("../assets/roboto/Roboto-Regular.ttf")); let font_handle = ui.fonts_mut().add(include_bytes!("../assets/roboto/Roboto-Regular.ttf"));
ui.push_font_stack(font_handle); ui.font_stack_push(font_handle);
Instant::now() Instant::now()
}, },
run: |ui, max_size, instant| { run: |ui, max_size, instant| {

View file

@ -30,7 +30,7 @@ fn main() {
let mut hui = UiInstance::new(); let mut hui = UiInstance::new();
let mut backend = GliumUiRenderer::new(&display); 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(); let instant = Instant::now();
event_loop.run(|event, window_target| { event_loop.run(|event, window_target| {

View file

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

View file

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

View file

@ -28,7 +28,10 @@ const IMAGE_DATA: &[u8] = include_bytes!("../assets/icons/visual-studio-code-ico
ui_main!( ui_main!(
"hUI: Internal input test", "hUI: Internal input test",
init: |ui| { 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) (0, image)
}, },
run: |ui, size, &mut (ref mut counter, 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!( ui_main!(
"hUI: Internal input test", "hUI: Internal input test",
init: |ui| { 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) (0, image)
}, },
run: |ui, size, &mut (ref mut counter, image)| { run: |ui, size, &mut (ref mut counter, image)| {

View file

@ -24,10 +24,11 @@ struct SetValue(f32);
ui_main!( ui_main!(
"hUI: 9-Patch demo", "hUI: 9-Patch demo",
init: |ui| { init: |_ui| {
( (
NinePatchAsset { 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), size: (190, 49),
scalable_region: Rect { scalable_region: Rect {
position: vec2(8. / 190., 8. / 49.), position: vec2(8. / 190., 8. / 49.),

View file

@ -24,10 +24,14 @@ struct Stuff {
ui_main!( ui_main!(
"hUI: vscode demo", "hUI: vscode demo",
init: |ui| { init: |ui| {
let handle = ui.add_font(include_bytes!("../assets/fira/FiraSans-Light.ttf")); let handle = ui.fonts_mut().add(include_bytes!("../assets/fira/FiraSans-Light.ttf"));
ui.push_font_stack(handle); ui.font_stack_push(handle);
Stuff { 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| { run: |ui, size, stuff| {

View file

@ -57,7 +57,7 @@ struct BufferPair {
} }
impl 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)..."); log::debug!("init ui buffers (empty)...");
Self { Self {
vertex_buffer: VertexBuffer::empty_dynamic(facade, 1024).unwrap(), vertex_buffer: VertexBuffer::empty_dynamic(facade, 1024).unwrap(),

View file

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

View file

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

View file

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

View file

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

View file

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