Move styling to a brand new iced_style
crate
This commit is contained in:
parent
9ab7c47dc7
commit
e1062a02d1
@ -24,6 +24,7 @@ maintenance = { status = "actively-developed" }
|
|||||||
members = [
|
members = [
|
||||||
"core",
|
"core",
|
||||||
"native",
|
"native",
|
||||||
|
"style",
|
||||||
"web",
|
"web",
|
||||||
"wgpu",
|
"wgpu",
|
||||||
"winit",
|
"winit",
|
||||||
|
@ -22,7 +22,7 @@ pub mod widget {
|
|||||||
//!
|
//!
|
||||||
//! [`TextInput`]: text_input/struct.TextInput.html
|
//! [`TextInput`]: text_input/struct.TextInput.html
|
||||||
//! [`text_input::State`]: text_input/struct.State.html
|
//! [`text_input::State`]: text_input/struct.State.html
|
||||||
pub use iced_wgpu::button;
|
pub use iced_wgpu::widget::*;
|
||||||
|
|
||||||
pub mod scrollable {
|
pub mod scrollable {
|
||||||
//! Navigate an endless amount of content with a scrollbar.
|
//! Navigate an endless amount of content with a scrollbar.
|
||||||
@ -73,8 +73,9 @@ pub mod widget {
|
|||||||
|
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use {
|
pub use {
|
||||||
button::Button, image::Image, scrollable::Scrollable, slider::Slider,
|
button::Button, container::Container, image::Image,
|
||||||
svg::Svg, text_input::TextInput,
|
scrollable::Scrollable, slider::Slider, svg::Svg,
|
||||||
|
text_input::TextInput,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A container that distributes its contents vertically.
|
/// 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`.
|
/// This is an alias of an `iced_native` row with a default `Renderer`.
|
||||||
pub type Row<'a, Message> =
|
pub type Row<'a, Message> =
|
||||||
iced_winit::Row<'a, Message, iced_wgpu::Renderer>;
|
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)]
|
#[doc(no_inline)]
|
||||||
|
14
style/Cargo.toml
Normal file
14
style/Cargo.toml
Normal file
@ -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" }
|
79
style/src/button.rs
Normal file
79
style/src/button.rs
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
41
style/src/container.rs
Normal file
41
style/src/container.rs
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
2
style/src/lib.rs
Normal file
2
style/src/lib.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod button;
|
||||||
|
pub mod container;
|
@ -12,6 +12,7 @@ svg = ["resvg"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced_native = { version = "0.1.0", path = "../native" }
|
iced_native = { version = "0.1.0", path = "../native" }
|
||||||
|
iced_style = { version = "0.1.0-alpha", path = "../style" }
|
||||||
wgpu = "0.4"
|
wgpu = "0.4"
|
||||||
glyph_brush = "0.6"
|
glyph_brush = "0.6"
|
||||||
wgpu_glyph = { version = "0.7", git = "https://github.com/hecrj/wgpu_glyph", branch = "fix/font-load-panic" }
|
wgpu_glyph = { version = "0.7", git = "https://github.com/hecrj/wgpu_glyph", branch = "fix/font-load-panic" }
|
||||||
|
@ -5,86 +5,11 @@
|
|||||||
//! [`Button`]: type.Button.html
|
//! [`Button`]: type.Button.html
|
||||||
//! [`State`]: struct.State.html
|
//! [`State`]: struct.State.html
|
||||||
use crate::Renderer;
|
use crate::Renderer;
|
||||||
use iced_native::{Background, Color};
|
|
||||||
|
|
||||||
pub use iced_native::button::State;
|
pub use iced_native::button::State;
|
||||||
|
pub use iced_style::button::{Style, StyleSheet};
|
||||||
|
|
||||||
/// A widget that produces a message when clicked.
|
/// A widget that produces a message when clicked.
|
||||||
///
|
///
|
||||||
/// This is an alias of an `iced_native` button with an `iced_wgpu::Renderer`.
|
/// 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>;
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,37 +1,10 @@
|
|||||||
use iced_native::{Background, Color};
|
//! Decorate content and apply alignment.
|
||||||
|
use crate::Renderer;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
pub use iced_style::container::{Style, StyleSheet};
|
||||||
pub struct Style {
|
|
||||||
pub text_color: Option<Color>,
|
|
||||||
pub background: Option<Background>,
|
|
||||||
pub border_radius: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait StyleSheet {
|
/// An element decorating some content.
|
||||||
fn style(&self) -> Style {
|
///
|
||||||
Style {
|
/// This is an alias of an `iced_native` container with a default
|
||||||
text_color: None,
|
/// `Renderer`.
|
||||||
background: None,
|
pub type Container<'a, Message> = iced_native::Container<'a, Message, Renderer>;
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -6,6 +6,9 @@ edition = "2018"
|
|||||||
description = "A winit runtime for Iced"
|
description = "A winit runtime for Iced"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/hecrj/iced"
|
repository = "https://github.com/hecrj/iced"
|
||||||
|
documentation = "https://docs.rs/iced_winit"
|
||||||
|
keywords = ["gui", "ui", "graphics", "interface", "widgets"]
|
||||||
|
categories = ["gui"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
debug = []
|
debug = []
|
||||||
|
Loading…
Reference in New Issue
Block a user