summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/multitouch/src/main.rs2
-rw-r--r--graphics/src/geometry/path.rs13
-rw-r--r--graphics/src/geometry/path/builder.rs68
-rw-r--r--widget/src/text_editor.rs12
-rw-r--r--winit/src/program.rs4
5 files changed, 92 insertions, 7 deletions
diff --git a/examples/multitouch/src/main.rs b/examples/multitouch/src/main.rs
index a0105a8a..d5e5dffa 100644
--- a/examples/multitouch/src/main.rs
+++ b/examples/multitouch/src/main.rs
@@ -126,7 +126,7 @@ impl canvas::Program<Message> for Multitouch {
let path = builder.build();
- let color_r = (10 % zone.0) as f32 / 20.0;
+ let color_r = (10 % (zone.0 + 1)) as f32 / 20.0;
let color_g = (10 % (zone.0 + 8)) as f32 / 20.0;
let color_b = (10 % (zone.0 + 3)) as f32 / 20.0;
diff --git a/graphics/src/geometry/path.rs b/graphics/src/geometry/path.rs
index 3d8fc6fa..c4f51593 100644
--- a/graphics/src/geometry/path.rs
+++ b/graphics/src/geometry/path.rs
@@ -9,7 +9,8 @@ pub use builder::Builder;
pub use lyon_path;
-use iced_core::{Point, Size};
+use crate::core::border;
+use crate::core::{Point, Size};
/// An immutable set of points that may or may not be connected.
///
@@ -47,6 +48,16 @@ impl Path {
Self::new(|p| p.rectangle(top_left, size))
}
+ /// Creates a new [`Path`] representing a rounded rectangle given its top-left
+ /// corner coordinate, its [`Size`] and [`border::Radius`].
+ pub fn rounded_rectangle(
+ top_left: Point,
+ size: Size,
+ radius: border::Radius,
+ ) -> Self {
+ Self::new(|p| p.rounded_rectangle(top_left, size, radius))
+ }
+
/// Creates a new [`Path`] representing a circle given its center
/// coordinate and its radius.
pub fn circle(center: Point, radius: f32) -> Self {
diff --git a/graphics/src/geometry/path/builder.rs b/graphics/src/geometry/path/builder.rs
index 1ccd83f2..44410f6d 100644
--- a/graphics/src/geometry/path/builder.rs
+++ b/graphics/src/geometry/path/builder.rs
@@ -1,6 +1,7 @@
use crate::geometry::path::{arc, Arc, Path};
-use iced_core::{Point, Radians, Size};
+use crate::core::border;
+use crate::core::{Point, Radians, Size};
use lyon_path::builder::{self, SvgPathBuilder};
use lyon_path::geom;
@@ -160,6 +161,71 @@ impl Builder {
self.close();
}
+ /// Adds a rounded rectangle to the [`Path`] given its top-left
+ /// corner coordinate its [`Size`] and [`border::Radius`].
+ #[inline]
+ pub fn rounded_rectangle(
+ &mut self,
+ top_left: Point,
+ size: Size,
+ radius: border::Radius,
+ ) {
+ let min_size = (size.height / 2.0).min(size.width / 2.0);
+ let [top_left_corner, top_right_corner, bottom_right_corner, bottom_left_corner] =
+ radius.into();
+
+ self.move_to(Point::new(
+ top_left.x + min_size.min(top_left_corner),
+ top_left.y,
+ ));
+ self.line_to(Point::new(
+ top_left.x + size.width - min_size.min(top_right_corner),
+ top_left.y,
+ ));
+ self.arc_to(
+ Point::new(top_left.x + size.width, top_left.y),
+ Point::new(
+ top_left.x + size.width,
+ top_left.y + min_size.min(top_right_corner),
+ ),
+ min_size.min(top_right_corner),
+ );
+ self.line_to(Point::new(
+ top_left.x + size.width,
+ top_left.y + size.height - min_size.min(bottom_right_corner),
+ ));
+ self.arc_to(
+ Point::new(top_left.x + size.width, top_left.y + size.height),
+ Point::new(
+ top_left.x + size.width - min_size.min(bottom_right_corner),
+ top_left.y + size.height,
+ ),
+ min_size.min(bottom_right_corner),
+ );
+ self.line_to(Point::new(
+ top_left.x + min_size.min(bottom_left_corner),
+ top_left.y + size.height,
+ ));
+ self.arc_to(
+ Point::new(top_left.x, top_left.y + size.height),
+ Point::new(
+ top_left.x,
+ top_left.y + size.height - min_size.min(bottom_left_corner),
+ ),
+ min_size.min(bottom_left_corner),
+ );
+ self.line_to(Point::new(
+ top_left.x,
+ top_left.y + min_size.min(top_left_corner),
+ ));
+ self.arc_to(
+ Point::new(top_left.x, top_left.y),
+ Point::new(top_left.x + min_size.min(top_left_corner), top_left.y),
+ min_size.min(top_left_corner),
+ );
+ self.close();
+ }
+
/// Adds a circle to the [`Path`] given its center coordinate and its
/// radius.
#[inline]
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs
index e0102656..1df97962 100644
--- a/widget/src/text_editor.rs
+++ b/widget/src/text_editor.rs
@@ -109,6 +109,12 @@ where
self
}
+ /// Sets the width of the [`TextEditor`].
+ pub fn width(mut self, width: impl Into<Pixels>) -> Self {
+ self.width = Length::from(width.into());
+ self
+ }
+
/// Sets the message that should be produced when some action is performed in
/// the [`TextEditor`].
///
@@ -498,7 +504,7 @@ where
state.highlighter_settings = self.highlighter_settings.clone();
}
- let limits = limits.height(self.height);
+ let limits = limits.width(self.width).height(self.height);
internal.editor.update(
limits.shrink(self.padding).max(),
@@ -975,7 +981,9 @@ impl<Message> Binding<Message> {
keyboard::Key::Named(key::Named::Backspace) => {
Some(Self::Backspace)
}
- keyboard::Key::Named(key::Named::Delete) => Some(Self::Delete),
+ keyboard::Key::Named(key::Named::Delete) if text.is_none() => {
+ Some(Self::Delete)
+ }
keyboard::Key::Named(key::Named::Escape) => Some(Self::Unfocus),
keyboard::Key::Character("c") if modifiers.command() => {
Some(Self::Copy)
diff --git a/winit/src/program.rs b/winit/src/program.rs
index 52d8eb5f..eef7e6c6 100644
--- a/winit/src/program.rs
+++ b/winit/src/program.rs
@@ -219,7 +219,7 @@ where
}
runtime.track(subscription::into_recipes(
- program.subscription().map(Action::Output),
+ runtime.enter(|| program.subscription().map(Action::Output)),
));
let (boot_sender, boot_receiver) = oneshot::channel();
@@ -1169,7 +1169,7 @@ fn update<P: Program, E: Executor>(
}
}
- let subscription = program.subscription();
+ let subscription = runtime.enter(|| program.subscription());
runtime.track(subscription::into_recipes(subscription.map(Action::Output)));
}