summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--src/native.rs14
-rw-r--r--style/Cargo.toml14
-rw-r--r--style/src/button.rs79
-rw-r--r--style/src/container.rs41
-rw-r--r--style/src/lib.rs2
-rw-r--r--wgpu/Cargo.toml1
-rw-r--r--wgpu/src/widget/button.rs77
-rw-r--r--wgpu/src/widget/container.rs43
-rw-r--r--winit/Cargo.toml3
10 files changed, 154 insertions, 121 deletions
diff --git a/Cargo.toml b/Cargo.toml
index ebd6412e..79a9007a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,6 +24,7 @@ maintenance = { status = "actively-developed" }
members = [
"core",
"native",
+ "style",
"web",
"wgpu",
"winit",
diff --git a/src/native.rs b/src/native.rs
index d5c9349a..54afee4b 100644
--- a/src/native.rs
+++ b/src/native.rs
@@ -22,7 +22,7 @@ pub mod widget {
//!
//! [`TextInput`]: text_input/struct.TextInput.html
//! [`text_input::State`]: text_input/struct.State.html
- pub use iced_wgpu::button;
+ pub use iced_wgpu::widget::*;
pub mod scrollable {
//! Navigate an endless amount of content with a scrollbar.
@@ -73,8 +73,9 @@ pub mod widget {
#[doc(no_inline)]
pub use {
- button::Button, image::Image, scrollable::Scrollable, slider::Slider,
- svg::Svg, text_input::TextInput,
+ button::Button, container::Container, image::Image,
+ scrollable::Scrollable, slider::Slider, svg::Svg,
+ text_input::TextInput,
};
/// A container that distributes its contents vertically.
@@ -88,13 +89,6 @@ pub mod widget {
/// This is an alias of an `iced_native` row with a default `Renderer`.
pub type Row<'a, Message> =
iced_winit::Row<'a, Message, iced_wgpu::Renderer>;
-
- /// An element decorating some content.
- ///
- /// This is an alias of an `iced_native` container with a default
- /// `Renderer`.
- pub type Container<'a, Message> =
- iced_winit::Container<'a, Message, iced_wgpu::Renderer>;
}
#[doc(no_inline)]
diff --git a/style/Cargo.toml b/style/Cargo.toml
new file mode 100644
index 00000000..5928c60d
--- /dev/null
+++ b/style/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "iced_style"
+version = "0.1.0-alpha"
+authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
+edition = "2018"
+description = "The default set of styles of Iced"
+license = "MIT"
+repository = "https://github.com/hecrj/iced"
+documentation = "https://docs.rs/iced_style"
+keywords = ["gui", "ui", "graphics", "interface", "widgets"]
+categories = ["gui"]
+
+[dependencies]
+iced_core = { version = "0.1.0", path = "../core" }
diff --git a/style/src/button.rs b/style/src/button.rs
new file mode 100644
index 00000000..42286897
--- /dev/null
+++ b/style/src/button.rs
@@ -0,0 +1,79 @@
+//! Allow your users to perform actions by pressing a button.
+use iced_core::{Background, Color};
+
+/// The appearance of a button.
+#[derive(Debug)]
+pub struct Style {
+ pub shadow_offset: f32,
+ pub background: Option<Background>,
+ pub border_radius: u16,
+ pub text_color: Color,
+}
+
+/// A set of rules that dictate the style of a button.
+pub trait StyleSheet {
+ fn active(&self) -> Style;
+
+ fn hovered(&self) -> Style {
+ let active = self.active();
+
+ Style {
+ shadow_offset: active.shadow_offset + 1.0,
+ ..active
+ }
+ }
+
+ fn pressed(&self) -> Style {
+ Style {
+ shadow_offset: 0.0,
+ ..self.active()
+ }
+ }
+
+ fn disabled(&self) -> Style {
+ let active = self.active();
+
+ Style {
+ shadow_offset: 0.0,
+ background: active.background.map(|background| match background {
+ Background::Color(color) => Background::Color(Color {
+ a: color.a * 0.5,
+ ..color
+ }),
+ }),
+ text_color: Color {
+ a: active.text_color.a * 0.5,
+ ..active.text_color
+ },
+ ..active
+ }
+ }
+}
+
+struct Default;
+
+impl StyleSheet for Default {
+ fn active(&self) -> Style {
+ Style {
+ shadow_offset: 1.0,
+ background: Some(Background::Color([0.5, 0.5, 0.5].into())),
+ border_radius: 5,
+ text_color: Color::BLACK,
+ }
+ }
+}
+
+impl std::default::Default for Box<dyn StyleSheet> {
+ fn default() -> Self {
+ Box::new(Default)
+ }
+}
+
+impl<T> From<T> for Box<dyn StyleSheet>
+where
+ T: 'static + StyleSheet,
+{
+ fn from(style: T) -> Self {
+ Box::new(style)
+ }
+}
diff --git a/style/src/container.rs b/style/src/container.rs
new file mode 100644
index 00000000..756ea0f9
--- /dev/null
+++ b/style/src/container.rs
@@ -0,0 +1,41 @@
+//! Decorate content and apply alignment.
+use iced_core::{Background, Color};
+
+/// The appearance of a container.
+#[derive(Debug, Clone, Copy)]
+pub struct Style {
+ pub text_color: Option<Color>,
+ pub background: Option<Background>,
+ pub border_radius: u16,
+}
+
+/// A set of rules that dictate the style of a container.
+pub trait StyleSheet {
+ /// Produces the style of a container.
+ fn style(&self) -> Style {
+ Style {
+ text_color: None,
+ background: None,
+ border_radius: 0,
+ }
+ }
+}
+
+struct Default;
+
+impl StyleSheet for Default {}
+
+impl std::default::Default for Box<dyn StyleSheet> {
+ fn default() -> Self {
+ Box::new(Default)
+ }
+}
+
+impl<T> From<T> for Box<dyn StyleSheet>
+where
+ T: 'static + StyleSheet,
+{
+ fn from(style: T) -> Self {
+ Box::new(style)
+ }
+}
diff --git a/style/src/lib.rs b/style/src/lib.rs
new file mode 100644
index 00000000..c6f34301
--- /dev/null
+++ b/style/src/lib.rs
@@ -0,0 +1,2 @@
+pub mod button;
+pub mod container;
diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml
index bb241914..19d41bba 100644
--- a/wgpu/Cargo.toml
+++ b/wgpu/Cargo.toml
@@ -12,6 +12,7 @@ svg = ["resvg"]
[dependencies]
iced_native = { version = "0.1.0", path = "../native" }
+iced_style = { version = "0.1.0-alpha", path = "../style" }
wgpu = "0.4"
glyph_brush = "0.6"
wgpu_glyph = { version = "0.7", git = "https://github.com/hecrj/wgpu_glyph", branch = "fix/font-load-panic" }
diff --git a/wgpu/src/widget/button.rs b/wgpu/src/widget/button.rs
index 2c4e174f..b738c55e 100644
--- a/wgpu/src/widget/button.rs
+++ b/wgpu/src/widget/button.rs
@@ -5,86 +5,11 @@
//! [`Button`]: type.Button.html
//! [`State`]: struct.State.html
use crate::Renderer;
-use iced_native::{Background, Color};
pub use iced_native::button::State;
+pub use iced_style::button::{Style, StyleSheet};
/// A widget that produces a message when clicked.
///
/// This is an alias of an `iced_native` button with an `iced_wgpu::Renderer`.
pub type Button<'a, Message> = iced_native::Button<'a, Message, Renderer>;
-
-#[derive(Debug)]
-pub struct Style {
- pub shadow_offset: f32,
- pub background: Option<Background>,
- pub border_radius: u16,
- pub text_color: Color,
-}
-
-pub trait StyleSheet {
- fn active(&self) -> Style;
-
- fn hovered(&self) -> Style {
- let active = self.active();
-
- Style {
- shadow_offset: active.shadow_offset + 1.0,
- ..active
- }
- }
-
- fn pressed(&self) -> Style {
- Style {
- shadow_offset: 0.0,
- ..self.active()
- }
- }
-
- fn disabled(&self) -> Style {
- let active = self.active();
-
- Style {
- shadow_offset: 0.0,
- background: active.background.map(|background| match background {
- Background::Color(color) => Background::Color(Color {
- a: color.a * 0.5,
- ..color
- }),
- }),
- text_color: Color {
- a: active.text_color.a * 0.5,
- ..active.text_color
- },
- ..active
- }
- }
-}
-
-struct Default;
-
-impl StyleSheet for Default {
- fn active(&self) -> Style {
- Style {
- shadow_offset: 1.0,
- background: Some(Background::Color([0.5, 0.5, 0.5].into())),
- border_radius: 5,
- text_color: Color::BLACK,
- }
- }
-}
-
-impl std::default::Default for Box<dyn StyleSheet> {
- fn default() -> Self {
- Box::new(Default)
- }
-}
-
-impl<T> From<T> for Box<dyn StyleSheet>
-where
- T: 'static + StyleSheet,
-{
- fn from(style: T) -> Self {
- Box::new(style)
- }
-}
diff --git a/wgpu/src/widget/container.rs b/wgpu/src/widget/container.rs
index 1fc0ec98..9a93a246 100644
--- a/wgpu/src/widget/container.rs
+++ b/wgpu/src/widget/container.rs
@@ -1,37 +1,10 @@
-use iced_native::{Background, Color};
+//! Decorate content and apply alignment.
+use crate::Renderer;
-#[derive(Debug, Clone, Copy)]
-pub struct Style {
- pub text_color: Option<Color>,
- pub background: Option<Background>,
- pub border_radius: u16,
-}
+pub use iced_style::container::{Style, StyleSheet};
-pub trait StyleSheet {
- fn style(&self) -> Style {
- Style {
- text_color: None,
- background: None,
- border_radius: 0,
- }
- }
-}
-
-struct Default;
-
-impl StyleSheet for Default {}
-
-impl std::default::Default for Box<dyn StyleSheet> {
- fn default() -> Self {
- Box::new(Default)
- }
-}
-
-impl<T> From<T> for Box<dyn StyleSheet>
-where
- T: 'static + StyleSheet,
-{
- fn from(style: T) -> Self {
- Box::new(style)
- }
-}
+/// An element decorating some content.
+///
+/// This is an alias of an `iced_native` container with a default
+/// `Renderer`.
+pub type Container<'a, Message> = iced_native::Container<'a, Message, Renderer>;
diff --git a/winit/Cargo.toml b/winit/Cargo.toml
index 60e3f2d0..5727f8cf 100644
--- a/winit/Cargo.toml
+++ b/winit/Cargo.toml
@@ -6,6 +6,9 @@ edition = "2018"
description = "A winit runtime for Iced"
license = "MIT"
repository = "https://github.com/hecrj/iced"
+documentation = "https://docs.rs/iced_winit"
+keywords = ["gui", "ui", "graphics", "interface", "widgets"]
+categories = ["gui"]
[features]
debug = []