From 803240a83ed8b7b171e54aba8bccdb2f3edf232f Mon Sep 17 00:00:00 2001 From: griffi-gh <prasol258@gmail.com> Date: Mon, 31 Mar 2025 14:21:47 +0200 Subject: [PATCH] use image crate in example 7 --- hui-examples/Cargo.toml | 1 + hui-examples/examples/ui_test_7_9patch.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/hui-examples/Cargo.toml b/hui-examples/Cargo.toml index 2fdead1..9d58196 100644 --- a/hui-examples/Cargo.toml +++ b/hui-examples/Cargo.toml @@ -9,6 +9,7 @@ publish = false hui = { path = "../hui" } hui-painter = { path = "../hui-painter" } hui-glium = { path = "../hui-glium" } +hui-euc = { path = "../hui-euc" } hui-winit = { path = "../hui-winit" } kubi-logging = { git = "https://github.com/griffi-gh/kubi", rev = "1e051c47b64c967305e4bbbd464ef5da2cc56bbb" } glium = "0.36" diff --git a/hui-examples/examples/ui_test_7_9patch.rs b/hui-examples/examples/ui_test_7_9patch.rs index 1d37c92..ddbbb9f 100644 --- a/hui-examples/examples/ui_test_7_9patch.rs +++ b/hui-examples/examples/ui_test_7_9patch.rs @@ -14,6 +14,7 @@ use hui::{ signal::Signal, size, }; +use hui_painter::texture::SourceTextureFormat; #[path = "../boilerplate.rs"] #[macro_use] @@ -24,11 +25,17 @@ struct SetValue(f32); ui_main!( "hUI: 9-Patch demo", - init: |_ui| { + init: |ui| { ( NinePatchAsset { // FIXME add image loader here - image: todo!("FIXME add image loader here"), //ui.add_image_file_path("./hui-examples/assets/ninepatch_button.png").unwrap(), + image: { + let data = std::fs::read("./hui-examples/assets/ninepatch_button.png").unwrap(); + let image = image::load_from_memory(&data[..]).unwrap(); + let width = image.width() as usize; + let data = image.as_rgba8().unwrap().as_raw(); + ui.textures_mut().add_with_data(SourceTextureFormat::RGBA8, data, width) + }, size: (190, 49), scalable_region: Rect { position: vec2(8. / 190., 8. / 49.),