summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-29 10:57:01 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-29 10:57:01 +0100
commitc7b170da6d180f80e539910cccb543720fa3713c (patch)
tree6ef48d17104173f0ac7182d3647bd461e5581bd2 /native
parent4b86c2ff987e334c3454540828c6f8d16d27c670 (diff)
downloadiced-c7b170da6d180f80e539910cccb543720fa3713c.tar.gz
iced-c7b170da6d180f80e539910cccb543720fa3713c.tar.bz2
iced-c7b170da6d180f80e539910cccb543720fa3713c.zip
Draft `Style` and `StyleSheet` for `Button`
Diffstat (limited to 'native')
-rw-r--r--native/src/lib.rs2
-rw-r--r--native/src/renderer/null.rs11
-rw-r--r--native/src/widget/button.rs47
3 files changed, 25 insertions, 35 deletions
diff --git a/native/src/lib.rs b/native/src/lib.rs
index 8dcacb2b..9d237196 100644
--- a/native/src/lib.rs
+++ b/native/src/lib.rs
@@ -34,7 +34,7 @@
//! [`Windowed`]: renderer/trait.Windowed.html
//! [`UserInterface`]: struct.UserInterface.html
//! [renderer]: renderer/index.html
-#![deny(missing_docs)]
+//#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![deny(unused_results)]
#![deny(unsafe_code)]
diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs
index 43076d61..1be669c2 100644
--- a/native/src/renderer/null.rs
+++ b/native/src/renderer/null.rs
@@ -1,7 +1,7 @@
use crate::{
- button, checkbox, column, radio, row, scrollable, text, text_input,
- Background, Color, Element, Font, HorizontalAlignment, Layout, Point,
- Rectangle, Renderer, Size, VerticalAlignment,
+ button, checkbox, column, radio, row, scrollable, text, text_input, Color,
+ Element, Font, HorizontalAlignment, Layout, Point, Rectangle, Renderer,
+ Size, VerticalAlignment,
};
/// A renderer that does nothing.
@@ -117,13 +117,14 @@ impl text_input::Renderer for Null {
}
impl button::Renderer for Null {
+ type Style = ();
+
fn draw(
&mut self,
_bounds: Rectangle,
_cursor_position: Point,
_is_pressed: bool,
- _background: Option<Background>,
- _border_radius: u16,
+ _style: &Self::Style,
_content: Self::Output,
) -> Self::Output {
}
diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs
index 2881105f..4a7187da 100644
--- a/native/src/widget/button.rs
+++ b/native/src/widget/button.rs
@@ -6,8 +6,8 @@
//! [`State`]: struct.State.html
use crate::{
input::{mouse, ButtonState},
- layout, Background, Clipboard, Element, Event, Hasher, Layout, Length,
- Point, Rectangle, Widget,
+ layout, Clipboard, Element, Event, Hasher, Layout, Length, Point,
+ Rectangle, Widget,
};
use std::hash::Hash;
@@ -28,7 +28,7 @@ use std::hash::Hash;
/// .on_press(Message::ButtonPressed);
/// ```
#[allow(missing_debug_implementations)]
-pub struct Button<'a, Message, Renderer> {
+pub struct Button<'a, Message, Renderer: self::Renderer> {
state: &'a mut State,
content: Element<'a, Message, Renderer>,
on_press: Option<Message>,
@@ -37,11 +37,13 @@ pub struct Button<'a, Message, Renderer> {
min_width: u32,
min_height: u32,
padding: u16,
- background: Option<Background>,
- border_radius: u16,
+ style: Renderer::Style,
}
-impl<'a, Message, Renderer> Button<'a, Message, Renderer> {
+impl<'a, Message, Renderer> Button<'a, Message, Renderer>
+where
+ Renderer: self::Renderer,
+{
/// Creates a new [`Button`] with some local [`State`] and the given
/// content.
///
@@ -60,8 +62,7 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> {
min_width: 0,
min_height: 0,
padding: 0,
- background: None,
- border_radius: 0,
+ style: Renderer::Style::default(),
}
}
@@ -105,23 +106,6 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> {
self
}
- /// Sets the [`Background`] of the [`Button`].
- ///
- /// [`Button`]: struct.Button.html
- /// [`Background`]: ../../struct.Background.html
- pub fn background<T: Into<Background>>(mut self, background: T) -> Self {
- self.background = Some(background.into());
- self
- }
-
- /// Sets the border radius of the [`Button`].
- ///
- /// [`Button`]: struct.Button.html
- pub fn border_radius(mut self, border_radius: u16) -> Self {
- self.border_radius = border_radius;
- self
- }
-
/// Sets the message that will be produced when the [`Button`] is pressed.
///
/// [`Button`]: struct.Button.html
@@ -129,6 +113,11 @@ impl<'a, Message, Renderer> Button<'a, Message, Renderer> {
self.on_press = Some(msg);
self
}
+
+ pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
+ self.style = style.into();
+ self
+ }
}
/// The local state of a [`Button`].
@@ -240,8 +229,7 @@ where
layout.bounds(),
cursor_position,
self.state.is_pressed,
- self.background,
- self.border_radius,
+ &self.style,
content,
)
}
@@ -260,6 +248,8 @@ where
/// [`Button`]: struct.Button.html
/// [renderer]: ../../renderer/index.html
pub trait Renderer: crate::Renderer + Sized {
+ type Style: Default;
+
/// Draws a [`Button`].
///
/// [`Button`]: struct.Button.html
@@ -268,8 +258,7 @@ pub trait Renderer: crate::Renderer + Sized {
bounds: Rectangle,
cursor_position: Point,
is_pressed: bool,
- background: Option<Background>,
- border_radius: u16,
+ style: &Self::Style,
content: Self::Output,
) -> Self::Output;
}