Write some docs for the new float widget
This commit is contained in:
parent
aa27ab50e5
commit
8f3bca299b
1 changed files with 15 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
#![allow(missing_docs)]
|
//! Make elements float!
|
||||||
use crate::core;
|
use crate::core;
|
||||||
use crate::core::border;
|
use crate::core::border;
|
||||||
use crate::core::layout;
|
use crate::core::layout;
|
||||||
|
|
@ -12,6 +12,7 @@ use crate::core::{
|
||||||
Size, Transformation, Vector, Widget,
|
Size, Transformation, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A widget that can make its contents float over other widgets.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Float<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer>
|
pub struct Float<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer>
|
||||||
where
|
where
|
||||||
|
|
@ -28,6 +29,7 @@ impl<'a, Message, Theme, Renderer> Float<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
Theme: Catalog,
|
Theme: Catalog,
|
||||||
{
|
{
|
||||||
|
/// Creates a new [`Float`] widget with the given content.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|
@ -40,11 +42,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the scale to be applied to the contents of the [`Float`].
|
||||||
pub fn scale(mut self, scale: f32) -> Self {
|
pub fn scale(mut self, scale: f32) -> Self {
|
||||||
self.scale = scale;
|
self.scale = scale;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the translation logic to be applied to the contents of the [`Float`].
|
||||||
|
///
|
||||||
|
/// The logic takes the original (non-scaled) bounds of the contents and the
|
||||||
|
/// viewport bounds. These bounds can be useful to ensure the floating elements
|
||||||
|
/// always stay on screen.
|
||||||
pub fn translate(
|
pub fn translate(
|
||||||
mut self,
|
mut self,
|
||||||
translate: impl Fn(Rectangle, Rectangle) -> Vector + 'a,
|
translate: impl Fn(Rectangle, Rectangle) -> Vector + 'a,
|
||||||
|
|
@ -53,6 +61,12 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets whether the [`Float`] contents should be opaque when floating.
|
||||||
|
///
|
||||||
|
/// Disabling opacity will make the mouse pass through the floating content, allowing
|
||||||
|
/// interaction with whatever is under it.
|
||||||
|
///
|
||||||
|
/// By default, a [`Float`] widget is opaque.
|
||||||
pub fn opaque(mut self, opaque: bool) -> Self {
|
pub fn opaque(mut self, opaque: bool) -> Self {
|
||||||
self.opaque = opaque;
|
self.opaque = opaque;
|
||||||
self
|
self
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue