fix most warnings

This commit is contained in:
griffi-gh 2024-02-18 17:22:31 +01:00
parent 57900bc287
commit 246b80c0fa
11 changed files with 32 additions and 28 deletions

View file

@ -1,5 +1,5 @@
use std::time::Instant; use std::time::Instant;
use glam::{Vec2, IVec2, UVec2}; use glam::UVec2;
use glium::{backend::glutin::SimpleWindowBuilder, Surface}; use glium::{backend::glutin::SimpleWindowBuilder, Surface};
use winit::{ use winit::{
event::{Event, WindowEvent}, event::{Event, WindowEvent},
@ -20,7 +20,7 @@ fn main() {
kubi_logging::init(); kubi_logging::init();
let event_loop = EventLoopBuilder::new().build().unwrap(); let event_loop = EventLoopBuilder::new().build().unwrap();
let (window, display) = SimpleWindowBuilder::new().build(&event_loop); let (_window, display) = SimpleWindowBuilder::new().build(&event_loop);
let mut hui = UiInstance::new(); let mut hui = UiInstance::new();
let mut backend = GliumUiRenderer::new(&display); let mut backend = GliumUiRenderer::new(&display);

View file

@ -14,8 +14,7 @@ use hui::{
rect::Rect rect::Rect
}, },
interaction::IntoInteractable, interaction::IntoInteractable,
UiSize, UiSize, UiDirection,
UiDirection, IfModified,
}; };
use hui_glium::GliumUiRenderer; use hui_glium::GliumUiRenderer;
@ -23,7 +22,7 @@ fn main() {
kubi_logging::init(); kubi_logging::init();
let event_loop = EventLoopBuilder::new().build().unwrap(); let event_loop = EventLoopBuilder::new().build().unwrap();
let (window, display) = SimpleWindowBuilder::new().build(&event_loop); let (_window, display) = SimpleWindowBuilder::new().build(&event_loop);
let mut hui = UiInstance::new(); let mut hui = UiInstance::new();
let mut backend = GliumUiRenderer::new(&display); let mut backend = GliumUiRenderer::new(&display);

View file

@ -1,14 +1,15 @@
use std::time::Instant; use glam::UVec2;
use glam::{UVec2, vec4};
use glium::{backend::glutin::SimpleWindowBuilder, Surface}; use glium::{backend::glutin::SimpleWindowBuilder, Surface};
use winit::{ use winit::{
event::{Event, WindowEvent}, event::{Event, WindowEvent},
event_loop::{EventLoopBuilder, ControlFlow} event_loop::{EventLoopBuilder, ControlFlow}
}; };
use hui::{ use hui::{
UiInstance, UiSize,
element::{ element::{
container::{Alignment, Container, Sides}, progress_bar::ProgressBar, rect::Rect, text::Text, UiElement container::{Alignment, Container, Sides},
}, interaction::IntoInteractable, IfModified, UiDirection, UiInstance, UiSize text::Text,
}
}; };
use hui_glium::GliumUiRenderer; use hui_glium::GliumUiRenderer;

View file

@ -94,7 +94,7 @@ impl CallSwapper {
} }
pub fn swap(&mut self) { pub fn swap(&mut self) {
self.calls.push(std::mem::replace(&mut self.call, UiDrawCall::default())); self.calls.push(std::mem::take(&mut self.call));
} }
pub fn finish(mut self) -> Vec<UiDrawCall> { pub fn finish(mut self) -> Vec<UiDrawCall> {

View file

@ -1,6 +1,9 @@
use glam::{Vec2, vec2, Vec4}; use glam::{Vec2, vec2, Vec4};
use crate::{ use crate::{
draw::{UiDrawCommand, UiDrawCommands}, element::{MeasureContext, ProcessContext, UiElement}, measure::{Hints, Response}, state::StateRepo, LayoutInfo, UiDirection, UiSize draw::UiDrawCommand,
element::{MeasureContext, ProcessContext, UiElement},
measure::{Hints, Response},
LayoutInfo, UiDirection, UiSize
}; };
#[derive(Clone, Copy, PartialEq, Eq, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Debug)]

View file

@ -1,10 +1,8 @@
use glam::{vec2, Vec4, vec4}; use glam::{vec2, Vec4, vec4};
use crate::{ use crate::{
draw::{UiDrawCommand, UiDrawCommands}, draw::UiDrawCommand,
element::{MeasureContext, ProcessContext, UiElement}, element::{MeasureContext, ProcessContext, UiElement},
measure::Response, measure::Response,
state::StateRepo,
LayoutInfo,
UiSize UiSize
}; };

View file

@ -1,10 +1,9 @@
use glam::{vec2, Vec4}; use glam::{vec2, Vec4};
use crate::{ use crate::{
draw::{UiDrawCommand, UiDrawCommands}, draw::UiDrawCommand,
element::{MeasureContext, ProcessContext, UiElement}, element::{MeasureContext, ProcessContext, UiElement},
measure::Response, measure::Response,
state::StateRepo, UiSize
LayoutInfo, UiSize
}; };
pub struct Rect { pub struct Rect {

View file

@ -1,12 +1,11 @@
use std::borrow::Cow; use std::borrow::Cow;
use glam::{vec2, Vec4}; use glam::{vec2, Vec4};
use crate::{ use crate::{
draw::{UiDrawCommand, UiDrawCommands}, draw::UiDrawCommand,
element::{MeasureContext, ProcessContext, UiElement}, element::{MeasureContext, ProcessContext, UiElement},
measure::Response, measure::Response,
state::StateRepo, text::{FontHandle, BUILTIN_FONT},
text::FontHandle, UiSize
LayoutInfo, UiSize
}; };
pub struct Text { pub struct Text {
@ -23,7 +22,7 @@ impl Default for Text {
text: "".into(), text: "".into(),
size: (UiSize::Auto, UiSize::Auto), size: (UiSize::Auto, UiSize::Auto),
color: Vec4::new(1., 1., 1., 1.), color: Vec4::new(1., 1., 1., 1.),
font: FontHandle(0), font: BUILTIN_FONT,
text_size: 16, text_size: 16,
} }
} }

View file

@ -2,6 +2,8 @@ use hashbrown::{HashMap, HashSet};
use nohash_hasher::BuildNoHashHasher; use nohash_hasher::BuildNoHashHasher;
use std::any::Any; use std::any::Any;
//TODO impl StateRepo functions and automatic cleanup of inactive ids
#[derive(Default)] #[derive(Default)]
pub struct StateRepo { pub struct StateRepo {
state: HashMap<u64, Box<dyn Any>, BuildNoHashHasher<u64>>, state: HashMap<u64, Box<dyn Any>, BuildNoHashHasher<u64>>,

View file

@ -4,7 +4,7 @@ mod font;
mod ftm; mod ftm;
use font::FontManager; use font::FontManager;
pub use font::FontHandle; pub use font::{FontHandle, BUILTIN_FONT};
use fontdue::{Font, FontSettings}; use fontdue::{Font, FontSettings};
use ftm::FontTextureManager; use ftm::FontTextureManager;
pub use ftm::{FontTextureInfo, GlyphCacheEntry}; pub use ftm::{FontTextureInfo, GlyphCacheEntry};
@ -72,7 +72,7 @@ impl<'a> TextMeasure<'a> {
acc.max(glyph.x + glyph.width as f32) acc.max(glyph.x + glyph.width as f32)
}) })
}).unwrap_or(0.), }).unwrap_or(0.),
height: layout.height() as f32, height: layout.height(),
} }
} }
} }

View file

@ -1,14 +1,14 @@
use fontdue::Font; use fontdue::Font;
#[cfg(feature = "builtin_font")]
const BIN_FONT: &[u8] = include_bytes!("../../assets/font/ProggyTiny.ttf");
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct FontHandle(pub(crate) usize); pub struct FontHandle(pub(crate) usize);
#[cfg(feature = "builtin_font")] #[cfg(feature = "builtin_font")]
pub const BUILTIN_FONT: FontHandle = FontHandle(0); pub const BUILTIN_FONT: FontHandle = FontHandle(0);
#[cfg(feature = "builtin_font")]
const BUILTIN_FONT_DATA: &[u8] = include_bytes!("../../assets/font/ProggyTiny.ttf");
pub struct FontManager { pub struct FontManager {
fonts: Vec<Font>, fonts: Vec<Font>,
} }
@ -20,7 +20,10 @@ impl FontManager {
}; };
#[cfg(feature = "builtin_font")] #[cfg(feature = "builtin_font")]
{ {
let font = Font::from_bytes(BIN_FONT, fontdue::FontSettings::default()).unwrap(); let font = Font::from_bytes(
BUILTIN_FONT_DATA,
fontdue::FontSettings::default()
).unwrap();
this.add_font(font); this.add_font(font);
}; };
this this