summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-03-10 01:59:02 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-03-10 01:59:02 +0100
commit21971e0037c2ddcb96fd48ea96332445de4137bb (patch)
tree7cc1dc9147923a45c25f70d187cdecf08ab33497 /native
parent35425001edcb54d861a42ec6d23f9e57b37745fd (diff)
downloadiced-21971e0037c2ddcb96fd48ea96332445de4137bb.tar.gz
iced-21971e0037c2ddcb96fd48ea96332445de4137bb.tar.bz2
iced-21971e0037c2ddcb96fd48ea96332445de4137bb.zip
Make `Clipboard` argument in `Widget` trait mutable
Diffstat (limited to 'native')
-rw-r--r--native/src/clipboard.rs14
-rw-r--r--native/src/element.rs18
-rw-r--r--native/src/lib.rs2
-rw-r--r--native/src/overlay.rs4
-rw-r--r--native/src/overlay/element.rs12
-rw-r--r--native/src/overlay/menu.rs10
-rw-r--r--native/src/program/state.rs4
-rw-r--r--native/src/user_interface.rs16
-rw-r--r--native/src/widget.rs4
-rw-r--r--native/src/widget/button.rs6
-rw-r--r--native/src/widget/checkbox.rs4
-rw-r--r--native/src/widget/column.rs6
-rw-r--r--native/src/widget/container.rs6
-rw-r--r--native/src/widget/image/viewer.rs4
-rw-r--r--native/src/widget/pane_grid.rs6
-rw-r--r--native/src/widget/pane_grid/content.rs8
-rw-r--r--native/src/widget/pane_grid/title_bar.rs6
-rw-r--r--native/src/widget/pick_list.rs4
-rw-r--r--native/src/widget/radio.rs4
-rw-r--r--native/src/widget/row.rs6
-rw-r--r--native/src/widget/scrollable.rs6
-rw-r--r--native/src/widget/slider.rs4
-rw-r--r--native/src/widget/text_input.rs63
-rw-r--r--native/src/widget/text_input/cursor.rs21
-rw-r--r--native/src/widget/text_input/value.rs9
-rw-r--r--native/src/widget/tooltip.rs6
26 files changed, 140 insertions, 113 deletions
diff --git a/native/src/clipboard.rs b/native/src/clipboard.rs
index fdb769da..081b4004 100644
--- a/native/src/clipboard.rs
+++ b/native/src/clipboard.rs
@@ -1,3 +1,5 @@
+//! Access the clipboard.
+
/// A buffer for short-term storage and transfer within and between
/// applications.
pub trait Clipboard {
@@ -7,3 +9,15 @@ pub trait Clipboard {
/// Writes the given text contents to the [`Clipboard`].
fn write(&mut self, contents: String);
}
+
+/// A null implementation of the [`Clipboard`] trait.
+#[derive(Debug, Clone, Copy)]
+pub struct Null;
+
+impl Clipboard for Null {
+ fn read(&self) -> Option<String> {
+ None
+ }
+
+ fn write(&mut self, _contents: String) {}
+}
diff --git a/native/src/element.rs b/native/src/element.rs
index d6e9639a..5c84a388 100644
--- a/native/src/element.rs
+++ b/native/src/element.rs
@@ -223,17 +223,17 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
self.widget.on_event(
event,
layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
}
@@ -311,9 +311,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<B>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<B>,
) -> event::Status {
let mut original_messages = Vec::new();
@@ -321,9 +321,9 @@ where
event,
layout,
cursor_position,
- &mut original_messages,
renderer,
clipboard,
+ &mut original_messages,
);
original_messages
@@ -401,17 +401,17 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
self.element.widget.on_event(
event,
layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
}
diff --git a/native/src/lib.rs b/native/src/lib.rs
index 0890785b..20bbb1d0 100644
--- a/native/src/lib.rs
+++ b/native/src/lib.rs
@@ -33,6 +33,7 @@
#![deny(unused_results)]
#![forbid(unsafe_code)]
#![forbid(rust_2018_idioms)]
+pub mod clipboard;
pub mod event;
pub mod keyboard;
pub mod layout;
@@ -45,7 +46,6 @@ pub mod touch;
pub mod widget;
pub mod window;
-mod clipboard;
mod element;
mod hasher;
mod runtime;
diff --git a/native/src/overlay.rs b/native/src/overlay.rs
index ea8bb384..84145e7f 100644
--- a/native/src/overlay.rs
+++ b/native/src/overlay.rs
@@ -67,9 +67,9 @@ where
_event: Event,
_layout: Layout<'_>,
_cursor_position: Point,
- _messages: &mut Vec<Message>,
_renderer: &Renderer,
- _clipboard: Option<&dyn Clipboard>,
+ _clipboard: &mut dyn Clipboard,
+ _messages: &mut Vec<Message>,
) -> event::Status {
event::Status::Ignored
}
diff --git a/native/src/overlay/element.rs b/native/src/overlay/element.rs
index 0f44a781..e4819037 100644
--- a/native/src/overlay/element.rs
+++ b/native/src/overlay/element.rs
@@ -53,17 +53,17 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
self.overlay.on_event(
event,
layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
}
@@ -117,9 +117,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<B>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<B>,
) -> event::Status {
let mut original_messages = Vec::new();
@@ -127,9 +127,9 @@ where
event,
layout,
cursor_position,
- &mut original_messages,
renderer,
clipboard,
+ &mut original_messages,
);
original_messages
diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs
index 5ad1391f..afb17bd3 100644
--- a/native/src/overlay/menu.rs
+++ b/native/src/overlay/menu.rs
@@ -219,17 +219,17 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
self.container.on_event(
event.clone(),
layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
}
@@ -320,9 +320,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- _messages: &mut Vec<Message>,
renderer: &Renderer,
- _clipboard: Option<&dyn Clipboard>,
+ _clipboard: &mut dyn Clipboard,
+ _messages: &mut Vec<Message>,
) -> event::Status {
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
diff --git a/native/src/program/state.rs b/native/src/program/state.rs
index e630890a..3f5f6069 100644
--- a/native/src/program/state.rs
+++ b/native/src/program/state.rs
@@ -91,8 +91,8 @@ where
&mut self,
bounds: Size,
cursor_position: Point,
- clipboard: Option<&dyn Clipboard>,
renderer: &mut P::Renderer,
+ clipboard: &mut dyn Clipboard,
debug: &mut Debug,
) -> Option<Command<P::Message>> {
let mut user_interface = build_user_interface(
@@ -109,8 +109,8 @@ where
let _ = user_interface.update(
&self.queued_events,
cursor_position,
- clipboard,
renderer,
+ clipboard,
&mut messages,
);
diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs
index 7a64ac59..475faf8d 100644
--- a/native/src/user_interface.rs
+++ b/native/src/user_interface.rs
@@ -134,7 +134,7 @@ where
/// completing [the previous example](#example):
///
/// ```no_run
- /// use iced_native::{UserInterface, Cache, Size, Point};
+ /// use iced_native::{clipboard, UserInterface, Cache, Size, Point};
/// use iced_wgpu::Renderer;
///
/// # mod iced_wgpu {
@@ -157,6 +157,7 @@ where
/// let mut renderer = Renderer::new();
/// let mut window_size = Size::new(1024.0, 768.0);
/// let mut cursor_position = Point::default();
+ /// let mut clipboard = clipboard::Null;
///
/// // Initialize our event storage
/// let mut events = Vec::new();
@@ -176,8 +177,8 @@ where
/// let event_statuses = user_interface.update(
/// &events,
/// cursor_position,
- /// None,
/// &renderer,
+ /// &mut clipboard,
/// &mut messages
/// );
///
@@ -193,8 +194,8 @@ where
&mut self,
events: &[Event],
cursor_position: Point,
- clipboard: Option<&dyn Clipboard>,
renderer: &Renderer,
+ clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>,
) -> Vec<event::Status> {
let (base_cursor, overlay_statuses) = if let Some(mut overlay) =
@@ -215,9 +216,9 @@ where
event,
Layout::new(&layer.layout),
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
})
.collect();
@@ -246,9 +247,9 @@ where
event,
Layout::new(&self.base.layout),
base_cursor,
- messages,
renderer,
clipboard,
+ messages,
);
event_status.merge(overlay_status)
@@ -269,7 +270,7 @@ where
/// [completing the last example](#example-1):
///
/// ```no_run
- /// use iced_native::{UserInterface, Cache, Size, Point};
+ /// use iced_native::{clipboard, UserInterface, Cache, Size, Point};
/// use iced_wgpu::Renderer;
///
/// # mod iced_wgpu {
@@ -292,6 +293,7 @@ where
/// let mut renderer = Renderer::new();
/// let mut window_size = Size::new(1024.0, 768.0);
/// let mut cursor_position = Point::default();
+ /// let mut clipboard = clipboard::Null;
/// let mut events = Vec::new();
/// let mut messages = Vec::new();
///
@@ -309,8 +311,8 @@ where
/// let event_statuses = user_interface.update(
/// &events,
/// cursor_position,
- /// None,
/// &renderer,
+ /// &mut clipboard,
/// &mut messages
/// );
///
diff --git a/native/src/widget.rs b/native/src/widget.rs
index d5c353df..791c53a3 100644
--- a/native/src/widget.rs
+++ b/native/src/widget.rs
@@ -164,9 +164,9 @@ where
_event: Event,
_layout: Layout<'_>,
_cursor_position: Point,
- _messages: &mut Vec<Message>,
_renderer: &Renderer,
- _clipboard: Option<&dyn Clipboard>,
+ _clipboard: &mut dyn Clipboard,
+ _messages: &mut Vec<Message>,
) -> event::Status {
event::Status::Ignored
}
diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs
index b8c14634..59d6e219 100644
--- a/native/src/widget/button.rs
+++ b/native/src/widget/button.rs
@@ -160,17 +160,17 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
if let event::Status::Captured = self.content.on_event(
event.clone(),
layout.children().next().unwrap(),
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
) {
return event::Status::Captured;
}
diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs
index 77a82fad..6ce2e973 100644
--- a/native/src/widget/checkbox.rs
+++ b/native/src/widget/checkbox.rs
@@ -150,9 +150,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
_renderer: &Renderer,
- _clipboard: Option<&dyn Clipboard>,
+ _clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs
index e0e88d31..d7f0365a 100644
--- a/native/src/widget/column.rs
+++ b/native/src/widget/column.rs
@@ -141,9 +141,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
self.children
.iter_mut()
@@ -153,9 +153,9 @@ where
event.clone(),
layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
})
.fold(event::Status::Ignored, event::Status::merge)
diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs
index 65764148..69fe699b 100644
--- a/native/src/widget/container.rs
+++ b/native/src/widget/container.rs
@@ -151,17 +151,17 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
self.content.widget.on_event(
event,
layout.children().next().unwrap(),
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
}
diff --git a/native/src/widget/image/viewer.rs b/native/src/widget/image/viewer.rs
index 5f0dda4e..a006c0af 100644
--- a/native/src/widget/image/viewer.rs
+++ b/native/src/widget/image/viewer.rs
@@ -155,9 +155,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- _messages: &mut Vec<Message>,
renderer: &Renderer,
- _clipboard: Option<&dyn Clipboard>,
+ _clipboard: &mut dyn Clipboard,
+ _messages: &mut Vec<Message>,
) -> event::Status {
let bounds = layout.bounds();
let is_mouse_over = bounds.contains(cursor_position);
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index c6fe4b60..9a3580e0 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -362,9 +362,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
let mut event_status = event::Status::Ignored;
@@ -461,9 +461,9 @@ where
event.clone(),
layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
})
.fold(event_status, event::Status::merge)
diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs
index 913cfe96..a5493fe2 100644
--- a/native/src/widget/pane_grid/content.rs
+++ b/native/src/widget/pane_grid/content.rs
@@ -143,9 +143,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
let mut event_status = event::Status::Ignored;
@@ -156,9 +156,9 @@ where
event.clone(),
children.next().unwrap(),
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
);
children.next().unwrap()
@@ -170,9 +170,9 @@ where
event,
body_layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
);
event_status.merge(body_status)
diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs
index 2f9659e8..ff689ddb 100644
--- a/native/src/widget/pane_grid/title_bar.rs
+++ b/native/src/widget/pane_grid/title_bar.rs
@@ -199,9 +199,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
if let Some(controls) = &mut self.controls {
let mut children = layout.children();
@@ -215,9 +215,9 @@ where
event,
controls_layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
} else {
event::Status::Ignored
diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs
index 74f4508e..046d5779 100644
--- a/native/src/widget/pick_list.rs
+++ b/native/src/widget/pick_list.rs
@@ -210,9 +210,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
_renderer: &Renderer,
- _clipboard: Option<&dyn Clipboard>,
+ _clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs
index 69952345..9482a9b1 100644
--- a/native/src/widget/radio.rs
+++ b/native/src/widget/radio.rs
@@ -156,9 +156,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
_renderer: &Renderer,
- _clipboard: Option<&dyn Clipboard>,
+ _clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs
index b71663bd..5634ab12 100644
--- a/native/src/widget/row.rs
+++ b/native/src/widget/row.rs
@@ -140,9 +140,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
self.children
.iter_mut()
@@ -152,9 +152,9 @@ where
event.clone(),
layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
})
.fold(event::Status::Ignored, event::Status::merge)
diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs
index 18cdf169..70ebebe2 100644
--- a/native/src/widget/scrollable.rs
+++ b/native/src/widget/scrollable.rs
@@ -162,9 +162,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
let bounds = layout.bounds();
let is_mouse_over = bounds.contains(cursor_position);
@@ -205,9 +205,9 @@ where
event.clone(),
content,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
};
diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs
index 010c6e53..2a74d5a3 100644
--- a/native/src/widget/slider.rs
+++ b/native/src/widget/slider.rs
@@ -180,9 +180,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
_renderer: &Renderer,
- _clipboard: Option<&dyn Clipboard>,
+ _clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
let mut change = || {
let bounds = layout.bounds();
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index 4c38b1a3..400cae2a 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -243,9 +243,9 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
@@ -503,43 +503,42 @@ where
}
keyboard::KeyCode::V => {
if self.state.keyboard_modifiers.is_command_pressed() {
- if let Some(clipboard) = clipboard {
- let content = match self.state.is_pasting.take()
- {
- Some(content) => content,
- None => {
- let content: String = clipboard
- .read()
- .unwrap_or(String::new())
- .chars()
- .filter(|c| !c.is_control())
- .collect();
-
- Value::new(&content)
- }
- };
-
- let mut editor = Editor::new(
- &mut self.value,
- &mut self.state.cursor,
- );
+ let content = match self.state.is_pasting.take() {
+ Some(content) => content,
+ None => {
+ let content: String = clipboard
+ .read()
+ .unwrap_or(String::new())
+ .chars()
+ .filter(|c| !c.is_control())
+ .collect();
+
+ Value::new(&content)
+ }
+ };
+
+ let mut editor = Editor::new(
+ &mut self.value,
+ &mut self.state.cursor,
+ );
- editor.paste(content.clone());
+ editor.paste(content.clone());
- let message =
- (self.on_change)(editor.contents());
- messages.push(message);
+ let message = (self.on_change)(editor.contents());
+ messages.push(message);
- self.state.is_pasting = Some(content);
- }
+ self.state.is_pasting = Some(content);
} else {
self.state.is_pasting = None;
}
}
- keyboard::KeyCode::A => {
- if self.state.keyboard_modifiers.is_command_pressed() {
- self.state.cursor.select_all(&self.value);
- }
+ keyboard::KeyCode::A
+ if self
+ .state
+ .keyboard_modifiers
+ .is_command_pressed() =>
+ {
+ self.state.cursor.select_all(&self.value);
}
keyboard::KeyCode::Escape => {
self.state.is_focused = false;
diff --git a/native/src/widget/text_input/cursor.rs b/native/src/widget/text_input/cursor.rs
index e630e293..1e7aee83 100644
--- a/native/src/widget/text_input/cursor.rs
+++ b/native/src/widget/text_input/cursor.rs
@@ -48,6 +48,18 @@ impl Cursor {
}
}
+ /// Returns the current selection of the [`Cursor`] for the given [`Value`].
+ ///
+ /// `start` is guaranteed to be <= than `end`.
+ pub fn selection(&self, value: &Value) -> Option<(usize, usize)> {
+ match self.state(value) {
+ State::Selection { start, end } => {
+ Some((start.min(end), start.max(end)))
+ }
+ _ => None,
+ }
+ }
+
pub(crate) fn move_to(&mut self, position: usize) {
self.state = State::Index(position);
}
@@ -161,15 +173,6 @@ impl Cursor {
end.min(value.len())
}
- pub(crate) fn selection(&self, value: &Value) -> Option<(usize, usize)> {
- match self.state(value) {
- State::Selection { start, end } => {
- Some((start.min(end), start.max(end)))
- }
- _ => None,
- }
- }
-
fn left(&self, value: &Value) -> usize {
match self.state(value) {
State::Index(index) => index,
diff --git a/native/src/widget/text_input/value.rs b/native/src/widget/text_input/value.rs
index 86be2790..2034cca4 100644
--- a/native/src/widget/text_input/value.rs
+++ b/native/src/widget/text_input/value.rs
@@ -73,6 +73,15 @@ impl Value {
.unwrap_or(self.len())
}
+ /// Returns a new [`Value`] containing the graphemes from `start` until the
+ /// given `end`.
+ pub fn select(&self, start: usize, end: usize) -> Self {
+ let graphemes =
+ self.graphemes[start.min(self.len())..end.min(self.len())].to_vec();
+
+ Self { graphemes }
+ }
+
/// Returns a new [`Value`] containing the graphemes until the given
/// `index`.
pub fn until(&self, index: usize) -> Self {
diff --git a/native/src/widget/tooltip.rs b/native/src/widget/tooltip.rs
index ab07868c..276afd41 100644
--- a/native/src/widget/tooltip.rs
+++ b/native/src/widget/tooltip.rs
@@ -120,17 +120,17 @@ where
event: Event,
layout: Layout<'_>,
cursor_position: Point,
- messages: &mut Vec<Message>,
renderer: &Renderer,
- clipboard: Option<&dyn Clipboard>,
+ clipboard: &mut dyn Clipboard,
+ messages: &mut Vec<Message>,
) -> event::Status {
self.content.widget.on_event(
event,
layout,
cursor_position,
- messages,
renderer,
clipboard,
+ messages,
)
}