summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-10-27 03:58:45 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-10-27 03:58:45 +0200
commit65823875791ecebf24d049cc0782e7475a37899b (patch)
tree1088c656ef7ad9782374952045022d2c104931b2 /widget
parent8cc19de254c37d3123d5ea1b6513f1f34d35c7c8 (diff)
parentf1b1344d59fa7354615f560bd25ed01ad0c9f865 (diff)
downloadiced-65823875791ecebf24d049cc0782e7475a37899b.tar.gz
iced-65823875791ecebf24d049cc0782e7475a37899b.tar.bz2
iced-65823875791ecebf24d049cc0782e7475a37899b.zip
Merge branch 'master' into text-editor
Diffstat (limited to 'widget')
-rw-r--r--widget/src/button.rs2
-rw-r--r--widget/src/column.rs2
-rw-r--r--widget/src/image.rs6
-rw-r--r--widget/src/image/viewer.rs2
-rw-r--r--widget/src/keyed/column.rs2
-rw-r--r--widget/src/lazy.rs6
-rw-r--r--widget/src/lazy/component.rs2
-rw-r--r--widget/src/lazy/responsive.rs4
-rw-r--r--widget/src/lib.rs6
-rw-r--r--widget/src/pane_grid.rs29
-rw-r--r--widget/src/pane_grid/node.rs14
-rw-r--r--widget/src/pane_grid/state.rs70
-rw-r--r--widget/src/pane_grid/title_bar.rs4
-rw-r--r--widget/src/pick_list.rs4
-rw-r--r--widget/src/row.rs4
-rw-r--r--widget/src/scrollable.rs36
-rw-r--r--widget/src/slider.rs2
-rw-r--r--widget/src/text_input.rs24
-rw-r--r--widget/src/text_input/cursor.rs26
-rw-r--r--widget/src/text_input/value.rs11
-rw-r--r--widget/src/toggler.rs2
-rw-r--r--widget/src/tooltip.rs2
-rw-r--r--widget/src/vertical_slider.rs2
23 files changed, 127 insertions, 135 deletions
diff --git a/widget/src/button.rs b/widget/src/button.rs
index 4915bd49..384a3156 100644
--- a/widget/src/button.rs
+++ b/widget/src/button.rs
@@ -146,7 +146,7 @@ where
}
fn diff(&self, tree: &mut Tree) {
- tree.diff_children(std::slice::from_ref(&self.content))
+ tree.diff_children(std::slice::from_ref(&self.content));
}
fn width(&self) -> Length {
diff --git a/widget/src/column.rs b/widget/src/column.rs
index f2347cc9..42e90ac1 100644
--- a/widget/src/column.rs
+++ b/widget/src/column.rs
@@ -159,7 +159,7 @@ where
child
.as_widget()
.operate(state, layout, renderer, operation);
- })
+ });
});
}
diff --git a/widget/src/image.rs b/widget/src/image.rs
index 3c83c87b..a0e89920 100644
--- a/widget/src/image.rs
+++ b/widget/src/image.rs
@@ -141,14 +141,14 @@ pub fn draw<Renderer, Handle>(
..bounds
};
- renderer.draw(handle.clone(), drawing_bounds + offset)
+ renderer.draw(handle.clone(), drawing_bounds + offset);
};
if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height
{
renderer.with_layer(bounds, render);
} else {
- render(renderer)
+ render(renderer);
}
}
@@ -191,7 +191,7 @@ where
_cursor: mouse::Cursor,
_viewport: &Rectangle,
) {
- draw(renderer, layout, &self.handle, self.content_fit)
+ draw(renderer, layout, &self.handle, self.content_fit);
}
}
diff --git a/widget/src/image/viewer.rs b/widget/src/image/viewer.rs
index 724d121e..44624fc8 100644
--- a/widget/src/image/viewer.rs
+++ b/widget/src/image/viewer.rs
@@ -334,7 +334,7 @@ where
y: bounds.y,
..Rectangle::with_size(image_size)
},
- )
+ );
});
});
}
diff --git a/widget/src/keyed/column.rs b/widget/src/keyed/column.rs
index 19016679..0ef82407 100644
--- a/widget/src/keyed/column.rs
+++ b/widget/src/keyed/column.rs
@@ -220,7 +220,7 @@ where
child
.as_widget()
.operate(state, layout, renderer, operation);
- })
+ });
});
}
diff --git a/widget/src/lazy.rs b/widget/src/lazy.rs
index bf695a57..589dd938 100644
--- a/widget/src/lazy.rs
+++ b/widget/src/lazy.rs
@@ -135,7 +135,7 @@ where
(*self.element.borrow_mut()) = Some(current.element.clone());
self.with_element(|element| {
- tree.diff_children(std::slice::from_ref(&element.as_widget()))
+ tree.diff_children(std::slice::from_ref(&element.as_widget()));
});
} else {
(*self.element.borrow_mut()) = Some(current.element.clone());
@@ -243,8 +243,8 @@ where
layout,
cursor,
viewport,
- )
- })
+ );
+ });
}
fn overlay<'b>(
diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs
index fe99a7f2..d454b72b 100644
--- a/widget/src/lazy/component.rs
+++ b/widget/src/lazy/component.rs
@@ -511,7 +511,7 @@ impl<'a, 'b, Message, Renderer, Event, S> Drop
for Overlay<'a, 'b, Message, Renderer, Event, S>
{
fn drop(&mut self) {
- if let Some(heads) = self.0.take().map(|inner| inner.into_heads()) {
+ if let Some(heads) = self.0.take().map(Inner::into_heads) {
*heads.instance.tree.borrow_mut().borrow_mut() = Some(heads.tree);
}
}
diff --git a/widget/src/lazy/responsive.rs b/widget/src/lazy/responsive.rs
index 0b819455..ed471988 100644
--- a/widget/src/lazy/responsive.rs
+++ b/widget/src/lazy/responsive.rs
@@ -240,9 +240,9 @@ where
|tree, renderer, layout, element| {
element.as_widget().draw(
tree, renderer, theme, style, layout, cursor, viewport,
- )
+ );
},
- )
+ );
}
fn mouse_interaction(
diff --git a/widget/src/lib.rs b/widget/src/lib.rs
index 4c318d75..97e4ac58 100644
--- a/widget/src/lib.rs
+++ b/widget/src/lib.rs
@@ -7,14 +7,8 @@
// missing_debug_implementations,
// missing_docs,
unused_results,
- clippy::extra_unused_lifetimes,
- clippy::from_over_into,
- clippy::needless_borrow,
- clippy::new_without_default,
- clippy::useless_conversion,
rustdoc::broken_intra_doc_links
)]
-#![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub use iced_renderer as renderer;
pub use iced_renderer::graphics;
diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs
index f868a648..2d25a543 100644
--- a/widget/src/pane_grid.rs
+++ b/widget/src/pane_grid.rs
@@ -308,7 +308,7 @@ where
.zip(layout.children())
.for_each(|(((_pane, content), state), layout)| {
content.operate(state, layout, renderer, operation);
- })
+ });
});
}
@@ -436,7 +436,7 @@ where
tree, renderer, theme, style, layout, cursor, rectangle,
);
},
- )
+ );
}
fn overlay<'b>(
@@ -606,11 +606,10 @@ pub fn update<'a, Message, T: Draggable>(
} else {
let dropped_region = contents
.zip(layout.children())
- .filter_map(|(target, layout)| {
+ .find_map(|(target, layout)| {
layout_region(layout, cursor_position)
.map(|region| (target, region))
- })
- .next();
+ });
match dropped_region {
Some(((target, _), region))
@@ -1151,21 +1150,19 @@ pub struct ResizeEvent {
* Helpers
*/
fn hovered_split<'a>(
- splits: impl Iterator<Item = (&'a Split, &'a (Axis, Rectangle, f32))>,
+ mut splits: impl Iterator<Item = (&'a Split, &'a (Axis, Rectangle, f32))>,
spacing: f32,
cursor_position: Point,
) -> Option<(Split, Axis, Rectangle)> {
- splits
- .filter_map(|(split, (axis, region, ratio))| {
- let bounds = axis.split_line_bounds(*region, *ratio, spacing);
+ splits.find_map(|(split, (axis, region, ratio))| {
+ let bounds = axis.split_line_bounds(*region, *ratio, spacing);
- if bounds.contains(cursor_position) {
- Some((*split, *axis, bounds))
- } else {
- None
- }
- })
- .next()
+ if bounds.contains(cursor_position) {
+ Some((*split, *axis, bounds))
+ } else {
+ None
+ }
+ })
}
/// The visible contents of the [`PaneGrid`]
diff --git a/widget/src/pane_grid/node.rs b/widget/src/pane_grid/node.rs
index 3c707f15..1f568f95 100644
--- a/widget/src/pane_grid/node.rs
+++ b/widget/src/pane_grid/node.rs
@@ -95,13 +95,13 @@ impl Node {
splits
}
- pub(crate) fn find(&mut self, pane: &Pane) -> Option<&mut Node> {
+ pub(crate) fn find(&mut self, pane: Pane) -> Option<&mut Node> {
match self {
Node::Split { a, b, .. } => {
a.find(pane).or_else(move || b.find(pane))
}
Node::Pane(p) => {
- if p == pane {
+ if *p == pane {
Some(self)
} else {
None
@@ -139,12 +139,12 @@ impl Node {
f(self);
}
- pub(crate) fn resize(&mut self, split: &Split, percentage: f32) -> bool {
+ pub(crate) fn resize(&mut self, split: Split, percentage: f32) -> bool {
match self {
Node::Split {
id, ratio, a, b, ..
} => {
- if id == split {
+ if *id == split {
*ratio = percentage;
true
@@ -158,13 +158,13 @@ impl Node {
}
}
- pub(crate) fn remove(&mut self, pane: &Pane) -> Option<Pane> {
+ pub(crate) fn remove(&mut self, pane: Pane) -> Option<Pane> {
match self {
Node::Split { a, b, .. } => {
- if a.pane() == Some(*pane) {
+ if a.pane() == Some(pane) {
*self = *b.clone();
Some(self.first_pane())
- } else if b.pane() == Some(*pane) {
+ } else if b.pane() == Some(pane) {
*self = *a.clone();
Some(self.first_pane())
} else {
diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs
index 28a52cf0..481cd770 100644
--- a/widget/src/pane_grid/state.rs
+++ b/widget/src/pane_grid/state.rs
@@ -75,14 +75,14 @@ impl<T> State<T> {
}
/// Returns the internal state of the given [`Pane`], if it exists.
- pub fn get(&self, pane: &Pane) -> Option<&T> {
- self.panes.get(pane)
+ pub fn get(&self, pane: Pane) -> Option<&T> {
+ self.panes.get(&pane)
}
/// Returns the internal state of the given [`Pane`] with mutability, if it
/// exists.
- pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T> {
- self.panes.get_mut(pane)
+ pub fn get_mut(&mut self, pane: Pane) -> Option<&mut T> {
+ self.panes.get_mut(&pane)
}
/// Returns an iterator over all the panes of the [`State`], alongside its
@@ -104,13 +104,13 @@ impl<T> State<T> {
/// Returns the adjacent [`Pane`] of another [`Pane`] in the given
/// direction, if there is one.
- pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option<Pane> {
+ pub fn adjacent(&self, pane: Pane, direction: Direction) -> Option<Pane> {
let regions = self
.internal
.layout
.pane_regions(0.0, Size::new(4096.0, 4096.0));
- let current_region = regions.get(pane)?;
+ let current_region = regions.get(&pane)?;
let target = match direction {
Direction::Left => {
@@ -142,7 +142,7 @@ impl<T> State<T> {
pub fn split(
&mut self,
axis: Axis,
- pane: &Pane,
+ pane: Pane,
state: T,
) -> Option<(Pane, Split)> {
self.split_node(axis, Some(pane), state, false)
@@ -151,32 +151,32 @@ impl<T> State<T> {
/// Split a target [`Pane`] with a given [`Pane`] on a given [`Region`].
///
/// Panes will be swapped by default for [`Region::Center`].
- pub fn split_with(&mut self, target: &Pane, pane: &Pane, region: Region) {
+ pub fn split_with(&mut self, target: Pane, pane: Pane, region: Region) {
match region {
Region::Center => self.swap(pane, target),
Region::Edge(edge) => match edge {
Edge::Top => {
- self.split_and_swap(Axis::Horizontal, target, pane, true)
+ self.split_and_swap(Axis::Horizontal, target, pane, true);
}
Edge::Bottom => {
- self.split_and_swap(Axis::Horizontal, target, pane, false)
+ self.split_and_swap(Axis::Horizontal, target, pane, false);
}
Edge::Left => {
- self.split_and_swap(Axis::Vertical, target, pane, true)
+ self.split_and_swap(Axis::Vertical, target, pane, true);
}
Edge::Right => {
- self.split_and_swap(Axis::Vertical, target, pane, false)
+ self.split_and_swap(Axis::Vertical, target, pane, false);
}
},
}
}
/// Drops the given [`Pane`] into the provided [`Target`].
- pub fn drop(&mut self, pane: &Pane, target: Target) {
+ pub fn drop(&mut self, pane: Pane, target: Target) {
match target {
Target::Edge(edge) => self.move_to_edge(pane, edge),
Target::Pane(target, region) => {
- self.split_with(&target, pane, region)
+ self.split_with(target, pane, region);
}
}
}
@@ -184,7 +184,7 @@ impl<T> State<T> {
fn split_node(
&mut self,
axis: Axis,
- pane: Option<&Pane>,
+ pane: Option<Pane>,
state: T,
inverse: bool,
) -> Option<(Pane, Split)> {
@@ -222,14 +222,14 @@ impl<T> State<T> {
fn split_and_swap(
&mut self,
axis: Axis,
- target: &Pane,
- pane: &Pane,
+ target: Pane,
+ pane: Pane,
swap: bool,
) {
if let Some((state, _)) = self.close(pane) {
if let Some((new_pane, _)) = self.split(axis, target, state) {
if swap {
- self.swap(target, &new_pane);
+ self.swap(target, new_pane);
}
}
}
@@ -238,19 +238,19 @@ impl<T> State<T> {
/// Move [`Pane`] to an [`Edge`] of the [`PaneGrid`].
///
/// [`PaneGrid`]: super::PaneGrid
- pub fn move_to_edge(&mut self, pane: &Pane, edge: Edge) {
+ pub fn move_to_edge(&mut self, pane: Pane, edge: Edge) {
match edge {
Edge::Top => {
- self.split_major_node_and_swap(Axis::Horizontal, pane, true)
+ self.split_major_node_and_swap(Axis::Horizontal, pane, true);
}
Edge::Bottom => {
- self.split_major_node_and_swap(Axis::Horizontal, pane, false)
+ self.split_major_node_and_swap(Axis::Horizontal, pane, false);
}
Edge::Left => {
- self.split_major_node_and_swap(Axis::Vertical, pane, true)
+ self.split_major_node_and_swap(Axis::Vertical, pane, true);
}
Edge::Right => {
- self.split_major_node_and_swap(Axis::Vertical, pane, false)
+ self.split_major_node_and_swap(Axis::Vertical, pane, false);
}
}
}
@@ -258,7 +258,7 @@ impl<T> State<T> {
fn split_major_node_and_swap(
&mut self,
axis: Axis,
- pane: &Pane,
+ pane: Pane,
swap: bool,
) {
if let Some((state, _)) = self.close(pane) {
@@ -273,14 +273,14 @@ impl<T> State<T> {
///
/// [`PaneGrid`]: super::PaneGrid
/// [`DragEvent`]: super::DragEvent
- pub fn swap(&mut self, a: &Pane, b: &Pane) {
+ pub fn swap(&mut self, a: Pane, b: Pane) {
self.internal.layout.update(&|node| match node {
Node::Split { .. } => {}
Node::Pane(pane) => {
- if pane == a {
- *node = Node::Pane(*b);
- } else if pane == b {
- *node = Node::Pane(*a);
+ if *pane == a {
+ *node = Node::Pane(b);
+ } else if *pane == b {
+ *node = Node::Pane(a);
}
}
});
@@ -296,19 +296,19 @@ impl<T> State<T> {
///
/// [`PaneGrid`]: super::PaneGrid
/// [`ResizeEvent`]: super::ResizeEvent
- pub fn resize(&mut self, split: &Split, ratio: f32) {
+ pub fn resize(&mut self, split: Split, ratio: f32) {
let _ = self.internal.layout.resize(split, ratio);
}
/// Closes the given [`Pane`] and returns its internal state and its closest
/// sibling, if it exists.
- pub fn close(&mut self, pane: &Pane) -> Option<(T, Pane)> {
- if self.maximized == Some(*pane) {
+ pub fn close(&mut self, pane: Pane) -> Option<(T, Pane)> {
+ if self.maximized == Some(pane) {
let _ = self.maximized.take();
}
if let Some(sibling) = self.internal.layout.remove(pane) {
- self.panes.remove(pane).map(|state| (state, sibling))
+ self.panes.remove(&pane).map(|state| (state, sibling))
} else {
None
}
@@ -318,8 +318,8 @@ impl<T> State<T> {
/// [`PaneGrid`] until [`Self::restore()`] is called.
///
/// [`PaneGrid`]: super::PaneGrid
- pub fn maximize(&mut self, pane: &Pane) {
- self.maximized = Some(*pane);
+ pub fn maximize(&mut self, pane: Pane) {
+ self.maximized = Some(pane);
}
/// Restore the currently maximized [`Pane`] to it's normal size. All panes
diff --git a/widget/src/pane_grid/title_bar.rs b/widget/src/pane_grid/title_bar.rs
index 5ae7a6a0..f4dbb6b1 100644
--- a/widget/src/pane_grid/title_bar.rs
+++ b/widget/src/pane_grid/title_bar.rs
@@ -286,7 +286,7 @@ where
controls_layout,
renderer,
operation,
- )
+ );
};
if show_title {
@@ -295,7 +295,7 @@ where
title_layout,
renderer,
operation,
- )
+ );
}
}
diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs
index 4b89d6ff..00c1a7ff 100644
--- a/widget/src/pick_list.rs
+++ b/widget/src/pick_list.rs
@@ -76,7 +76,7 @@ where
text_line_height: text::LineHeight::default(),
text_shaping: text::Shaping::Basic,
font: None,
- handle: Default::default(),
+ handle: Handle::default(),
style: Default::default(),
}
}
@@ -253,7 +253,7 @@ where
&self.handle,
&self.style,
|| tree.state.downcast_ref::<State<Renderer::Paragraph>>(),
- )
+ );
}
fn overlay<'b>(
diff --git a/widget/src/row.rs b/widget/src/row.rs
index 71cf0509..7ca90fbb 100644
--- a/widget/src/row.rs
+++ b/widget/src/row.rs
@@ -101,7 +101,7 @@ where
}
fn diff(&self, tree: &mut Tree) {
- tree.diff_children(&self.children)
+ tree.diff_children(&self.children);
}
fn width(&self) -> Length {
@@ -148,7 +148,7 @@ where
child
.as_widget()
.operate(state, layout, renderer, operation);
- })
+ });
});
}
diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs
index def28821..49aed2f0 100644
--- a/widget/src/scrollable.rs
+++ b/widget/src/scrollable.rs
@@ -46,7 +46,7 @@ where
id: None,
width: Length::Shrink,
height: Length::Shrink,
- direction: Default::default(),
+ direction: Direction::default(),
content: content.into(),
on_scroll: None,
style: Default::default(),
@@ -117,7 +117,7 @@ impl Direction {
match self {
Self::Horizontal(properties) => Some(properties),
Self::Both { horizontal, .. } => Some(horizontal),
- _ => None,
+ Self::Vertical(_) => None,
}
}
@@ -126,7 +126,7 @@ impl Direction {
match self {
Self::Vertical(properties) => Some(properties),
Self::Both { vertical, .. } => Some(vertical),
- _ => None,
+ Self::Horizontal(_) => None,
}
}
}
@@ -217,7 +217,7 @@ where
}
fn diff(&self, tree: &mut Tree) {
- tree.diff_children(std::slice::from_ref(&self.content))
+ tree.diff_children(std::slice::from_ref(&self.content));
}
fn width(&self) -> Length {
@@ -348,9 +348,9 @@ where
layout,
cursor,
viewport,
- )
+ );
},
- )
+ );
}
fn mouse_interaction(
@@ -1069,7 +1069,7 @@ impl operation::Scrollable for State {
}
fn scroll_to(&mut self, offset: AbsoluteOffset) {
- State::scroll_to(self, offset)
+ State::scroll_to(self, offset);
}
}
@@ -1203,7 +1203,7 @@ impl State {
(self.offset_y.absolute(bounds.height, content_bounds.height)
- delta.y)
.clamp(0.0, content_bounds.height - bounds.height),
- )
+ );
}
if bounds.width < content_bounds.width {
@@ -1364,15 +1364,15 @@ impl Scrollbars {
let ratio = bounds.height / content_bounds.height;
// min height for easier grabbing with super tall content
- let scroller_height = (bounds.height * ratio).max(2.0);
- let scroller_offset = translation.y * ratio;
+ let scroller_height = (scrollbar_bounds.height * ratio).max(2.0);
+ let scroller_offset =
+ translation.y * ratio * scrollbar_bounds.height / bounds.height;
let scroller_bounds = Rectangle {
x: bounds.x + bounds.width
- total_scrollbar_width / 2.0
- scroller_width / 2.0,
- y: (scrollbar_bounds.y + scroller_offset - x_scrollbar_height)
- .max(0.0),
+ y: (scrollbar_bounds.y + scroller_offset).max(0.0),
width: scroller_width,
height: scroller_height,
};
@@ -1399,8 +1399,8 @@ impl Scrollbars {
// Need to adjust the width of the horizontal scrollbar if the vertical scrollbar
// is present
- let scrollbar_y_width = show_scrollbar_y
- .map_or(0.0, |v| v.width.max(v.scroller_width) + v.margin);
+ let scrollbar_y_width = y_scrollbar
+ .map_or(0.0, |scrollbar| scrollbar.total_bounds.width);
let total_scrollbar_height =
width.max(scroller_width) + 2.0 * margin;
@@ -1425,12 +1425,12 @@ impl Scrollbars {
let ratio = bounds.width / content_bounds.width;
// min width for easier grabbing with extra wide content
- let scroller_length = (bounds.width * ratio).max(2.0);
- let scroller_offset = translation.x * ratio;
+ let scroller_length = (scrollbar_bounds.width * ratio).max(2.0);
+ let scroller_offset =
+ translation.x * ratio * scrollbar_bounds.width / bounds.width;
let scroller_bounds = Rectangle {
- x: (scrollbar_bounds.x + scroller_offset - scrollbar_y_width)
- .max(0.0),
+ x: (scrollbar_bounds.x + scroller_offset).max(0.0),
y: bounds.y + bounds.height
- total_scrollbar_height / 2.0
- scroller_width / 2.0,
diff --git a/widget/src/slider.rs b/widget/src/slider.rs
index 2c4a2913..ac0982c8 100644
--- a/widget/src/slider.rs
+++ b/widget/src/slider.rs
@@ -223,7 +223,7 @@ where
&self.range,
theme,
&self.style,
- )
+ );
}
fn mouse_interaction(
diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs
index f9a2d419..27efe755 100644
--- a/widget/src/text_input.rs
+++ b/widget/src/text_input.rs
@@ -250,7 +250,7 @@ where
self.is_secure,
self.icon.as_ref(),
&self.style,
- )
+ );
}
}
@@ -375,7 +375,7 @@ where
self.is_secure,
self.icon.as_ref(),
&self.style,
- )
+ );
}
fn mouse_interaction(
@@ -619,7 +619,7 @@ where
font,
size,
line_height,
- )
+ );
};
match event {
@@ -846,7 +846,7 @@ where
state.cursor.move_left_by_words(value);
}
} else if modifiers.shift() {
- state.cursor.select_left(value)
+ state.cursor.select_left(value);
} else {
state.cursor.move_left(value);
}
@@ -861,7 +861,7 @@ where
state.cursor.move_right_by_words(value);
}
} else if modifiers.shift() {
- state.cursor.select_right(value)
+ state.cursor.select_right(value);
} else {
state.cursor.move_right(value);
}
@@ -1217,7 +1217,7 @@ pub fn draw<Renderer>(
if text_width > text_bounds.width {
renderer.with_layer(text_bounds, |renderer| {
- renderer.with_translation(Vector::new(-offset, 0.0), render)
+ renderer.with_translation(Vector::new(-offset, 0.0), render);
});
} else {
render(renderer);
@@ -1339,29 +1339,29 @@ impl<P: text::Paragraph> operation::Focusable for State<P> {
}
fn focus(&mut self) {
- State::focus(self)
+ State::focus(self);
}
fn unfocus(&mut self) {
- State::unfocus(self)
+ State::unfocus(self);
}
}
impl<P: text::Paragraph> operation::TextInput for State<P> {
fn move_cursor_to_front(&mut self) {
- State::move_cursor_to_front(self)
+ State::move_cursor_to_front(self);
}
fn move_cursor_to_end(&mut self) {
- State::move_cursor_to_end(self)
+ State::move_cursor_to_end(self);
}
fn move_cursor_to(&mut self, position: usize) {
- State::move_cursor_to(self, position)
+ State::move_cursor_to(self, position);
}
fn select_all(&mut self) {
- State::select_all(self)
+ State::select_all(self);
}
}
diff --git a/widget/src/text_input/cursor.rs b/widget/src/text_input/cursor.rs
index 9680dfd7..f682b17d 100644
--- a/widget/src/text_input/cursor.rs
+++ b/widget/src/text_input/cursor.rs
@@ -56,7 +56,7 @@ impl Cursor {
State::Selection { start, end } => {
Some((start.min(end), start.max(end)))
}
- _ => None,
+ State::Index(_) => None,
}
}
@@ -65,11 +65,11 @@ impl Cursor {
}
pub(crate) fn move_right(&mut self, value: &Value) {
- self.move_right_by_amount(value, 1)
+ self.move_right_by_amount(value, 1);
}
pub(crate) fn move_right_by_words(&mut self, value: &Value) {
- self.move_to(value.next_end_of_word(self.right(value)))
+ self.move_to(value.next_end_of_word(self.right(value)));
}
pub(crate) fn move_right_by_amount(
@@ -79,7 +79,7 @@ impl Cursor {
) {
match self.state(value) {
State::Index(index) => {
- self.move_to(index.saturating_add(amount).min(value.len()))
+ self.move_to(index.saturating_add(amount).min(value.len()));
}
State::Selection { start, end } => self.move_to(end.max(start)),
}
@@ -89,7 +89,7 @@ impl Cursor {
match self.state(value) {
State::Index(index) if index > 0 => self.move_to(index - 1),
State::Selection { start, end } => self.move_to(start.min(end)),
- _ => self.move_to(0),
+ State::Index(_) => self.move_to(0),
}
}
@@ -108,10 +108,10 @@ impl Cursor {
pub(crate) fn select_left(&mut self, value: &Value) {
match self.state(value) {
State::Index(index) if index > 0 => {
- self.select_range(index, index - 1)
+ self.select_range(index, index - 1);
}
State::Selection { start, end } if end > 0 => {
- self.select_range(start, end - 1)
+ self.select_range(start, end - 1);
}
_ => {}
}
@@ -120,10 +120,10 @@ impl Cursor {
pub(crate) fn select_right(&mut self, value: &Value) {
match self.state(value) {
State::Index(index) if index < value.len() => {
- self.select_range(index, index + 1)
+ self.select_range(index, index + 1);
}
State::Selection { start, end } if end < value.len() => {
- self.select_range(start, end + 1)
+ self.select_range(start, end + 1);
}
_ => {}
}
@@ -132,10 +132,10 @@ impl Cursor {
pub(crate) fn select_left_by_words(&mut self, value: &Value) {
match self.state(value) {
State::Index(index) => {
- self.select_range(index, value.previous_start_of_word(index))
+ self.select_range(index, value.previous_start_of_word(index));
}
State::Selection { start, end } => {
- self.select_range(start, value.previous_start_of_word(end))
+ self.select_range(start, value.previous_start_of_word(end));
}
}
}
@@ -143,10 +143,10 @@ impl Cursor {
pub(crate) fn select_right_by_words(&mut self, value: &Value) {
match self.state(value) {
State::Index(index) => {
- self.select_range(index, value.next_end_of_word(index))
+ self.select_range(index, value.next_end_of_word(index));
}
State::Selection { start, end } => {
- self.select_range(start, value.next_end_of_word(end))
+ self.select_range(start, value.next_end_of_word(end));
}
}
}
diff --git a/widget/src/text_input/value.rs b/widget/src/text_input/value.rs
index d1b056c8..46a1f754 100644
--- a/widget/src/text_input/value.rs
+++ b/widget/src/text_input/value.rs
@@ -89,11 +89,6 @@ impl Value {
Self { graphemes }
}
- /// Converts the [`Value`] into a `String`.
- pub fn to_string(&self) -> String {
- self.graphemes.concat()
- }
-
/// Inserts a new `char` at the given grapheme `index`.
pub fn insert(&mut self, index: usize, c: char) {
self.graphemes.insert(index, c.to_string());
@@ -131,3 +126,9 @@ impl Value {
}
}
}
+
+impl std::fmt::Display for Value {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(&self.graphemes.concat())
+ }
+}
diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs
index 2440317f..476c8330 100644
--- a/widget/src/toggler.rs
+++ b/widget/src/toggler.rs
@@ -286,7 +286,7 @@ where
style,
label_layout,
tree.state.downcast_ref(),
- Default::default(),
+ crate::text::Appearance::default(),
);
}
diff --git a/widget/src/tooltip.rs b/widget/src/tooltip.rs
index edc74e31..b041d2e9 100644
--- a/widget/src/tooltip.rs
+++ b/widget/src/tooltip.rs
@@ -114,7 +114,7 @@ where
}
fn diff(&self, tree: &mut widget::Tree) {
- tree.diff_children(&[self.content.as_widget(), &self.tooltip])
+ tree.diff_children(&[self.content.as_widget(), &self.tooltip]);
}
fn state(&self) -> widget::tree::State {
diff --git a/widget/src/vertical_slider.rs b/widget/src/vertical_slider.rs
index 1efcd63b..01d3359c 100644
--- a/widget/src/vertical_slider.rs
+++ b/widget/src/vertical_slider.rs
@@ -220,7 +220,7 @@ where
&self.range,
theme,
&self.style,
- )
+ );
}
fn mouse_interaction(