summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Casper Storm <casper.storm@lich.io>2023-02-16 14:32:59 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-04-11 05:11:23 +0200
commitd24a4a46895ed711ddfc3199a0445f0b69a812e4 (patch)
treed18477c286585f14334a2ae591e81f7ce86fee05
parentbfc5db9009f10a67ed277ce9d1997bcdea3f6acd (diff)
downloadiced-d24a4a46895ed711ddfc3199a0445f0b69a812e4.tar.gz
iced-d24a4a46895ed711ddfc3199a0445f0b69a812e4.tar.bz2
iced-d24a4a46895ed711ddfc3199a0445f0b69a812e4.zip
Changed `Handle` to `Icon` to be consistent
-rw-r--r--examples/text_input/src/main.rs18
-rw-r--r--native/src/widget/text_input.rs87
-rw-r--r--src/widget.rs2
-rw-r--r--style/src/text_input.rs4
-rw-r--r--style/src/theme.rs6
5 files changed, 59 insertions, 58 deletions
diff --git a/examples/text_input/src/main.rs b/examples/text_input/src/main.rs
index b25ed7e1..e0ba1983 100644
--- a/examples/text_input/src/main.rs
+++ b/examples/text_input/src/main.rs
@@ -13,13 +13,13 @@ pub fn main() -> iced::Result {
#[derive(Default)]
struct Example {
value: String,
- is_showing_handle: bool,
+ is_showing_icon: bool,
}
#[derive(Debug, Clone)]
enum Message {
Changed(String),
- ToggleHandle(bool),
+ ToggleIcon(bool),
}
impl Sandbox for Example {
@@ -36,27 +36,27 @@ impl Sandbox for Example {
fn update(&mut self, message: Message) {
match message {
Message::Changed(value) => self.value = value,
- Message::ToggleHandle(_) => {
- self.is_showing_handle = !self.is_showing_handle
+ Message::ToggleIcon(_) => {
+ self.is_showing_icon = !self.is_showing_icon
}
}
}
fn view(&self) -> Element<Message> {
let checkbox =
- checkbox("Handle", self.is_showing_handle, Message::ToggleHandle)
+ checkbox("Icon", self.is_showing_icon, Message::ToggleIcon)
.spacing(5)
.text_size(16);
let mut text_input =
text_input("Placeholder", self.value.as_str(), Message::Changed);
- if self.is_showing_handle {
- text_input = text_input.handle(text_input::Handle {
+ if self.is_showing_icon {
+ text_input = text_input.icon(text_input::Icon {
font: ICON_FONT,
- text: String::from('\u{e900}'),
+ code_point: '\u{e900}',
size: Some(18),
- position: text_input::HandlePosition::Right,
+ position: text_input::IconPosition::Right,
});
}
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index 7696da99..575f4436 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -31,41 +31,38 @@ use crate::{
pub use iced_style::text_input::{Appearance, StyleSheet};
-/// The position of the [`Handle`].
+/// The position of the [`Icon`].
#[derive(Clone, Default, Debug)]
-pub enum HandlePosition {
- /// Position the handle to the left.
+pub enum IconPosition {
+ /// Position the [`Icon`] to the left.
Left,
- /// Position the handle to the left.
+ /// Position the [`Icon`] to the left.
///
/// This is the default.
#[default]
Right,
}
-/// The content of the [`Handle`].
+/// The content of the [`Icon`].
#[derive(Clone)]
-pub struct Handle<Renderer>
-where
- Renderer: text::Renderer,
-{
- /// Font that will be used to display the `text`.
- pub font: Renderer::Font,
- /// Text that will be shown.
- pub text: String,
+pub struct Icon<Font> {
+ /// Font that will be used to display the `code_point`.
+ pub font: Font,
+ /// The unicode code point that will be used as the icon.
+ pub code_point: char,
/// Font size of the content.
pub size: Option<u16>,
- /// Position of the handle.
- pub position: HandlePosition,
+ /// Position of the icon.
+ pub position: IconPosition,
}
-impl<Renderer> std::fmt::Debug for Handle<Renderer>
+impl<Renderer> std::fmt::Debug for Icon<Renderer>
where
Renderer: text::Renderer,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("Handle")
- .field("text", &self.text)
+ f.debug_struct("Icon")
+ .field("code_point", &self.code_point)
.field("size", &self.size)
.field("position", &self.position)
.finish()
@@ -109,7 +106,7 @@ where
on_change: Box<dyn Fn(String) -> Message + 'a>,
on_paste: Option<Box<dyn Fn(String) -> Message + 'a>>,
on_submit: Option<Message>,
- handle: Option<Handle<Renderer>>,
+ icon: Option<Icon<Renderer::Font>>,
style: <Renderer::Theme as StyleSheet>::Style,
}
@@ -141,7 +138,7 @@ where
on_change: Box::new(on_change),
on_paste: None,
on_submit: None,
- handle: None,
+ icon: None,
style: Default::default(),
}
}
@@ -176,9 +173,9 @@ where
self
}
- /// Sets the [`Handle`] of the [`TextInput`].
- pub fn handle(mut self, handle: Handle<Renderer>) -> Self {
- self.handle = Some(handle);
+ /// Sets the [`Icon`] of the [`TextInput`].
+ pub fn icon(mut self, icon: Icon<Renderer::Font>) -> Self {
+ self.icon = Some(icon);
self
}
@@ -241,7 +238,7 @@ where
self.padding,
&self.font,
self.is_secure,
- self.handle.as_ref(),
+ self.icon.as_ref(),
&self.style,
)
}
@@ -341,7 +338,7 @@ where
self.padding,
&self.font,
self.is_secure,
- self.handle.as_ref(),
+ self.icon.as_ref(),
&self.style,
)
}
@@ -869,7 +866,7 @@ pub fn draw<Renderer>(
padding: Padding,
font: &Renderer::Font,
is_secure: bool,
- handle: Option<&Handle<Renderer>>,
+ icon: Option<&Icon<Renderer::Font>>,
style: &<Renderer::Theme as StyleSheet>::Style,
) where
Renderer: text::Renderer,
@@ -881,26 +878,29 @@ pub fn draw<Renderer>(
let bounds = layout.bounds();
let text_bounds = {
let bounds = layout.children().next().unwrap().bounds();
- if let Some(handle) = handle {
- let Handle {
+ if let Some(icon) = icon {
+ let Icon {
font,
size,
- text,
+ code_point,
position,
- } = handle;
+ } = icon;
let padding = f32::from(padding.horizontal());
let size = size.unwrap_or_else(|| renderer.default_size());
- let width =
- renderer.measure_width(text.as_str(), size, font.clone());
+ let width = renderer.measure_width(
+ &code_point.to_string(),
+ size,
+ font.clone(),
+ );
match position {
- HandlePosition::Left => Rectangle {
+ IconPosition::Left => Rectangle {
x: bounds.x + (width + padding),
width: bounds.width - (width + padding),
..bounds
},
- HandlePosition::Right => Rectangle {
+ IconPosition::Right => Rectangle {
x: bounds.x,
width: bounds.width - (width + padding),
..bounds
@@ -931,27 +931,28 @@ pub fn draw<Renderer>(
appearance.background,
);
- if let Some(handle) = handle {
- let Handle {
+ if let Some(icon) = icon {
+ let Icon {
size,
font,
- text,
+ code_point,
position,
- } = handle;
+ } = icon;
let padding = f32::from(padding.horizontal());
let size = size.unwrap_or_else(|| renderer.default_size());
- let width = renderer.measure_width(text.as_str(), size, font.clone());
+ let width =
+ renderer.measure_width(&code_point.to_string(), size, font.clone());
renderer.fill_text(Text {
- content: text,
+ content: &code_point.to_string(),
size: f32::from(size),
font: font.clone(),
- color: appearance.handle_color,
+ color: appearance.icon_color,
bounds: Rectangle {
x: match position {
- HandlePosition::Left => bounds.x + width + padding,
- HandlePosition::Right => bounds.x + bounds.width - padding,
+ IconPosition::Left => bounds.x + width + padding,
+ IconPosition::Right => bounds.x + bounds.width - padding,
},
y: bounds.center_y() - f32::from(size) / 2.0,
height: f32::from(size),
diff --git a/src/widget.rs b/src/widget.rs
index 948456d3..d3c16088 100644
--- a/src/widget.rs
+++ b/src/widget.rs
@@ -124,7 +124,7 @@ pub mod text_input {
//! Display fields that can be filled with text.
pub use iced_native::widget::text_input::{
focus, move_cursor_to, move_cursor_to_end, move_cursor_to_front,
- select_all, Appearance, Handle, HandlePosition, Id, StyleSheet,
+ select_all, Appearance, Icon, IconPosition, Id, StyleSheet,
};
/// A field that can be filled with text.
diff --git a/style/src/text_input.rs b/style/src/text_input.rs
index 5e703e61..73b05852 100644
--- a/style/src/text_input.rs
+++ b/style/src/text_input.rs
@@ -12,8 +12,8 @@ pub struct Appearance {
pub border_width: f32,
/// The border [`Color`] of the text input.
pub border_color: Color,
- /// The handle [`Color`] of the text input.
- pub handle_color: Color,
+ /// The icon [`Color`] of the text input.
+ pub icon_color: Color,
}
/// A set of rules that dictate the style of a text input.
diff --git a/style/src/theme.rs b/style/src/theme.rs
index 4837e10b..0d974a19 100644
--- a/style/src/theme.rs
+++ b/style/src/theme.rs
@@ -1028,7 +1028,7 @@ impl text_input::StyleSheet for Theme {
border_radius: 2.0,
border_width: 1.0,
border_color: palette.background.strong.color,
- handle_color: palette.background.weak.text,
+ icon_color: palette.background.weak.text,
}
}
@@ -1044,7 +1044,7 @@ impl text_input::StyleSheet for Theme {
border_radius: 2.0,
border_width: 1.0,
border_color: palette.background.base.text,
- handle_color: palette.background.weak.text,
+ icon_color: palette.background.weak.text,
}
}
@@ -1060,7 +1060,7 @@ impl text_input::StyleSheet for Theme {
border_radius: 2.0,
border_width: 1.0,
border_color: palette.primary.strong.color,
- handle_color: palette.background.weak.text,
+ icon_color: palette.background.weak.text,
}
}