summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-05 06:10:13 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-05 06:10:13 +0100
commitd575f4541126e2ab25908fe55c6805f16716b2a5 (patch)
tree9d5221fe201b64e2ec649228ebae26be819dbf58 /native
parente92ea48e8814b42fc566017db085ca9bdaf3c272 (diff)
downloadiced-d575f4541126e2ab25908fe55c6805f16716b2a5.tar.gz
iced-d575f4541126e2ab25908fe55c6805f16716b2a5.tar.bz2
iced-d575f4541126e2ab25908fe55c6805f16716b2a5.zip
Draft first version of event subscriptions :tada:
Diffstat (limited to 'native')
-rw-r--r--native/Cargo.toml2
-rw-r--r--native/src/lib.rs4
-rw-r--r--native/src/widget/checkbox.rs15
3 files changed, 16 insertions, 5 deletions
diff --git a/native/Cargo.toml b/native/Cargo.toml
index 7993676e..c5f9c7ac 100644
--- a/native/Cargo.toml
+++ b/native/Cargo.toml
@@ -8,6 +8,6 @@ license = "MIT"
repository = "https://github.com/hecrj/iced"
[dependencies]
-iced_core = { version = "0.1.0", path = "../core", features = ["command"] }
+iced_core = { version = "0.1.0", path = "../core", features = ["command", "subscription"] }
twox-hash = "1.5"
raw-window-handle = "0.3"
diff --git a/native/src/lib.rs b/native/src/lib.rs
index 45c3c699..9afb3bc9 100644
--- a/native/src/lib.rs
+++ b/native/src/lib.rs
@@ -52,8 +52,8 @@ mod size;
mod user_interface;
pub use iced_core::{
- Align, Background, Color, Command, Font, HorizontalAlignment, Length,
- Point, Rectangle, Vector, VerticalAlignment,
+ subscription, Align, Background, Color, Command, Font, HorizontalAlignment,
+ Length, Point, Rectangle, Subscription, Vector, VerticalAlignment,
};
pub use element::Element;
diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs
index 9563291c..159cba84 100644
--- a/native/src/widget/checkbox.rs
+++ b/native/src/widget/checkbox.rs
@@ -31,6 +31,7 @@ pub struct Checkbox<Message> {
on_toggle: Box<dyn Fn(bool) -> Message>,
label: String,
label_color: Option<Color>,
+ width: Length,
}
impl<Message> Checkbox<Message> {
@@ -53,6 +54,7 @@ impl<Message> Checkbox<Message> {
on_toggle: Box::new(f),
label: String::from(label),
label_color: None,
+ width: Length::Fill,
}
}
@@ -63,6 +65,14 @@ impl<Message> Checkbox<Message> {
self.label_color = Some(color.into());
self
}
+
+ /// Sets the width of the [`Checkbox`].
+ ///
+ /// [`Checkbox`]: struct.Checkbox.html
+ pub fn width(mut self, width: Length) -> Self {
+ self.width = width;
+ self
+ }
}
impl<Message, Renderer> Widget<Message, Renderer> for Checkbox<Message>
@@ -70,7 +80,7 @@ where
Renderer: self::Renderer + text::Renderer + row::Renderer,
{
fn width(&self) -> Length {
- Length::Fill
+ Length::Shrink
}
fn height(&self) -> Length {
@@ -85,6 +95,7 @@ where
let size = self::Renderer::default_size(renderer);
Row::<(), Renderer>::new()
+ .width(self.width)
.spacing(15)
.align_items(Align::Center)
.push(
@@ -92,7 +103,7 @@ where
.width(Length::Units(size as u16))
.height(Length::Units(size as u16)),
)
- .push(Text::new(&self.label))
+ .push(Text::new(&self.label).width(self.width))
.layout(renderer, limits)
}