From 10e10e5e06841574425d2633f1c2916733f7b4ff Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 8 Oct 2019 03:13:41 +0200 Subject: Make `iced_core::Button` customizable Now it supports: - Any kind of content - Custom border radius - Custom background --- web/src/element.rs | 8 ++++++++ web/src/widget/button.rs | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'web') diff --git a/web/src/element.rs b/web/src/element.rs index 8270d8db..a2b78c69 100644 --- a/web/src/element.rs +++ b/web/src/element.rs @@ -14,6 +14,14 @@ impl<'a, Message> Element<'a, Message> { } } + pub fn node<'b>( + &self, + bump: &'b bumpalo::Bump, + bus: &Bus, + ) -> dodrio::Node<'b> { + self.widget.node(bump, bus) + } + pub fn explain(self, _color: Color) -> Element<'a, Message> { self } diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 23a4165a..257034a7 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -2,7 +2,10 @@ use crate::{Bus, Element, Widget}; use dodrio::bumpalo; -pub use iced_core::button::*; +pub use iced_core::button::State; + +pub type Button<'a, Message> = + iced_core::Button<'a, Message, Element<'a, Message>>; impl<'a, Message> Widget for Button<'a, Message> where @@ -15,9 +18,8 @@ where ) -> dodrio::Node<'b> { use dodrio::builder::*; - let label = bumpalo::format!(in bump, "{}", self.label); - - let mut node = button(bump).children(vec![text(label.into_bump_str())]); + let mut node = + button(bump).children(vec![self.content.node(bump, bus)]); if let Some(on_press) = self.on_press { let event_bus = bus.clone(); -- cgit From a92a0b73ed7ed935df762d06c4249894fd35b227 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 9 Oct 2019 05:36:49 +0200 Subject: Move `winit` logic from `iced` to `iced_winit` - Added new `renderer::Windowed` trait. This shoud allow users to easily try different renderers by simply changing one line. - Renamed `UserInterface` traits to `Application`, as the `run` method takes total control of the current thread. - Moved `MouseCursor` back to `iced_native`. The new `renderer::Windowed` trait returns one on `draw`. - Split `iced_native` renderer in multiple modules, for consistency. --- web/src/bus.rs | 4 ++-- web/src/lib.rs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'web') diff --git a/web/src/bus.rs b/web/src/bus.rs index d76466f5..b4fd67c7 100644 --- a/web/src/bus.rs +++ b/web/src/bus.rs @@ -1,4 +1,4 @@ -use crate::Application; +use crate::Instance; use std::rc::Rc; @@ -14,7 +14,7 @@ where pub fn new() -> Self { Self { publish: Rc::new(Box::new(|message, root| { - let app = root.unwrap_mut::>(); + let app = root.unwrap_mut::>(); app.update(message) })), diff --git a/web/src/lib.rs b/web/src/lib.rs index caf17df5..04848d07 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -11,7 +11,7 @@ pub use element::Element; pub use iced_core::{Align, Color, Justify, Length}; pub use widget::*; -pub trait UserInterface { +pub trait Application { type Message; fn update( @@ -25,23 +25,23 @@ pub trait UserInterface { where Self: 'static + Sized, { + let app = Instance::new(self); + let window = web_sys::window().unwrap(); let document = window.document().unwrap(); let body = document.body().unwrap(); - - let app = Application::new(self); - let vdom = dodrio::Vdom::new(&body, app); + vdom.forget(); } } -struct Application { - ui: RefCell>>, +struct Instance { + ui: RefCell>>, } -impl Application { - fn new(ui: impl UserInterface + 'static) -> Self { +impl Instance { + fn new(ui: impl Application + 'static) -> Self { Self { ui: RefCell::new(Box::new(ui)), } @@ -55,7 +55,7 @@ impl Application { } } -impl dodrio::Render for Application +impl dodrio::Render for Instance where Message: 'static, { -- cgit From f8a232c8af4c50557fbf0c2e0b2ba46fb63f6adc Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 22 Oct 2019 23:20:24 +0200 Subject: Remove generic handle in `Image` For now, we will simply assume images will be loaded from a given path. --- web/src/widget/image.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'web') diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs index fd4ff0df..bd3e5daf 100644 --- a/web/src/widget/image.rs +++ b/web/src/widget/image.rs @@ -2,9 +2,9 @@ use crate::{Bus, Element, Length, Widget}; use dodrio::bumpalo; -pub type Image<'a> = iced_core::Image<&'a str>; +pub use iced_core::Image; -impl<'a, Message> Widget for Image<'a> { +impl Widget for Image { fn node<'b>( &self, bump: &'b bumpalo::Bump, @@ -12,7 +12,7 @@ impl<'a, Message> Widget for Image<'a> { ) -> dodrio::Node<'b> { use dodrio::builder::*; - let src = bumpalo::format!(in bump, "{}", self.handle); + let src = bumpalo::format!(in bump, "{}", self.path); let mut image = img(bump).attr("src", src.into_bump_str()); @@ -35,8 +35,8 @@ impl<'a, Message> Widget for Image<'a> { } } -impl<'a, Message> From> for Element<'a, Message> { - fn from(image: Image<'a>) -> Element<'a, Message> { +impl<'a, Message> From for Element<'a, Message> { + fn from(image: Image) -> Element<'a, Message> { Element::new(image) } } -- cgit From c7ef9d0da705d8f27011fe41d2103c73aae42d2d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 23 Oct 2019 02:33:07 +0200 Subject: Connect `iced_web` with `iced` properly --- web/Cargo.toml | 3 +-- web/src/lib.rs | 13 +++---------- 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'web') diff --git a/web/Cargo.toml b/web/Cargo.toml index d5a987b0..473bde17 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -17,8 +17,7 @@ maintenance = { status = "actively-developed" } [dependencies] iced_core = { version = "0.1.0-alpha", path = "../core" } dodrio = "0.1.0" -futures-preview = "=0.3.0-alpha.18" -wasm-bindgen = "0.2.50" +wasm-bindgen = "0.2.51" [dependencies.web-sys] version = "0.3.27" diff --git a/web/src/lib.rs b/web/src/lib.rs index 04848d07..559a5af0 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -1,5 +1,4 @@ use dodrio::bumpalo; -use futures::Future; use std::cell::RefCell; mod bus; @@ -8,16 +7,13 @@ pub mod widget; pub use bus::Bus; pub use element::Element; -pub use iced_core::{Align, Color, Justify, Length}; +pub use iced_core::{Align, Background, Color, Justify, Length}; pub use widget::*; pub trait Application { type Message; - fn update( - &mut self, - message: Self::Message, - ) -> Option>>; + fn update(&mut self, message: Self::Message); fn view(&mut self) -> Element; @@ -48,10 +44,7 @@ impl Instance { } fn update(&mut self, message: Message) { - let mut ui = self.ui.borrow_mut(); - - // TODO: Resolve futures and publish resulting messages - let _ = ui.update(message); + self.ui.borrow_mut().update(message); } } -- cgit