-
Notifications
You must be signed in to change notification settings - Fork 569
Supplement image widget docs #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
a8e22b5
8b0e298
98897b7
282e438
b3ebd02
7207ead
c5db438
b4f26ea
13982de
7939d36
c05e4c7
dda5f59
929e639
09cefc5
2478f99
0466a12
c6e9a2a
5f9bdd3
7ce624c
8ae701b
40a384b
8233389
9c424d9
d8bb2af
95a37d0
fd7bbf4
a262ba5
ae67f6b
5cb9577
037e3e8
b79a175
7f9b923
978cfd4
21e92a7
f26a354
a202bf8
dff42b3
cd3c132
0ff367b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,52 @@ use crate::{ | |
| PaintCtx, Rect, RenderContext, Size, UpdateCtx, Widget, | ||
| }; | ||
|
|
||
| /// A widget that renders an Image | ||
| /// A widget that renders a bitmap Image. | ||
| /// | ||
| /// Contains data about how to fill given space and interpolate pixels. | ||
covercash2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// Configuration options are provided via the builder pattern. | ||
| /// | ||
| /// Note: interpolation can lead to blurry or pixelated images and so is not | ||
| /// recommended for things like icons. Instead consider using | ||
|
||
| /// [SVG files](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) | ||
| /// and enabling the `svg` feature with `cargo`. | ||
| /// | ||
| /// (See also: | ||
| /// [`ImageData`], | ||
| /// [`FillStrat`], | ||
| /// [`InterpolationMode`] | ||
covercash2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// ) | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// Create an image widget and configure it using builder methods | ||
| /// ``` | ||
| /// use druid::{ | ||
| /// widget::{Image, ImageData, FillStrat}, | ||
| /// piet::InterpolationMode, | ||
| /// }; | ||
| /// | ||
| /// let image_data = ImageData::empty(); | ||
| /// let image_widget = Image::new(image_data) | ||
| /// // set fill strategy | ||
covercash2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// .fill_mode(FillStrat::Fill) | ||
| /// // set interpolation mode | ||
| /// .interpolation_mode(InterpolationMode::NearestNeighbor); | ||
covercash2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// ``` | ||
| /// Create an image widget and configure it using setters | ||
| /// ``` | ||
| /// use druid::{ | ||
| /// widget::{Image, ImageData, FillStrat}, | ||
| /// piet::InterpolationMode, | ||
| /// }; | ||
| /// | ||
| /// let image_data = ImageData::empty(); | ||
| /// let mut image_widget = Image::new(image_data); | ||
| /// // set fill strategy | ||
| /// image_widget.set_fill_mode(FillStrat::FitWidth); | ||
| /// // set interpolation mode | ||
| /// image_widget.set_interpolation_mode(InterpolationMode::NearestNeighbor); | ||
| /// ``` | ||
| pub struct Image { | ||
| image_data: ImageData, | ||
| fill: FillStrat, | ||
|
|
@@ -35,7 +80,10 @@ pub struct Image { | |
| impl Image { | ||
| /// Create an image drawing widget from `ImageData`. | ||
| /// | ||
| /// The Image will scale to fit its box constraints. | ||
| /// By default, the Image will scale to fit its box constraints | ||
| /// ([`FillStrat::Fill`]) | ||
| /// and will be scaled bilinearly | ||
| /// ([`InterpolationMode::Bilinear`]) | ||
|
Comment on lines
+91
to
+93
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two links aren't defined. |
||
| pub fn new(image_data: ImageData) -> Self { | ||
| Image { | ||
| image_data, | ||
|
|
@@ -50,7 +98,7 @@ impl Image { | |
| self | ||
| } | ||
|
|
||
| /// Modify the widget's `FillStrat`. | ||
| /// Modify the widget's [`FillStrat`]. | ||
covercash2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub fn set_fill_mode(&mut self, newfil: FillStrat) { | ||
| self.fill = newfil; | ||
| } | ||
|
|
@@ -61,7 +109,7 @@ impl Image { | |
| self | ||
| } | ||
|
|
||
| /// Modify the widget's `InterpolationMode`. | ||
| /// Modify the widget's [`InterpolationMode`]. | ||
covercash2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub fn set_interpolation_mode(&mut self, interpolation: InterpolationMode) { | ||
| self.interpolation = interpolation; | ||
| } | ||
|
|
@@ -106,7 +154,14 @@ impl<T: Data> Widget<T> for Image { | |
| } | ||
| } | ||
|
|
||
| /// Stored Image data. | ||
| /// Loaded image data. | ||
covercash2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// By default, Druid does not parse image data. | ||
| /// However, [enabling the `image` feature](../index.html#optional-features) | ||
covercash2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// provides several | ||
| /// methods by which you can load image files. | ||
| /// | ||
| /// Contains raw bytes, dimensions, and image format ([`druid::piet::ImageFormat`]). | ||
covercash2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #[derive(Clone)] | ||
| pub struct ImageData { | ||
| pixels: Vec<u8>, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.