From ba470a2b2a334fa961af19ef9412ad2dfb4acbeb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 5 Nov 2019 02:58:42 +0100 Subject: Remove unnecessary code in `Value` --- core/src/widget/text_input.rs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'core/src') 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> for Value { - type Output = [char]; - - fn index(&self, index: RangeTo) -> &[char] { - &self.0[index] - } -} -- cgit From 470266f54069a1c9b6147026d018b437b6457f7b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 5 Nov 2019 03:16:46 +0100 Subject: Add horizontal offset to `Primitive::Clip` --- core/src/vector.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'core/src') 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 { + pub x: T, + pub y: T, } -impl Vector { +impl Vector { /// 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 std::ops::Add for Vector +where + T: std::ops::Add, +{ + type Output = Self; + + fn add(self, b: Self) -> Self { + Self::new(self.x + b.x, self.y + b.y) + } +} -- cgit