summaryrefslogtreecommitdiffstats
path: root/src/widget/radio.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/widget/radio.rs')
-rw-r--r--src/widget/radio.rs48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/widget/radio.rs b/src/widget/radio.rs
index 8a678ec8..a59d52aa 100644
--- a/src/widget/radio.rs
+++ b/src/widget/radio.rs
@@ -8,13 +8,12 @@ use crate::{
use std::hash::Hash;
-/// A circular button representing a choice.
+/// A circular button representing a choice, with a generic text `Color`.
///
-/// It implements [`Widget`] when the [`core::Renderer`] implements the
+/// It implements [`Widget`] when the associated `Renderer` implements the
/// [`radio::Renderer`] trait.
///
-/// [`Widget`]: ../../core/trait.Widget.html
-/// [`core::Renderer`]: ../../core/trait.Renderer.html
+/// [`Widget`]: ../trait.Widget.html
/// [`radio::Renderer`]: trait.Renderer.html
///
/// # Example
@@ -26,12 +25,6 @@ use std::hash::Hash;
/// Black,
/// }
///
-/// impl Default for Color {
-/// fn default() -> Color {
-/// Color::Black
-/// }
-/// }
-///
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// pub enum Choice {
/// A,
@@ -45,16 +38,19 @@ use std::hash::Hash;
///
/// let selected_choice = Some(Choice::A);
///
-/// Radio::<Color, Message>::new(Choice::A, "This is A", selected_choice, Message::RadioSelected)
+/// Radio::new(Choice::A, "This is A", selected_choice, Message::RadioSelected)
+/// .label_color(Color::Black);
+///
+/// Radio::new(Choice::B, "This is B", selected_choice, Message::RadioSelected)
/// .label_color(Color::Black);
/// ```
///
-/// ![Checkbox drawn by the built-in renderer](https://github.com/hecrj/coffee/blob/bda9818f823dfcb8a7ad0ff4940b4d4b387b5208/images/ui/radio.png?raw=true)
+/// ![Radio buttons drawn by Coffee's renderer](https://github.com/hecrj/coffee/blob/bda9818f823dfcb8a7ad0ff4940b4d4b387b5208/images/ui/radio.png?raw=true)
pub struct Radio<Color, Message> {
is_selected: bool,
on_click: Message,
label: String,
- label_color: Color,
+ label_color: Option<Color>,
}
impl<Color, Message> std::fmt::Debug for Radio<Color, Message>
@@ -72,10 +68,7 @@ where
}
}
-impl<Color, Message> Radio<Color, Message>
-where
- Color: Default,
-{
+impl<Color, Message> Radio<Color, Message> {
/// Creates a new [`Radio`] button.
///
/// It expects:
@@ -95,16 +88,15 @@ where
is_selected: Some(value) == selected,
on_click: f(value),
label: String::from(label),
- label_color: Color::default(),
+ label_color: None,
}
}
- /// Sets the [`Color`] of the label of the [`Radio`].
+ /// Sets the `Color` of the label of the [`Radio`].
///
- /// [`Color`]: ../../../../graphics/struct.Color.html
/// [`Radio`]: struct.Radio.html
pub fn label_color(mut self, color: Color) -> Self {
- self.label_color = color;
+ self.label_color = Some(color);
self
}
}
@@ -112,7 +104,7 @@ where
impl<Color, Message, Renderer> Widget<Message, Renderer>
for Radio<Color, Message>
where
- Color: 'static + Copy + Default + std::fmt::Debug,
+ Color: 'static + Copy + std::fmt::Debug,
Renderer: self::Renderer + text::Renderer<Color>,
Message: Copy + std::fmt::Debug,
{
@@ -175,18 +167,18 @@ where
)
}
- fn hash(&self, state: &mut Hasher) {
+ fn hash_layout(&self, state: &mut Hasher) {
self.label.hash(state);
}
}
/// The renderer of a [`Radio`] button.
///
-/// Your [`core::Renderer`] will need to implement this trait before being
+/// Your [renderer] will need to implement this trait before being
/// able to use a [`Radio`] button in your user interface.
///
/// [`Radio`]: struct.Radio.html
-/// [`core::Renderer`]: ../../core/trait.Renderer.html
+/// [renderer]: ../../renderer/index.html
pub trait Renderer {
/// Draws a [`Radio`] button.
///
@@ -200,8 +192,8 @@ pub trait Renderer {
fn draw(
&mut self,
cursor_position: Point,
- bounds: Rectangle<f32>,
- label_bounds: Rectangle<f32>,
+ bounds: Rectangle,
+ label_bounds: Rectangle,
is_selected: bool,
) -> MouseCursor;
}
@@ -209,7 +201,7 @@ pub trait Renderer {
impl<'a, Color, Message, Renderer> From<Radio<Color, Message>>
for Element<'a, Message, Renderer>
where
- Color: 'static + Copy + Default + std::fmt::Debug,
+ Color: 'static + Copy + std::fmt::Debug,
Renderer: self::Renderer + text::Renderer<Color>,
Message: 'static + Copy + std::fmt::Debug,
{