Use intra-doc links in image::viewer

This commit is contained in:
Héctor Ramón Jiménez 2020-12-18 11:27:43 +01:00
parent 6a51282933
commit c54a6446a3

View File

@ -28,9 +28,7 @@ pub struct Viewer<'a> {
impl<'a> Viewer<'a> { impl<'a> Viewer<'a> {
/// Creates a new [`Viewer`] with the given [`State`] and [`Handle`]. /// Creates a new [`Viewer`] with the given [`State`] and [`Handle`].
/// ///
/// [`Viewer`]: struct.Viewer.html /// [`Handle`]: image::Handle
/// [`State`]: struct.State.html
/// [`Handle`]: ../../image/struct.Handle.html
pub fn new(state: &'a mut State, handle: image::Handle) -> Self { pub fn new(state: &'a mut State, handle: image::Handle) -> Self {
Viewer { Viewer {
state, state,
@ -47,40 +45,30 @@ impl<'a> Viewer<'a> {
} }
/// Sets the padding of the [`Viewer`]. /// Sets the padding of the [`Viewer`].
///
/// [`Viewer`]: struct.Viewer.html
pub fn padding(mut self, units: u16) -> Self { pub fn padding(mut self, units: u16) -> Self {
self.padding = units; self.padding = units;
self self
} }
/// Sets the width of the [`Viewer`]. /// Sets the width of the [`Viewer`].
///
/// [`Viewer`]: struct.Viewer.html
pub fn width(mut self, width: Length) -> Self { pub fn width(mut self, width: Length) -> Self {
self.width = width; self.width = width;
self self
} }
/// Sets the height of the [`Viewer`]. /// Sets the height of the [`Viewer`].
///
/// [`Viewer`]: struct.Viewer.html
pub fn height(mut self, height: Length) -> Self { pub fn height(mut self, height: Length) -> Self {
self.height = height; self.height = height;
self self
} }
/// Sets the max width of the [`Viewer`]. /// Sets the max width of the [`Viewer`].
///
/// [`Viewer`]: struct.Viewer.html
pub fn max_width(mut self, max_width: u32) -> Self { pub fn max_width(mut self, max_width: u32) -> Self {
self.max_width = max_width; self.max_width = max_width;
self self
} }
/// Sets the max height of the [`Viewer`]. /// Sets the max height of the [`Viewer`].
///
/// [`Viewer`]: struct.Viewer.html
pub fn max_height(mut self, max_height: u32) -> Self { pub fn max_height(mut self, max_height: u32) -> Self {
self.max_height = max_height; self.max_height = max_height;
self self
@ -89,8 +77,6 @@ impl<'a> Viewer<'a> {
/// Sets the max scale applied to the image of the [`Viewer`]. /// Sets the max scale applied to the image of the [`Viewer`].
/// ///
/// Default is `10.0` /// Default is `10.0`
///
/// [`Viewer`]: struct.Viewer.html
pub fn max_scale(mut self, max_scale: f32) -> Self { pub fn max_scale(mut self, max_scale: f32) -> Self {
self.max_scale = max_scale; self.max_scale = max_scale;
self self
@ -99,8 +85,6 @@ impl<'a> Viewer<'a> {
/// Sets the min scale applied to the image of the [`Viewer`]. /// Sets the min scale applied to the image of the [`Viewer`].
/// ///
/// Default is `0.25` /// Default is `0.25`
///
/// [`Viewer`]: struct.Viewer.html
pub fn min_scale(mut self, min_scale: f32) -> Self { pub fn min_scale(mut self, min_scale: f32) -> Self {
self.min_scale = min_scale; self.min_scale = min_scale;
self self
@ -110,8 +94,6 @@ impl<'a> Viewer<'a> {
/// when zoomed in / out. /// when zoomed in / out.
/// ///
/// Default is `0.10` /// Default is `0.10`
///
/// [`Viewer`]: struct.Viewer.html
pub fn scale_step(mut self, scale_step: f32) -> Self { pub fn scale_step(mut self, scale_step: f32) -> Self {
self.scale_step = scale_step; self.scale_step = scale_step;
self self
@ -120,8 +102,6 @@ impl<'a> Viewer<'a> {
/// Returns the bounds of the underlying image, given the bounds of /// Returns the bounds of the underlying image, given the bounds of
/// the [`Viewer`]. Scaling will be applied and original aspect ratio /// the [`Viewer`]. Scaling will be applied and original aspect ratio
/// will be respected. /// will be respected.
///
/// [`Viewer`]: struct.Viewer.html
fn image_size<Renderer>(&self, renderer: &Renderer, bounds: Size) -> Size fn image_size<Renderer>(&self, renderer: &Renderer, bounds: Size) -> Size
where where
Renderer: self::Renderer + image::Renderer, Renderer: self::Renderer + image::Renderer,
@ -344,8 +324,6 @@ where
} }
/// The local state of a [`Viewer`]. /// The local state of a [`Viewer`].
///
/// [`Viewer`]: struct.Viewer.html
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct State { pub struct State {
scale: f32, scale: f32,
@ -367,17 +345,12 @@ impl Default for State {
impl State { impl State {
/// Creates a new [`State`]. /// Creates a new [`State`].
///
/// [`State`]: struct.State.html
pub fn new() -> Self { pub fn new() -> Self {
State::default() State::default()
} }
/// Returns the current offset of the [`State`], given the bounds /// Returns the current offset of the [`State`], given the bounds
/// of the [`Viewer`] and its image. /// of the [`Viewer`] and its image.
///
/// [`Viewer`]: struct.Viewer.html
/// [`State`]: struct.State.html
fn offset(&self, bounds: Rectangle, image_size: Size) -> Vector { fn offset(&self, bounds: Rectangle, image_size: Size) -> Vector {
let hidden_width = let hidden_width =
(image_size.width - bounds.width / 2.0).max(0.0).round(); (image_size.width - bounds.width / 2.0).max(0.0).round();
@ -392,9 +365,6 @@ impl State {
} }
/// Returns if the cursor is currently grabbed by the [`Viewer`]. /// Returns if the cursor is currently grabbed by the [`Viewer`].
///
/// [`Viewer`]: struct.Viewer.html
/// [`State`]: struct.State.html
pub fn is_cursor_grabbed(&self) -> bool { pub fn is_cursor_grabbed(&self) -> bool {
self.cursor_grabbed_at.is_some() self.cursor_grabbed_at.is_some()
} }
@ -405,22 +375,19 @@ impl State {
/// Your [renderer] will need to implement this trait before being /// Your [renderer] will need to implement this trait before being
/// able to use a [`Viewer`] in your user interface. /// able to use a [`Viewer`] in your user interface.
/// ///
/// [`Viewer`]: struct.Viewer.html /// [renderer]: crate::renderer
/// [renderer]: ../../../renderer/index.html
pub trait Renderer: crate::Renderer + Sized { pub trait Renderer: crate::Renderer + Sized {
/// Draws the [`Viewer`]. /// Draws the [`Viewer`].
/// ///
/// It receives: /// It receives:
/// - the [`State`] of the [`Viewer`] /// - the [`State`] of the [`Viewer`]
/// - the bounds of the [`Viewer`] widget /// - the bounds of the [`Viewer`] widget
/// - the bounds of the scaled [`Viewer`] image /// - the [`Size`] of the scaled [`Viewer`] image
/// - the translation of the clipped image /// - the translation of the clipped image
/// - the [`Handle`] to the underlying image /// - the [`Handle`] to the underlying image
/// - whether the mouse is over the [`Viewer`] or not /// - whether the mouse is over the [`Viewer`] or not
/// ///
/// [`Viewer`]: struct.Viewer.html /// [`Handle`]: image::Handle
/// [`State`]: struct.State.html
/// [`Handle`]: ../../image/struct.Handle.html
fn draw( fn draw(
&mut self, &mut self,
state: &State, state: &State,