From 1429051cbb5fcb5f6dd7da7a6b9f5e3ebeb856ee Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Tue, 8 Oct 2024 10:57:43 +0200 Subject: [PATCH 1/2] Add documentation about image widget --- guide/src/widgets/controls/image.md | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/guide/src/widgets/controls/image.md b/guide/src/widgets/controls/image.md index 439ad4a..c195c02 100644 --- a/guide/src/widgets/controls/image.md +++ b/guide/src/widgets/controls/image.md @@ -3,4 +3,54 @@ The [`Image`][image] widget displays an image/texture with configurable scaling options. +## ImageCornerRadius + +Use [`ImageCornerRadius`][ImageCornerRadius] component to set the corner/border radius of an image. `CornerRadius` is not used. + +```rs +image + .with_dynamic(&ImageCornerRadius, CornerRadius) // CornerRadius is a Dynamic(Lp) here + .with(&ImageCornerRadius, Lp::points(6)) // or, a static corner radius +``` + +## Dynamic textures + +Use a [`Dynamic`][Dynamic]`(`[`AnyTexture`][AnyTexture]`)`. + +You can default to a empty texture like so: + +```rs +AnyTexture::Lazy( + LazyTexture::from_image( + image::DynamicImage::ImageRgba8( + image::ImageBuffer::new(1, 1) + ), + cushy::kludgine::wgpu::FilterMode::Linear + ) +) +``` + +To load an image from bytes, use the [`image`][image-crate] crate and then pass it to LazyTexture: + +```rs +let image = image::load_from_memory(&bytes).unwrap(); +let texture = LazyTexture::from_image( + image, + cushy::kludgine::wgpu::FilterMode::Linear +); +let texture = AnyTexture::Lazy(texture); +dynamic_texture.set(texture); +``` + +## FilterMode + +[`FilterMode`][FilterMode] enum specifies the sampler to be used for when an image is scaled. +Linear smooths the version, making it blurry at the extremes but with less grain. +Nearest makes the result more pixelated with hard edges. + [image]: <{{ docs }}/widgets/image/struct.Image.html> +[image-crate]: +[ImageCornerRadius]: <{{ docs }}/widgets/image/struct.ImageCornerRadius.html> +[FilterMode]: +[Dynamic]: +[AnyTexture]: From bea18f97ae7cf4c24a84163e7c4983e1d70c23b3 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Tue, 8 Oct 2024 11:00:58 +0200 Subject: [PATCH 2/2] Add example for the Image widget itself --- guide/src/widgets/controls/image.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/guide/src/widgets/controls/image.md b/guide/src/widgets/controls/image.md index c195c02..ae9496b 100644 --- a/guide/src/widgets/controls/image.md +++ b/guide/src/widgets/controls/image.md @@ -20,14 +20,17 @@ Use a [`Dynamic`][Dynamic]`(`[`AnyTexture`][AnyTexture]`)`. You can default to a empty texture like so: ```rs -AnyTexture::Lazy( - LazyTexture::from_image( - image::DynamicImage::ImageRgba8( - image::ImageBuffer::new(1, 1) - ), - cushy::kludgine::wgpu::FilterMode::Linear +let dynamic_texture = Dynamic::new( + AnyTexture::Lazy( + LazyTexture::from_image( + image::DynamicImage::ImageRgba8( + image::ImageBuffer::new(1, 1) + ), + cushy::kludgine::wgpu::FilterMode::Linear + ) ) -) +); +let widget = Image::new(dynamic_texture); // Creates image widget with an empty texture, that can later be changed ``` To load an image from bytes, use the [`image`][image-crate] crate and then pass it to LazyTexture: