Skip to content
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

Supplement image widget docs #1018

Merged
merged 39 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a8e22b5
add example to `Image` widget
covercash2 Jun 1, 2020
8b0e298
export `Image` and `ImageData`
covercash2 Jun 2, 2020
98897b7
Merge branch 'master' of https://github.com/xi-editor/druid into imag…
covercash2 Jun 2, 2020
282e438
add not about "image" feature
covercash2 Jun 2, 2020
b3ebd02
minor doc edits
covercash2 Jun 2, 2020
7207ead
Merge branch 'master' of https://github.com/xi-editor/druid into imag…
covercash2 Jun 4, 2020
c5db438
remove image feature reminder
covercash2 Jun 4, 2020
b4f26ea
minor doc edits
covercash2 Jun 4, 2020
13982de
add example
covercash2 Jun 4, 2020
7939d36
added note about image feature
covercash2 Jun 4, 2020
c05e4c7
update changelog
covercash2 Jun 4, 2020
dda5f59
rustfmt
covercash2 Jun 4, 2020
929e639
fix typo
covercash2 Jun 5, 2020
09cefc5
simplify changelog entry
covercash2 Jun 6, 2020
2478f99
fix links
covercash2 Jun 6, 2020
0466a12
clarify note about interpolation
covercash2 Jun 7, 2020
c6e9a2a
minor doc edits
covercash2 Jun 7, 2020
5f9bdd3
clarify note about interpolation
covercash2 Jun 13, 2020
7ce624c
added link to internal docs
covercash2 Jun 13, 2020
8ae701b
add example to `Image` widget
covercash2 Jun 1, 2020
40a384b
add not about "image" feature
covercash2 Jun 2, 2020
8233389
minor doc edits
covercash2 Jun 2, 2020
9c424d9
remove image feature reminder
covercash2 Jun 4, 2020
d8bb2af
minor doc edits
covercash2 Jun 4, 2020
95a37d0
add example
covercash2 Jun 4, 2020
fd7bbf4
added note about image feature
covercash2 Jun 4, 2020
a262ba5
update changelog
covercash2 Jun 4, 2020
ae67f6b
rustfmt
covercash2 Jun 4, 2020
5cb9577
fix typo
covercash2 Jun 5, 2020
037e3e8
simplify changelog entry
covercash2 Jun 6, 2020
b79a175
fix links
covercash2 Jun 6, 2020
7f9b923
clarify note about interpolation
covercash2 Jun 7, 2020
978cfd4
minor doc edits
covercash2 Jun 7, 2020
21e92a7
clarify note about interpolation
covercash2 Jun 13, 2020
f26a354
added link to internal docs
covercash2 Jun 13, 2020
a202bf8
Links now work on stable
covercash2 Jun 18, 2020
dff42b3
Merge branch 'image_doc' of github.com:covercash2/druid into image_doc
covercash2 Jun 18, 2020
cd3c132
Merge branch 'master' of https://github.com/xi-editor/druid into imag…
covercash2 Jun 18, 2020
0ff367b
Merge branch 'master' into image_doc
xStrom Jun 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You can find its changes [documented below](#060---2020-06-01).

### Docs

- Added documentation for the `druid::Image` widget. ([#1018] by [@covercash2])
covercash2 marked this conversation as resolved.
Show resolved Hide resolved
- Fixed a link in `druid::command` documentation. ([#1008] by [@covercash2])

### Examples
Expand Down Expand Up @@ -319,6 +320,7 @@ Last release without a changelog :(
[#1008]: https://github.com/xi-editor/druid/pull/1008
[#1011]: https://github.com/xi-editor/druid/pull/1011
[#1013]: https://github.com/xi-editor/druid/pull/1013
[#1018]: https://github.com/xi-editor/druid/pull/1018

[Unreleased]: https://github.com/xi-editor/druid/compare/v0.6.0...master
[0.6.0]: https://github.com/xi-editor/druid/compare/v0.5.0...v0.6.0
Expand Down
65 changes: 60 additions & 5 deletions druid/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can lead to when? With DPI scaling? Should mention just briefly that when scaling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure exactly how DPI scaling is relevant here? like images may look fine on a normal DPI screen but blurry when in hiDPI situations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly, yea.

/// [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.
Show resolved Hide resolved
/// .fill_mode(FillStrat::Fill)
/// // set interpolation mode
/// .interpolation_mode(InterpolationMode::NearestNeighbor);
covercash2 marked this conversation as resolved.
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,
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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,
Expand All @@ -50,7 +98,7 @@ impl Image {
self
}

/// Modify the widget's `FillStrat`.
/// Modify the widget's [`FillStrat`].
covercash2 marked this conversation as resolved.
Show resolved Hide resolved
pub fn set_fill_mode(&mut self, newfil: FillStrat) {
self.fill = newfil;
}
Expand All @@ -61,7 +109,7 @@ impl Image {
self
}

/// Modify the widget's `InterpolationMode`.
/// Modify the widget's [`InterpolationMode`].
covercash2 marked this conversation as resolved.
Show resolved Hide resolved
pub fn set_interpolation_mode(&mut self, interpolation: InterpolationMode) {
self.interpolation = interpolation;
}
Expand Down Expand Up @@ -106,7 +154,14 @@ impl<T: Data> Widget<T> for Image {
}
}

/// Stored Image data.
/// Loaded image data.
covercash2 marked this conversation as resolved.
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.
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.
Show resolved Hide resolved
#[derive(Clone)]
pub struct ImageData {
pixels: Vec<u8>,
Expand Down