Introduce state lifetime for style_sheet in ProgressBar
This commit is contained in:
parent
6504dca059
commit
d758006ee9
3 changed files with 16 additions and 15 deletions
|
|
@ -21,15 +21,15 @@ pub use iced_style::progress_bar::{Style, StyleSheet};
|
||||||
///
|
///
|
||||||
/// 
|
/// 
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct ProgressBar {
|
pub struct ProgressBar<'a> {
|
||||||
range: RangeInclusive<f32>,
|
range: RangeInclusive<f32>,
|
||||||
value: f32,
|
value: f32,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Option<Length>,
|
height: Option<Length>,
|
||||||
style_sheet: Box<dyn StyleSheet>,
|
style_sheet: Box<dyn StyleSheet + 'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgressBar {
|
impl<'a> ProgressBar<'a> {
|
||||||
/// The default height of a [`ProgressBar`].
|
/// The default height of a [`ProgressBar`].
|
||||||
pub const DEFAULT_HEIGHT: u16 = 30;
|
pub const DEFAULT_HEIGHT: u16 = 30;
|
||||||
|
|
||||||
|
|
@ -63,14 +63,14 @@ impl ProgressBar {
|
||||||
/// Sets the style of the [`ProgressBar`].
|
/// Sets the style of the [`ProgressBar`].
|
||||||
pub fn style(
|
pub fn style(
|
||||||
mut self,
|
mut self,
|
||||||
style_sheet: impl Into<Box<dyn StyleSheet>>,
|
style_sheet: impl Into<Box<dyn StyleSheet + 'a>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.style_sheet = style_sheet.into();
|
self.style_sheet = style_sheet.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message, Renderer> Widget<Message, Renderer> for ProgressBar
|
impl<'a, Message, Renderer> Widget<Message, Renderer> for ProgressBar<'a>
|
||||||
where
|
where
|
||||||
Renderer: crate::Renderer,
|
Renderer: crate::Renderer,
|
||||||
{
|
{
|
||||||
|
|
@ -147,12 +147,13 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer> From<ProgressBar> for Element<'a, Message, Renderer>
|
impl<'a, Message, Renderer> From<ProgressBar<'a>>
|
||||||
|
for Element<'a, Message, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: 'a + crate::Renderer,
|
Renderer: 'a + crate::Renderer,
|
||||||
Message: 'a,
|
Message: 'a,
|
||||||
{
|
{
|
||||||
fn from(progress_bar: ProgressBar) -> Element<'a, Message, Renderer> {
|
fn from(progress_bar: ProgressBar<'a>) -> Element<'a, Message, Renderer> {
|
||||||
Element::new(progress_bar)
|
Element::new(progress_bar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,9 @@ impl std::default::Default for Box<dyn StyleSheet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> From<T> for Box<dyn StyleSheet>
|
impl<'a, T> From<T> for Box<dyn StyleSheet + 'a>
|
||||||
where
|
where
|
||||||
T: 'static + StyleSheet,
|
T: 'a + StyleSheet,
|
||||||
{
|
{
|
||||||
fn from(style: T) -> Self {
|
fn from(style: T) -> Self {
|
||||||
Box::new(style)
|
Box::new(style)
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,15 @@ use std::ops::RangeInclusive;
|
||||||
///
|
///
|
||||||
/// 
|
/// 
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct ProgressBar {
|
pub struct ProgressBar<'a> {
|
||||||
range: RangeInclusive<f32>,
|
range: RangeInclusive<f32>,
|
||||||
value: f32,
|
value: f32,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Option<Length>,
|
height: Option<Length>,
|
||||||
style: Box<dyn StyleSheet>,
|
style: Box<dyn StyleSheet + 'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgressBar {
|
impl<'a> ProgressBar<'a> {
|
||||||
/// Creates a new [`ProgressBar`].
|
/// Creates a new [`ProgressBar`].
|
||||||
///
|
///
|
||||||
/// It expects:
|
/// It expects:
|
||||||
|
|
@ -61,7 +61,7 @@ impl ProgressBar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message> Widget<Message> for ProgressBar {
|
impl<'a, Message> Widget<Message> for ProgressBar<'a> {
|
||||||
fn node<'b>(
|
fn node<'b>(
|
||||||
&self,
|
&self,
|
||||||
bump: &'b bumpalo::Bump,
|
bump: &'b bumpalo::Bump,
|
||||||
|
|
@ -106,11 +106,11 @@ impl<Message> Widget<Message> for ProgressBar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message> From<ProgressBar> for Element<'a, Message>
|
impl<'a, Message> From<ProgressBar<'a>> for Element<'a, Message>
|
||||||
where
|
where
|
||||||
Message: 'static,
|
Message: 'static,
|
||||||
{
|
{
|
||||||
fn from(container: ProgressBar) -> Element<'a, Message> {
|
fn from(container: ProgressBar<'a>) -> Element<'a, Message> {
|
||||||
Element::new(container)
|
Element::new(container)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue