Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic wgpu renderer #22

Merged
merged 53 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
e1b9d42
Start `iced_winit` and `iced_wgpu`
hecrj Oct 2, 2019
6329408
Open a window using `winit`
hecrj Oct 2, 2019
8bb33cd
Initialize `wgpu`
hecrj Oct 2, 2019
fc38119
Clear the window properly on redraw
hecrj Oct 2, 2019
ebb8dbb
Draft UI event loop
hecrj Oct 2, 2019
5204cc8
Count redraws and add a couple of TODOs
hecrj Oct 4, 2019
a7d1194
Add `Renderer` and `Primitive` concepts
hecrj Oct 5, 2019
a90f7fc
Move `MouseCursor` to `iced_wgpu`
hecrj Oct 5, 2019
0c3f787
Draft basic text rendering using `wgpu_glyph`
hecrj Oct 5, 2019
ef498eb
Add some padding to the `tour` example
hecrj Oct 5, 2019
957beee
Merge branch 'master' into basic-renderer
hecrj Oct 5, 2019
ae56edc
Center `tour` example
hecrj Oct 5, 2019
5a5ca34
Modularize `iced_wgpu`
hecrj Oct 5, 2019
7765e6d
Draft `Box` primitive
hecrj Oct 6, 2019
5286ef3
Make `tour` a simple example instead of a crate
hecrj Oct 6, 2019
70c17b0
Rename `Box` primitive to `Quad`
hecrj Oct 7, 2019
c9510db
Render colored quads
hecrj Oct 7, 2019
c9da3a1
Use `log` crate instead of `dbg!`
hecrj Oct 7, 2019
67f8da4
Initialize renderer primitive properly
hecrj Oct 7, 2019
0995950
Use latest `wgpu`
hecrj Oct 7, 2019
a0234d5
Draft fragment shader for rounded rectangles
hecrj Oct 7, 2019
10e10e5
Make `iced_core::Button` customizable
hecrj Oct 8, 2019
1a93f0e
Merge branch 'master' into basic-renderer
hecrj Oct 8, 2019
a92a0b7
Move `winit` logic from `iced` to `iced_winit`
hecrj Oct 9, 2019
fb8b50a
Move `winit` conversions to `iced_winit`
hecrj Oct 10, 2019
ab34ef4
Move `winit::Application` to its own module
hecrj Oct 10, 2019
ae585eb
Process `winit` mouse input and cursor movement
hecrj Oct 10, 2019
2fe01a0
Use improved `RedrawRequested` API in `iced_winit`
hecrj Oct 10, 2019
1f60ca3
Update mouse cursor icon properly in `iced_winit`
hecrj Oct 10, 2019
650d020
Handle window resizes in `iced_winit`
hecrj Oct 11, 2019
8846a23
Rename `Renderer::Primitive` to `Renderer::Output`
hecrj Oct 11, 2019
a031a6f
Handle mouse cursor in `iced_wgpu`
hecrj Oct 11, 2019
c63bdac
Make `Renderer` immutable in `UserInterface::build`
hecrj Oct 11, 2019
e74f117
Add a slight shadow to buttons for feedback
hecrj Oct 12, 2019
afacb35
Draw sliders in `iced_wgpu`
hecrj Oct 12, 2019
a444819
Fix button shadow feedback in `iced_wgpu`
hecrj Oct 12, 2019
8c3dabb
Draw radio buttons in `iced_wgpu`
hecrj Oct 12, 2019
ccc463a
Draw checkbox in `iced_wgpu`
hecrj Oct 13, 2019
734e80d
Draft `Debugger` implementation in `iced_wgpu`
hecrj Oct 13, 2019
665b1d4
Update examples `README`
hecrj Oct 13, 2019
7916e6c
Fix integration CI workflow
hecrj Oct 13, 2019
523736f
Fix `wgpu_glyph` dependency in `iced_wgpu`
hecrj Oct 13, 2019
f8a232c
Remove generic handle in `Image`
hecrj Oct 22, 2019
38b6c84
Implement basic image rendering in `iced_wgpu`
hecrj Oct 22, 2019
871eb41
Add `TODO` to `image::Renderer::node`
hecrj Oct 22, 2019
c7ef9d0
Connect `iced_web` with `iced` properly
hecrj Oct 23, 2019
6145140
Make `tour` example work on Wasm again
hecrj Oct 23, 2019
2f8e9db
Remove warnings in `wgpu::image`
hecrj Oct 23, 2019
7fdd7f5
Remove unused `Align` in `core::Text`
hecrj Oct 23, 2019
1788d5d
Update `README`s
hecrj Oct 23, 2019
ac611ab
Remove unnecessary comma
hecrj Oct 23, 2019
f6fc0b7
Remove leftover `winit` feature for `doc.rs`
hecrj Oct 23, 2019
99e1a37
Set initial window size to 1280x1024 for now
hecrj Oct 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ jobs:
- uses: actions/checkout@master
- name: Run tests
run: cargo test --verbose --all --all-features
- name: Build tour for WebAssembly
if: matrix.targets == 'wasm32-unknown-unknown'
run: cargo build --verbose --package iced_tour --lib --target wasm32-unknown-unknown
18 changes: 16 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iced"
version = "0.1.0-alpha"
version = "0.1.0-alpha.1"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
description = "A cross-platform GUI library inspired by Elm"
Expand All @@ -19,5 +19,19 @@ members = [
"core",
"native",
"web",
"examples/tour",
"wgpu",
"winit",
]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
iced_winit = { version = "0.1.0-alpha", path = "winit" }
iced_wgpu = { version = "0.1.0-alpha", path = "wgpu" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
iced_web = { version = "0.1.0-alpha", path = "web" }

[dev-dependencies]
env_logger = "0.7"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen = "0.2.51"
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ __view logic__:

```rust
use iced::{Button, Column, Text};
use iced_wgpu::Renderer; // Iced does not include a renderer! We need to bring our own!

impl Counter {
pub fn view(&mut self) -> Column<Message, Renderer> {
pub fn view(&mut self) -> Column<Message> {
// We use a column: a simple vertical layout
Column::new()
.push(
Expand Down
7 changes: 7 additions & 0 deletions core/src/background.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::Color;

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Background {
Color(Color),
// TODO: Add gradient and image variants
}
27 changes: 27 additions & 0 deletions core/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,31 @@ impl Color {
b: 0.0,
a: 1.0,
};

/// The white color.
pub const WHITE: Color = Color {
r: 1.0,
g: 1.0,
b: 1.0,
a: 1.0,
};

pub fn into_linear(self) -> [f32; 4] {
// As described in:
// https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation
fn linear_component(u: f32) -> f32 {
if u < 0.04045 {
u / 12.92
} else {
((u + 0.055) / 1.055).powf(2.4)
}
}

[
linear_component(self.r),
linear_component(self.g),
linear_component(self.b),
self.a,
]
}
}
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod widget;

mod align;
mod background;
mod color;
mod justify;
mod length;
Expand All @@ -9,6 +10,7 @@ mod rectangle;
mod vector;

pub use align::Align;
pub use background::Background;
pub use color::Color;
pub use justify::Justify;
pub use length::Length;
Expand Down
96 changes: 34 additions & 62 deletions core/src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,58 @@
//! [`Button`]: struct.Button.html
//! [`State`]: struct.State.html

use crate::{Align, Length};
use crate::{Align, Background, Length};

/// A generic widget that produces a message when clicked.
///
/// # Example
///
/// ```
/// use iced_core::{button, Button};
///
/// pub enum Message {
/// ButtonClicked,
/// }
///
/// let state = &mut button::State::new();
///
/// Button::new(state, "Click me!")
/// .on_press(Message::ButtonClicked);
/// ```
///
/// ![Button drawn by Coffee's renderer](https://github.com/hecrj/coffee/blob/bda9818f823dfcb8a7ad0ff4940b4d4b387b5208/images/ui/button.png?raw=true)
pub struct Button<'a, Message> {
pub struct Button<'a, Message, Element> {
/// The current state of the button
pub state: &'a mut State,

/// The label of the button
pub label: String,
pub content: Element,

/// The message to produce when the button is pressed
pub on_press: Option<Message>,

pub class: Class,

pub width: Length,

pub padding: u16,

pub background: Option<Background>,

pub border_radius: u16,

pub align_self: Option<Align>,
}

impl<'a, Message> std::fmt::Debug for Button<'a, Message>
impl<'a, Message, Element> std::fmt::Debug for Button<'a, Message, Element>
where
Message: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Button")
.field("state", &self.state)
.field("label", &self.label)
.field("on_press", &self.on_press)
.finish()
}
}

impl<'a, Message> Button<'a, Message> {
impl<'a, Message, Element> Button<'a, Message, Element> {
/// Creates a new [`Button`] with some local [`State`] and the given label.
///
/// [`Button`]: struct.Button.html
/// [`State`]: struct.State.html
pub fn new(state: &'a mut State, label: &str) -> Self {
pub fn new<E>(state: &'a mut State, content: E) -> Self
where
E: Into<Element>,
{
Button {
state,
label: String::from(label),
content: content.into(),
on_press: None,
class: Class::Primary,
width: Length::Shrink,
padding: 0,
background: None,
border_radius: 0,
align_self: None,
}
}
Expand All @@ -79,6 +69,21 @@ impl<'a, Message> Button<'a, Message> {
self
}

pub fn padding(mut self, padding: u16) -> Self {
self.padding = padding;
self
}

pub fn background(mut self, background: Background) -> Self {
self.background = Some(background);
self
}

pub fn border_radius(mut self, border_radius: u16) -> Self {
self.border_radius = border_radius;
self
}

/// Sets the alignment of the [`Button`] itself.
///
/// This is useful if you want to override the default alignment given by
Expand All @@ -90,16 +95,6 @@ impl<'a, Message> Button<'a, Message> {
self
}

/// Sets the [`Class`] of the [`Button`].
///
///
/// [`Button`]: struct.Button.html
/// [`Class`]: enum.Class.html
pub fn class(mut self, class: Class) -> Self {
self.class = class;
self
}

/// Sets the message that will be produced when the [`Button`] is pressed.
///
/// [`Button`]: struct.Button.html
Expand Down Expand Up @@ -133,26 +128,3 @@ impl State {
self.is_pressed
}
}

/// The type of a [`Button`].
///
/// ![Different buttons drawn by the built-in renderer in Coffee](https://github.com/hecrj/coffee/blob/bda9818f823dfcb8a7ad0ff4940b4d4b387b5208/images/ui/button_classes.png?raw=true)
///
/// [`Button`]: struct.Button.html
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Class {
/// The [`Button`] performs the main action.
///
/// [`Button`]: struct.Button.html
Primary,

/// The [`Button`] performs an alternative action.
///
/// [`Button`]: struct.Button.html
Secondary,

/// The [`Button`] performs a productive action.
///
/// [`Button`]: struct.Button.html
Positive,
}
28 changes: 9 additions & 19 deletions core/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::{Align, Length, Rectangle};
/// ```
/// use iced_core::Image;
///
/// # let my_handle = String::from("some_handle");
/// let image = Image::new(my_handle);
/// let image = Image::new("resources/ferris.png");
/// ```
pub struct Image<I> {
/// The image handle
pub handle: I,
#[derive(Debug)]
pub struct Image {
/// The image path
pub path: String,

/// The part of the image to show
pub clip: Option<Rectangle<u16>>,
Expand All @@ -28,23 +28,13 @@ pub struct Image<I> {
pub align_self: Option<Align>,
}

impl<I> std::fmt::Debug for Image<I> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Image")
.field("clip", &self.clip)
.field("width", &self.width)
.field("height", &self.height)
.finish()
}
}

impl<I> Image<I> {
/// Creates a new [`Image`] with given image handle.
impl Image {
/// Creates a new [`Image`] with the given path.
///
/// [`Image`]: struct.Image.html
pub fn new(handle: I) -> Self {
pub fn new<T: Into<String>>(path: T) -> Self {
Image {
handle,
path: path.into(),
clip: None,
width: Length::Shrink,
height: Length::Shrink,
Expand Down
Loading