Fix Image and ProgressBar doc examples
This commit is contained in:
parent
64fc0ffded
commit
52394732fc
2 changed files with 17 additions and 29 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
//! Displays image to your users.
|
//! Displays image to your users.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Style, Node, Element, MouseCursor, Layout, Hasher, Widget,
|
Element, Hasher, Layout, MouseCursor, Node, Point, Rectangle, Style, Widget,
|
||||||
Rectangle, Point,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
@ -20,7 +19,8 @@ use std::hash::Hash;
|
||||||
/// ```
|
/// ```
|
||||||
/// use iced::Image;
|
/// 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> {
|
pub struct Image<I> {
|
||||||
image: I,
|
image: I,
|
||||||
|
|
@ -41,9 +41,9 @@ impl<I> Image<I> {
|
||||||
/// Creates a new [`Image`] with given image handle.
|
/// Creates a new [`Image`] with given image handle.
|
||||||
///
|
///
|
||||||
/// [`Image`]: struct.Image.html
|
/// [`Image`]: struct.Image.html
|
||||||
pub fn new(image: &I) -> Self where I: Clone {
|
pub fn new(image: I) -> Self {
|
||||||
Image {
|
Image {
|
||||||
image: image.clone(),
|
image,
|
||||||
source: None,
|
source: None,
|
||||||
style: Style::default().fill_width().fill_height(),
|
style: Style::default().fill_width().fill_height(),
|
||||||
}
|
}
|
||||||
|
|
@ -89,11 +89,7 @@ where
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
_cursor_position: Point,
|
_cursor_position: Point,
|
||||||
) -> MouseCursor {
|
) -> MouseCursor {
|
||||||
renderer.draw(
|
renderer.draw(layout.bounds(), self.image.clone(), self.source);
|
||||||
layout.bounds(),
|
|
||||||
self.image.clone(),
|
|
||||||
self.source,
|
|
||||||
);
|
|
||||||
|
|
||||||
MouseCursor::OutOfBounds
|
MouseCursor::OutOfBounds
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +113,7 @@ pub trait Renderer<I> {
|
||||||
/// * the bounds of the [`Image`]
|
/// * the bounds of the [`Image`]
|
||||||
/// * the handle of the loaded [`Image`]
|
/// * the handle of the loaded [`Image`]
|
||||||
/// * the portion of the image that we wants to draw,
|
/// * 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
|
/// [`Image`]: struct.Image.html
|
||||||
fn draw(
|
fn draw(
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
//! Displays action progress to your users.
|
//! Displays action progress to your users.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Style, Node, Element, MouseCursor, Layout, Hasher, Widget,
|
Element, Hasher, Layout, MouseCursor, Node, Point, Rectangle, Style, Widget,
|
||||||
Point, Rectangle,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
@ -18,7 +17,7 @@ use std::hash::Hash;
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use coffee::ui::ProgressBar;
|
/// use iced::ProgressBar;
|
||||||
///
|
///
|
||||||
/// let progress = 0.75;
|
/// let progress = 0.75;
|
||||||
///
|
///
|
||||||
|
|
@ -60,7 +59,7 @@ impl ProgressBar {
|
||||||
|
|
||||||
impl<Message, Renderer> Widget<Message, Renderer> for ProgressBar
|
impl<Message, Renderer> Widget<Message, Renderer> for ProgressBar
|
||||||
where
|
where
|
||||||
Renderer: self::Renderer
|
Renderer: self::Renderer,
|
||||||
{
|
{
|
||||||
fn node(&self, _renderer: &Renderer) -> Node {
|
fn node(&self, _renderer: &Renderer) -> Node {
|
||||||
Node::new(self.style.height(50))
|
Node::new(self.style.height(50))
|
||||||
|
|
@ -72,10 +71,7 @@ where
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
_cursor_position: Point,
|
_cursor_position: Point,
|
||||||
) -> MouseCursor {
|
) -> MouseCursor {
|
||||||
renderer.draw(
|
renderer.draw(layout.bounds(), self.progress);
|
||||||
layout.bounds(),
|
|
||||||
self.progress,
|
|
||||||
);
|
|
||||||
|
|
||||||
MouseCursor::OutOfBounds
|
MouseCursor::OutOfBounds
|
||||||
}
|
}
|
||||||
|
|
@ -100,11 +96,7 @@ pub trait Renderer {
|
||||||
/// * the progress of the [`ProgressBar`]
|
/// * the progress of the [`ProgressBar`]
|
||||||
///
|
///
|
||||||
/// [`ProgressBar`]: struct.ProgressBar.html
|
/// [`ProgressBar`]: struct.ProgressBar.html
|
||||||
fn draw(
|
fn draw(&mut self, bounds: Rectangle<f32>, progress: f32);
|
||||||
&mut self,
|
|
||||||
bounds: Rectangle<f32>,
|
|
||||||
progress: f32,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer> From<ProgressBar> for Element<'a, Message, Renderer>
|
impl<'a, Message, Renderer> From<ProgressBar> for Element<'a, Message, Renderer>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue