summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-09-03 13:47:32 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-09-03 13:47:32 +0200
commit52394732fc2a5c6152a938f1b2967c921bfef7be (patch)
treefb705005debe5c1d9ccd8dbe9d6043dea245062c /src
parent64fc0ffded3d4243bbe288a760319ff100d060e1 (diff)
downloadiced-52394732fc2a5c6152a938f1b2967c921bfef7be.tar.gz
iced-52394732fc2a5c6152a938f1b2967c921bfef7be.tar.bz2
iced-52394732fc2a5c6152a938f1b2967c921bfef7be.zip
Fix `Image` and `ProgressBar` doc examples
Diffstat (limited to 'src')
-rw-r--r--src/widget/image.rs24
-rw-r--r--src/widget/progress_bar.rs22
2 files changed, 17 insertions, 29 deletions
diff --git a/src/widget/image.rs b/src/widget/image.rs
index f9b3a037..500abe0d 100644
--- a/src/widget/image.rs
+++ b/src/widget/image.rs
@@ -1,14 +1,13 @@
//! Displays image to your users.
use crate::{
- Style, Node, Element, MouseCursor, Layout, Hasher, Widget,
- Rectangle, Point,
+ Element, Hasher, Layout, MouseCursor, Node, Point, Rectangle, Style, Widget,
};
use std::hash::Hash;
/// A widget that displays an image.
-///
+///
/// It implements [`Widget`] when the associated [`core::Renderer`] implements
/// the [`image::Renderer`] trait.
///
@@ -20,7 +19,8 @@ use std::hash::Hash;
/// ```
/// use iced::Image;
///
-/// let image = Image::new("image");
+/// # let my_handle = String::from("some_handle");
+/// let image = Image::new(my_handle);
/// ```
pub struct Image<I> {
image: I,
@@ -41,16 +41,16 @@ impl<I> Image<I> {
/// Creates a new [`Image`] with given image handle.
///
/// [`Image`]: struct.Image.html
- pub fn new(image: &I) -> Self where I: Clone {
+ pub fn new(image: I) -> Self {
Image {
- image: image.clone(),
+ image,
source: None,
style: Style::default().fill_width().fill_height(),
}
}
/// Sets the portion of the [`Image`] that we want to draw.
- ///
+ ///
/// [`Image`]: struct.Image.html
pub fn clip(mut self, source: Rectangle<u16>) -> Self {
self.source = Some(source);
@@ -89,11 +89,7 @@ where
layout: Layout<'_>,
_cursor_position: Point,
) -> MouseCursor {
- renderer.draw(
- layout.bounds(),
- self.image.clone(),
- self.source,
- );
+ renderer.draw(layout.bounds(), self.image.clone(), self.source);
MouseCursor::OutOfBounds
}
@@ -117,8 +113,8 @@ pub trait Renderer<I> {
/// * the bounds of the [`Image`]
/// * the handle of the loaded [`Image`]
/// * the portion of the image that we wants to draw,
- /// if not specified, draw entire image
- ///
+ /// if not specified, draw entire image
+ ///
/// [`Image`]: struct.Image.html
fn draw(
&mut self,
diff --git a/src/widget/progress_bar.rs b/src/widget/progress_bar.rs
index 0ce274e4..19e164f6 100644
--- a/src/widget/progress_bar.rs
+++ b/src/widget/progress_bar.rs
@@ -1,14 +1,13 @@
//! Displays action progress to your users.
use crate::{
- Style, Node, Element, MouseCursor, Layout, Hasher, Widget,
- Point, Rectangle,
+ Element, Hasher, Layout, MouseCursor, Node, Point, Rectangle, Style, Widget,
};
use std::hash::Hash;
/// A widget that displays a progress of an action.
-///
+///
/// It implements [`Widget`] when the associated [`core::Renderer`] implements
/// the [`button::Renderer`] trait.
///
@@ -18,7 +17,7 @@ use std::hash::Hash;
/// # Example
///
/// ```
-/// use coffee::ui::ProgressBar;
+/// use iced::ProgressBar;
///
/// let progress = 0.75;
///
@@ -60,7 +59,7 @@ impl ProgressBar {
impl<Message, Renderer> Widget<Message, Renderer> for ProgressBar
where
- Renderer: self::Renderer
+ Renderer: self::Renderer,
{
fn node(&self, _renderer: &Renderer) -> Node {
Node::new(self.style.height(50))
@@ -72,10 +71,7 @@ where
layout: Layout<'_>,
_cursor_position: Point,
) -> MouseCursor {
- renderer.draw(
- layout.bounds(),
- self.progress,
- );
+ renderer.draw(layout.bounds(), self.progress);
MouseCursor::OutOfBounds
}
@@ -98,13 +94,9 @@ pub trait Renderer {
/// It receives:
/// * the bounds of the [`ProgressBar`]
/// * the progress of the [`ProgressBar`]
- ///
+ ///
/// [`ProgressBar`]: struct.ProgressBar.html
- fn draw(
- &mut self,
- bounds: Rectangle<f32>,
- progress: f32,
- );
+ fn draw(&mut self, bounds: Rectangle<f32>, progress: f32);
}
impl<'a, Message, Renderer> From<ProgressBar> for Element<'a, Message, Renderer>