-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
a8e22b5
add example to `Image` widget
covercash2 8b0e298
export `Image` and `ImageData`
covercash2 98897b7
Merge branch 'master' of https://github.com/xi-editor/druid into imag…
covercash2 282e438
add not about "image" feature
covercash2 b3ebd02
minor doc edits
covercash2 7207ead
Merge branch 'master' of https://github.com/xi-editor/druid into imag…
covercash2 c5db438
remove image feature reminder
covercash2 b4f26ea
minor doc edits
covercash2 13982de
add example
covercash2 7939d36
added note about image feature
covercash2 c05e4c7
update changelog
covercash2 dda5f59
rustfmt
covercash2 929e639
fix typo
covercash2 09cefc5
simplify changelog entry
covercash2 2478f99
fix links
covercash2 0466a12
clarify note about interpolation
covercash2 c6e9a2a
minor doc edits
covercash2 5f9bdd3
clarify note about interpolation
covercash2 7ce624c
added link to internal docs
covercash2 8ae701b
add example to `Image` widget
covercash2 40a384b
add not about "image" feature
covercash2 8233389
minor doc edits
covercash2 9c424d9
remove image feature reminder
covercash2 d8bb2af
minor doc edits
covercash2 95a37d0
add example
covercash2 fd7bbf4
added note about image feature
covercash2 a262ba5
update changelog
covercash2 ae67f6b
rustfmt
covercash2 5cb9577
fix typo
covercash2 037e3e8
simplify changelog entry
covercash2 b79a175
fix links
covercash2 7f9b923
clarify note about interpolation
covercash2 978cfd4
minor doc edits
covercash2 21e92a7
clarify note about interpolation
covercash2 f26a354
added link to internal docs
covercash2 a202bf8
Links now work on stable
covercash2 dff42b3
Merge branch 'image_doc' of github.com:covercash2/druid into image_doc
covercash2 cd3c132
Merge branch 'master' of https://github.com/xi-editor/druid into imag…
covercash2 0ff367b
Merge branch 'master' into image_doc
xStrom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,58 @@ use crate::{ | |
| RenderContext, Size, UpdateCtx, Widget, | ||
| }; | ||
|
|
||
| /// A widget that renders an Image | ||
| /// A widget that renders a bitmap Image. | ||
| /// | ||
| /// Contains data about how to fill the given space and interpolate pixels. | ||
| /// Configuration options are provided via the builder pattern. | ||
| /// | ||
| /// Note: when [scaling a bitmap image], such as supporting multiple | ||
| /// screen sizes and resolutions, interpolation can lead to blurry | ||
| /// or pixelated images and so is not recommended for things like icons. | ||
| /// Instead consider using [SVG files] and enabling the `svg` feature with `cargo`. | ||
| /// | ||
| /// (See also: | ||
| /// [`ImageData`], | ||
| /// [`FillStrat`], | ||
| /// [`InterpolationMode`] | ||
| /// ) | ||
| /// | ||
| /// # 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 the fill strategy | ||
| /// .fill_mode(FillStrat::Fill) | ||
| /// // set the interpolation mode | ||
| /// .interpolation_mode(InterpolationMode::Bilinear); | ||
| /// ``` | ||
| /// 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 the fill strategy | ||
| /// image_widget.set_fill_mode(FillStrat::FitWidth); | ||
| /// // set the interpolation mode | ||
| /// image_widget.set_interpolation_mode(InterpolationMode::Bilinear); | ||
| /// ``` | ||
| /// | ||
| /// [scaling a bitmap image]: ../struct.Scale.html#pixels-and-display-points | ||
| /// [SVG files]: https://en.wikipedia.org/wiki/Scalable_Vector_Graphics | ||
| /// [`ImageData`]: struct.ImageData.html | ||
| /// [`FillStrat`]: ../widget/enum.FillStrat.html | ||
| /// [`InterpolationMode`]: ../piet/enum.InterpolationMode.html | ||
| pub struct Image { | ||
| image_data: ImageData, | ||
| paint_data: Option<PietImage>, | ||
|
|
@@ -36,7 +87,13 @@ 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. |
||
| /// | ||
| /// [`FillStrat::Fill`]: ../widget/enum.FillStrat.html#variant.Fill | ||
| /// [`InterpolationMode::Bilinear`]: ../piet/enum.InterpolationMode.html#variant.Bilinear | ||
| pub fn new(image_data: ImageData) -> Self { | ||
| Image { | ||
| image_data, | ||
|
|
@@ -52,7 +109,7 @@ impl Image { | |
| self | ||
| } | ||
|
|
||
| /// Modify the widget's `FillStrat`. | ||
| /// Modify the widget's fill strategy. | ||
| pub fn set_fill_mode(&mut self, newfil: FillStrat) { | ||
| self.fill = newfil; | ||
| self.paint_data = None; | ||
|
|
@@ -64,7 +121,7 @@ impl Image { | |
| self | ||
| } | ||
|
|
||
| /// Modify the widget's `InterpolationMode`. | ||
| /// Modify the widget's interpolation mode. | ||
| pub fn set_interpolation_mode(&mut self, interpolation: InterpolationMode) { | ||
| self.interpolation = interpolation; | ||
| self.paint_data = None; | ||
|
|
@@ -122,7 +179,17 @@ impl<T: Data> Widget<T> for Image { | |
| } | ||
| } | ||
|
|
||
| /// Stored Image data. | ||
| /// Processed image data. | ||
| /// | ||
| /// By default, Druid does not parse image data. | ||
| /// However, enabling [the `image` feature] | ||
| /// provides several | ||
| /// methods by which you can load image files. | ||
| /// | ||
| /// Contains raw bytes, dimensions, and image format ([`piet::ImageFormat`]). | ||
| /// | ||
| /// [the `image` feature]: ../index.html#optional-features | ||
| /// [`piet::ImageFormat`]: ../piet/enum.ImageFormat.html | ||
| #[derive(Clone)] | ||
| pub struct ImageData { | ||
| pixels: Vec<u8>, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.