summaryrefslogtreecommitdiffstats
path: root/web/src
diff options
context:
space:
mode:
Diffstat (limited to 'web/src')
-rw-r--r--web/src/hasher.rs21
-rw-r--r--web/src/lib.rs4
-rw-r--r--web/src/subscription.rs19
-rw-r--r--web/src/widget/button.rs4
-rw-r--r--web/src/widget/column.rs8
-rw-r--r--web/src/widget/container.rs2
-rw-r--r--web/src/widget/row.rs8
-rw-r--r--web/src/widget/text.rs7
-rw-r--r--web/src/widget/text_input.rs6
9 files changed, 71 insertions, 8 deletions
diff --git a/web/src/hasher.rs b/web/src/hasher.rs
new file mode 100644
index 00000000..1a28a2f9
--- /dev/null
+++ b/web/src/hasher.rs
@@ -0,0 +1,21 @@
+use std::collections::hash_map::DefaultHasher;
+
+/// The hasher used to compare subscriptions.
+#[derive(Debug)]
+pub struct Hasher(DefaultHasher);
+
+impl Default for Hasher {
+ fn default() -> Self {
+ Hasher(DefaultHasher::default())
+ }
+}
+
+impl core::hash::Hasher for Hasher {
+ fn write(&mut self, bytes: &[u8]) {
+ self.0.write(bytes)
+ }
+
+ fn finish(&self) -> u64 {
+ self.0.finish()
+ }
+}
diff --git a/web/src/lib.rs b/web/src/lib.rs
index 782bcf93..d4c422d2 100644
--- a/web/src/lib.rs
+++ b/web/src/lib.rs
@@ -61,18 +61,22 @@ use std::{cell::RefCell, rc::Rc};
mod bus;
mod element;
+mod hasher;
pub mod style;
+pub mod subscription;
pub mod widget;
pub use bus::Bus;
pub use dodrio;
pub use element::Element;
+pub use hasher::Hasher;
pub use iced_core::{
Align, Background, Color, Command, Font, HorizontalAlignment, Length,
VerticalAlignment,
};
pub use style::Style;
+pub use subscription::Subscription;
pub use widget::*;
/// An interactive web application.
diff --git a/web/src/subscription.rs b/web/src/subscription.rs
new file mode 100644
index 00000000..4638c8ab
--- /dev/null
+++ b/web/src/subscription.rs
@@ -0,0 +1,19 @@
+//! Listen to external events in your application.
+use crate::Hasher;
+
+/// A request to listen to external events.
+///
+/// Besides performing async actions on demand with [`Command`], most
+/// applications also need to listen to external events passively.
+///
+/// A [`Subscription`] is normally provided to some runtime, like a [`Command`],
+/// and it will generate events as long as the user keeps requesting it.
+///
+/// For instance, you can use a [`Subscription`] to listen to a WebSocket
+/// connection, keyboard presses, mouse events, time ticks, etc.
+///
+/// [`Command`]: ../struct.Command.html
+/// [`Subscription`]: struct.Subscription.html
+pub type Subscription<T> = iced_core::Subscription<Hasher, (), T>;
+
+pub use iced_core::subscription::Recipe;
diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs
index 4cc8b3de..e628bd18 100644
--- a/web/src/widget/button.rs
+++ b/web/src/widget/button.rs
@@ -130,6 +130,7 @@ where
) -> dodrio::Node<'b> {
use dodrio::builder::*;
+ let width = style::length(self.width);
let padding_class =
style_sheet.insert(bump, Style::Padding(self.padding));
@@ -149,9 +150,10 @@ where
"style",
bumpalo::format!(
in bump,
- "background: {}; border-radius: {}px; min-width: {}px",
+ "background: {}; border-radius: {}px; width:{}; min-width: {}px",
background,
self.border_radius,
+ width,
self.min_width
)
.into_bump_str(),
diff --git a/web/src/widget/column.rs b/web/src/widget/column.rs
index cc850f5f..e0e49148 100644
--- a/web/src/widget/column.rs
+++ b/web/src/widget/column.rs
@@ -133,6 +133,8 @@ impl<'a, Message> Widget<Message> for Column<'a, Message> {
let width = style::length(self.width);
let height = style::length(self.height);
+ let align_items = style::align(self.align_items);
+
// TODO: Complete styling
div(bump)
.attr(
@@ -142,10 +144,12 @@ impl<'a, Message> Widget<Message> for Column<'a, Message> {
)
.attr("style", bumpalo::format!(
in bump,
- "width: {}; height: {}; max-width: {}px",
+ "width: {}; height: {}; max-width: {}px; max-height: {}px; align-items: {}",
width,
height,
- self.max_width
+ self.max_width,
+ self.max_height,
+ align_items
).into_bump_str()
)
.children(children)
diff --git a/web/src/widget/container.rs b/web/src/widget/container.rs
index 25e4ebf8..bdc88979 100644
--- a/web/src/widget/container.rs
+++ b/web/src/widget/container.rs
@@ -134,7 +134,7 @@ where
impl<'a, Message> From<Container<'a, Message>> for Element<'a, Message>
where
- Message: 'static + Clone,
+ Message: 'static,
{
fn from(container: Container<'a, Message>) -> Element<'a, Message> {
Element::new(container)
diff --git a/web/src/widget/row.rs b/web/src/widget/row.rs
index e47478be..02754e2e 100644
--- a/web/src/widget/row.rs
+++ b/web/src/widget/row.rs
@@ -134,6 +134,8 @@ impl<'a, Message> Widget<Message> for Row<'a, Message> {
let width = style::length(self.width);
let height = style::length(self.height);
+ let justify_content = style::align(self.align_items);
+
// TODO: Complete styling
div(bump)
.attr(
@@ -143,10 +145,12 @@ impl<'a, Message> Widget<Message> for Row<'a, Message> {
)
.attr("style", bumpalo::format!(
in bump,
- "width: {}; height: {}; max-width: {}px",
+ "width: {}; height: {}; max-width: {}px; max-height: {}px; justify-content: {}",
width,
height,
- self.max_width
+ self.max_width,
+ self.max_height,
+ justify_content
).into_bump_str()
)
.children(children)
diff --git a/web/src/widget/text.rs b/web/src/widget/text.rs
index 6194a12e..2fdbc0a6 100644
--- a/web/src/widget/text.rs
+++ b/web/src/widget/text.rs
@@ -119,6 +119,9 @@ impl<'a, Message> Widget<Message> for Text {
let content = bumpalo::format!(in bump, "{}", self.content);
let color = style::color(self.color.unwrap_or(Color::BLACK));
+ let width = style::length(self.width);
+ let height = style::length(self.height);
+
let text_align = match self.horizontal_alignment {
HorizontalAlignment::Left => "left",
HorizontalAlignment::Center => "center",
@@ -127,7 +130,9 @@ impl<'a, Message> Widget<Message> for Text {
let style = bumpalo::format!(
in bump,
- "font-size: {}px; color: {}; text-align: {}",
+ "width: {}; height: {}; font-size: {}px; color: {}; text-align: {}",
+ width,
+ height,
self.size.unwrap_or(20),
color,
text_align
diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs
index d6357512..99792c84 100644
--- a/web/src/widget/text_input.rs
+++ b/web/src/widget/text_input.rs
@@ -128,6 +128,8 @@ where
use dodrio::builder::*;
use wasm_bindgen::JsCast;
+ let width = style::length(self.width);
+ let max_width = style::length(self.max_width);
let padding_class =
style_sheet.insert(bump, Style::Padding(self.padding));
@@ -143,7 +145,9 @@ where
"style",
bumpalo::format!(
in bump,
- "font-size: {}px",
+ "width: {}; max-width: {}; font-size: {}px",
+ width,
+ max_width,
self.size.unwrap_or(20)
)
.into_bump_str(),