1
1
Fork 0
mirror of https://github.com/griffi-gh/hUI.git synced 2025-04-04 06:56:29 -05:00

fix remaining examples

This commit is contained in:
griffi-gh 2025-03-11 11:42:35 +01:00
parent 287b6f4144
commit 5aaa7bb282
7 changed files with 29 additions and 29 deletions

View file

@ -137,7 +137,7 @@ fn main() {
hui.end_frame(); hui.end_frame();
backend.update(&hui); backend.update(&hui.backend_data());
backend.draw(&mut frame, resolution); backend.draw(&mut frame, resolution);
frame.finish().unwrap(); frame.finish().unwrap();

View file

@ -43,7 +43,7 @@ ui_main!{
if instant.elapsed().as_secs_f32() < 5. { if instant.elapsed().as_secs_f32() < 5. {
Text::default() Text::default()
.with_text("Downloading your mom...") .with_text("Downloading your mom...")
.with_text_size(24) .with_text_size(24.)
.add_child(ui); .add_child(ui);
ProgressBar::default() ProgressBar::default()
.with_value(mom_ratio) .with_value(mom_ratio)
@ -63,7 +63,7 @@ ui_main!{
.with_children(|ui| { .with_children(|ui| {
Text::default() Text::default()
.with_text(format!("{:.2}% ({:.1} GB)", mom_ratio * 100., mom_ratio * 10000.)) .with_text(format!("{:.2}% ({:.1} GB)", mom_ratio * 100., mom_ratio * 10000.))
.with_text_size(16) .with_text_size(16.)
.add_child(ui); .add_child(ui);
}) })
.add_child(ui); .add_child(ui);
@ -71,11 +71,11 @@ ui_main!{
Text::default() Text::default()
.with_text("Error 413: Request Entity Too Large") .with_text("Error 413: Request Entity Too Large")
.with_color((1., 0.125, 0.125, 1.)) .with_color((1., 0.125, 0.125, 1.))
.with_text_size(20) .with_text_size(20.)
.add_child(ui); .add_child(ui);
Text::default() Text::default()
.with_text(format!("Exiting in {}...", 10 - instant.elapsed().as_secs())) .with_text(format!("Exiting in {}...", 10 - instant.elapsed().as_secs()))
.with_text_size(16) .with_text_size(16.)
.add_child(ui); .add_child(ui);
} else { } else {
std::process::exit(0); std::process::exit(0);

View file

@ -57,14 +57,14 @@ fn main() {
})); }));
elem.push(Box::new(Text { elem.push(Box::new(Text {
text: "THIS LINE SHOULD BE SHARP!".into(), text: "THIS LINE SHOULD BE SHARP!".into(),
text_size: 32, text_size: 32.,
..Default::default() ..Default::default()
})); }));
elem.push(Box::new(Text { elem.push(Box::new(Text {
text: "All lines except 3 and 6 below will be blurry:".into(), text: "All lines except 3 and 6 below will be blurry:".into(),
..Default::default() ..Default::default()
})); }));
for size in [9, 12, 16, 18, 24, 32] { for size in [9., 12., 16., 18., 24., 32.] {
elem.push(Box::new(Text { elem.push(Box::new(Text {
text: "Testing default font, Proggy Tiny".into(), text: "Testing default font, Proggy Tiny".into(),
text_size: size, text_size: size,
@ -82,7 +82,7 @@ fn main() {
elem.push(Box::new(Text { elem.push(Box::new(Text {
text: "Hello, world!\nżółty liść. życie nie ma sensu i wszyscy zginemy;\nтест кирилиці їїїїїїїїїїї\njapanese text: テスト".into(), text: "Hello, world!\nżółty liść. życie nie ma sensu i wszyscy zginemy;\nтест кирилиці їїїїїїїїїїї\njapanese text: テスト".into(),
font: Some(font_handle), font: Some(font_handle),
text_size: 32, text_size: 32.,
..Default::default() ..Default::default()
})); }));
if instant.elapsed().as_secs() & 1 != 0 { if instant.elapsed().as_secs() & 1 != 0 {
@ -97,7 +97,7 @@ fn main() {
elem.push(Box::new(Spacer(100.))); elem.push(Box::new(Spacer(100.)));
elem.push(Box::new(Text { elem.push(Box::new(Text {
text: "FLAG SHOULD NOT OVERLAP WITH TEXT".into(), text: "FLAG SHOULD NOT OVERLAP WITH TEXT".into(),
text_size: 64, text_size: 64.,
color: vec4(1., 0., 1., 1.), color: vec4(1., 0., 1., 1.),
..Default::default() ..Default::default()
})); }));
@ -108,7 +108,7 @@ fn main() {
hui.end_frame(); hui.end_frame();
backend.update(&hui); backend.update(&hui.backend_data());
backend.draw(&mut frame, resolution); backend.draw(&mut frame, resolution);
frame.finish().unwrap(); frame.finish().unwrap();

View file

@ -21,7 +21,7 @@ ui_main!(|ui, size, _| {
.with_children(|ui| { .with_children(|ui| {
Text::default() Text::default()
.with_text("Hello, world") .with_text("Hello, world")
.with_text_size(100) .with_text_size(100.)
.with_color(color::BLACK) .with_color(color::BLACK)
.add_child(ui); .add_child(ui);
Container::default() Container::default()
@ -33,7 +33,7 @@ ui_main!(|ui, size, _| {
.with_children(|ui| { .with_children(|ui| {
Text::default() Text::default()
.with_text("Lorem ipsum dolor sit amet, consectetur adipiscing elit.") .with_text("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
.with_text_size(24) .with_text_size(24.)
.add_child(ui); .add_child(ui);
}) })
.add_child(ui); .add_child(ui);

View file

@ -1,7 +1,6 @@
use hui::{ use hui::{
color, size, color, size,
signal::Signal, signal::Signal,
draw::TextureFormat,
layout::{Alignment, Direction}, layout::{Alignment, Direction},
element::{ element::{
container::Container, container::Container,
@ -12,6 +11,7 @@ use hui::{
UiElementExt, UiElementExt,
}, },
}; };
use hui_painter::texture::SourceTextureFormat;
#[derive(Signal)] #[derive(Signal)]
enum CounterSignal { enum CounterSignal {
@ -28,7 +28,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(TextureFormat::Rgba, IMAGE_DATA, 32); let image = ui.add_image(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)| {
@ -42,7 +42,7 @@ ui_main!(
.with_wrap(true) .with_wrap(true)
.with_children(|ui| { .with_children(|ui| {
Text::new("Number of images:") Text::new("Number of images:")
.with_text_size(24) .with_text_size(24.)
.add_child(ui); .add_child(ui);
Break.add_child(ui); Break.add_child(ui);
Container::default() Container::default()
@ -50,7 +50,7 @@ ui_main!(
.with_background(color::ORANGE) .with_background(color::ORANGE)
.with_children(|ui| { .with_children(|ui| {
Text::new("-") Text::new("-")
.with_text_size(32) .with_text_size(32.)
.add_child(ui); .add_child(ui);
}) })
.on_click(|| CounterSignal::Decrement) .on_click(|| CounterSignal::Decrement)
@ -60,7 +60,7 @@ ui_main!(
.with_align(Alignment::Center) .with_align(Alignment::Center)
.with_children(|ui| { .with_children(|ui| {
Text::new(counter.to_string()) Text::new(counter.to_string())
.with_text_size(64) .with_text_size(64.)
.add_child(ui); .add_child(ui);
}) })
.add_child(ui); .add_child(ui);
@ -69,7 +69,7 @@ ui_main!(
.with_background(color::ORANGE) .with_background(color::ORANGE)
.with_children(|ui| { .with_children(|ui| {
Text::new("+") Text::new("+")
.with_text_size(32) .with_text_size(32.)
.add_child(ui); .add_child(ui);
}) })
.on_click(|| CounterSignal::Increment) .on_click(|| CounterSignal::Increment)

View file

@ -27,7 +27,7 @@ ui_main!(
init: |ui| { init: |ui| {
( (
NinePatchAsset { NinePatchAsset {
image: ui.add_image_file_path("./hui-examples/assets/ninepatch_button.png").unwrap(), image: todo!(), //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.),
@ -50,7 +50,7 @@ ui_main!(
.with_padding(10.) .with_padding(10.)
.with_children(|ui| { .with_children(|ui| {
Text::new("Hello, world!\nThis is a 9-patch frame used as a background \nfor Container with a Text element.\nIt's scalable and looks great!\nBelow, there are two FillRects with the same \n9-patch frame used as the background.") Text::new("Hello, world!\nThis is a 9-patch frame used as a background \nfor Container with a Text element.\nIt's scalable and looks great!\nBelow, there are two FillRects with the same \n9-patch frame used as the background.")
.with_text_size(16) .with_text_size(16.)
.add_child(ui); .add_child(ui);
}) })
.add_child(ui); .add_child(ui);
@ -60,7 +60,7 @@ ui_main!(
.add_child(ui); .add_child(ui);
Text::new("This one's fancy:") Text::new("This one's fancy:")
.with_color(color::BLACK) .with_color(color::BLACK)
.with_text_size(32) .with_text_size(32.)
.add_child(ui); .add_child(ui);
FrameView::default() FrameView::default()
.with_size(size!(700, 50)) .with_size(size!(700, 50))
@ -73,7 +73,7 @@ ui_main!(
.add_child(ui); .add_child(ui);
Text::new("Slider customized with `NinePatchFrame`s:") Text::new("Slider customized with `NinePatchFrame`s:")
.with_color(color::BLACK) .with_color(color::BLACK)
.with_text_size(32) .with_text_size(32.)
.add_child(ui); .add_child(ui);
Slider::new(*value) Slider::new(*value)
.with_size(size!(50%, 30)) .with_size(size!(50%, 30))

View file

@ -2,7 +2,6 @@
use hui::{ use hui::{
color, size, color, size,
draw::{ImageHandle, TextureFormat},
layout::{Alignment, Direction}, layout::{Alignment, Direction},
element::{ element::{
container::Container, container::Container,
@ -12,13 +11,14 @@ use hui::{
UiElementExt UiElementExt
}, },
}; };
use hui_painter::texture::{SourceTextureFormat, TextureHandle};
#[path = "../boilerplate.rs"] #[path = "../boilerplate.rs"]
#[macro_use] #[macro_use]
mod boilerplate; mod boilerplate;
struct Stuff { struct Stuff {
vscode_icon: ImageHandle, vscode_icon: TextureHandle,
} }
ui_main!( ui_main!(
@ -27,7 +27,7 @@ ui_main!(
let handle = ui.add_font(include_bytes!("../assets/fira/FiraSans-Light.ttf")); let handle = ui.add_font(include_bytes!("../assets/fira/FiraSans-Light.ttf"));
ui.push_font(handle); ui.push_font(handle);
Stuff { Stuff {
vscode_icon: ui.add_image(TextureFormat::Rgba, include_bytes!("../assets/icons/visual-studio-code-icon_32x32.rgba"), 32), vscode_icon: ui.add_image(SourceTextureFormat::RGBA8, include_bytes!("../assets/icons/visual-studio-code-icon_32x32.rgba"), 32),
} }
}, },
run: |ui, size, stuff| { run: |ui, size, stuff| {
@ -48,7 +48,7 @@ ui_main!(
.add_child(ui); .add_child(ui);
for item in ["File", "Edit", "Selection", "View", "Go", "Run", "Terminal", "Help"] { for item in ["File", "Edit", "Selection", "View", "Go", "Run", "Terminal", "Help"] {
Text::new(item) Text::new(item)
.with_text_size(15) .with_text_size(15.)
.add_child(ui); .add_child(ui);
} }
Container::default() Container::default()
@ -56,7 +56,7 @@ ui_main!(
.with_align((Alignment::End, Alignment::Center)) .with_align((Alignment::End, Alignment::Center))
.with_children(|ui| { .with_children(|ui| {
Text::new("- ×") Text::new("- ×")
.with_text_size(32) .with_text_size(32.)
.add_child(ui); .add_child(ui);
}) })
.add_child(ui); .add_child(ui);
@ -111,12 +111,12 @@ ui_main!(
.with_padding((10., 2.)) .with_padding((10., 2.))
.with_children(|ui| { .with_children(|ui| {
Text::new("><") Text::new("><")
.with_text_size(13) .with_text_size(13.)
.add_child(ui); .add_child(ui);
}) })
.add_child(ui); .add_child(ui);
Text::new("master") Text::new("master")
.with_text_size(15) .with_text_size(15.)
.add_child(ui); .add_child(ui);
}) })
.add_child(ui); .add_child(ui);