summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-05 03:43:54 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-05 03:43:54 +0100
commitb68ac3aa47369df503360efec21cd7ca4ffa719a (patch)
treedfb8dcddf91a15b81656f0fc9fd020a501bbf6bd /core/src
parent81cfb863ab676204aee5f5d1ed0a2bd953833081 (diff)
parentda2717c74dbe3e1123ff41de345a409c1afc2f18 (diff)
downloadiced-b68ac3aa47369df503360efec21cd7ca4ffa719a.tar.gz
iced-b68ac3aa47369df503360efec21cd7ca4ffa719a.tar.bz2
iced-b68ac3aa47369df503360efec21cd7ca4ffa719a.zip
Merge branch 'master' into feature/performance-metrics
Diffstat (limited to 'core/src')
-rw-r--r--core/src/vector.rs21
-rw-r--r--core/src/widget/text_input.rs19
2 files changed, 17 insertions, 23 deletions
diff --git a/core/src/vector.rs b/core/src/vector.rs
index f45daab9..92bf64ff 100644
--- a/core/src/vector.rs
+++ b/core/src/vector.rs
@@ -1,15 +1,26 @@
/// A 2D vector.
#[derive(Debug, Clone, Copy, PartialEq)]
-pub struct Vector {
- pub x: f32,
- pub y: f32,
+pub struct Vector<T = f32> {
+ pub x: T,
+ pub y: T,
}
-impl Vector {
+impl<T> Vector<T> {
/// Creates a new [`Vector`] with the given components.
///
/// [`Vector`]: struct.Vector.html
- pub fn new(x: f32, y: f32) -> Self {
+ pub fn new(x: T, y: T) -> Self {
Self { x, y }
}
}
+
+impl<T> std::ops::Add for Vector<T>
+where
+ T: std::ops::Add<Output = T>,
+{
+ type Output = Self;
+
+ fn add(self, b: Self) -> Self {
+ Self::new(self.x + b.x, self.y + b.y)
+ }
+}
diff --git a/core/src/widget/text_input.rs b/core/src/widget/text_input.rs
index 6c7dff67..e5d6b70d 100644
--- a/core/src/widget/text_input.rs
+++ b/core/src/widget/text_input.rs
@@ -1,7 +1,5 @@
use crate::Length;
-use std::ops::{Index, RangeTo};
-
pub struct TextInput<'a, Message> {
pub state: &'a mut State,
pub placeholder: String,
@@ -93,13 +91,6 @@ impl State {
Self::default()
}
- pub fn focused() -> Self {
- Self {
- is_focused: true,
- ..Self::default()
- }
- }
-
pub fn move_cursor_right(&mut self, value: &Value) {
let current = self.cursor_position(value);
@@ -134,7 +125,7 @@ impl Value {
}
pub fn until(&self, index: usize) -> Self {
- Self(self.0[..index].iter().cloned().collect())
+ Self(self.0[..index.min(self.len())].iter().cloned().collect())
}
pub fn to_string(&self) -> String {
@@ -155,11 +146,3 @@ impl Value {
self.0.remove(index);
}
}
-
-impl Index<RangeTo<usize>> for Value {
- type Output = [char];
-
- fn index(&self, index: RangeTo<usize>) -> &[char] {
- &self.0[index]
- }
-}