Wire up styling to Radio in iced_native

This commit is contained in:
Héctor Ramón Jiménez 2021-10-20 19:06:53 +07:00
parent cc560aca18
commit d39ad717ed
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
11 changed files with 97 additions and 135 deletions

View file

@ -31,17 +31,17 @@ use dodrio::bumpalo;
///
/// ![Radio buttons drawn by Coffee's renderer](https://github.com/hecrj/coffee/blob/bda9818f823dfcb8a7ad0ff4940b4d4b387b5208/images/ui/radio.png?raw=true)
#[allow(missing_debug_implementations)]
pub struct Radio<Message> {
pub struct Radio<'a, Message> {
is_selected: bool,
on_click: Message,
label: String,
id: Option<String>,
name: Option<String>,
#[allow(dead_code)]
style: Box<dyn StyleSheet>,
style_sheet: &'a dyn StyleSheet,
}
impl<Message> Radio<Message> {
impl<'a, Message> Radio<'a, Message> {
/// Creates a new [`Radio`] button.
///
/// It expects:
@ -66,13 +66,13 @@ impl<Message> Radio<Message> {
label: label.into(),
id: None,
name: None,
style: Default::default(),
style_sheet: Default::default(),
}
}
/// Sets the style of the [`Radio`] button.
pub fn style(mut self, style: impl Into<Box<dyn StyleSheet>>) -> Self {
self.style = style.into();
pub fn style(mut self, style_sheet: &'a dyn StyleSheet) -> Self {
self.style_sheet = style_sheet;
self
}
@ -89,7 +89,7 @@ impl<Message> Radio<Message> {
}
}
impl<Message> Widget<Message> for Radio<Message>
impl<'a, Message> Widget<Message> for Radio<'a, Message>
where
Message: 'static + Clone,
{
@ -142,11 +142,11 @@ where
}
}
impl<'a, Message> From<Radio<Message>> for Element<'a, Message>
impl<'a, Message> From<Radio<'a, Message>> for Element<'a, Message>
where
Message: 'static + Clone,
{
fn from(radio: Radio<Message>) -> Element<'a, Message> {
fn from(radio: Radio<'a, Message>) -> Element<'a, Message> {
Element::new(radio)
}
}