From 898307e9ac8e11de275d7d4d58b93a6f24a1e800 Mon Sep 17 00:00:00 2001 From: Casper Storm Date: Mon, 20 Feb 2023 14:42:10 +0100 Subject: Removed text_input example in favor for Tour --- examples/tour/src/main.rs | 78 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 12 deletions(-) (limited to 'examples/tour/src/main.rs') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index de063d00..5edee850 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -5,8 +5,14 @@ use iced::widget::{ scrollable, slider, text, text_input, toggler, vertical_space, }; use iced::widget::{Button, Column, Container, Slider}; +use iced::Font; use iced::{Color, Element, Length, Renderer, Sandbox, Settings}; +const ICON_FONT: Font = Font::External { + name: "Icons", + bytes: include_bytes!("../fonts/icons.ttf"), +}; + pub fn main() -> iced::Result { env_logger::init(); @@ -127,6 +133,7 @@ impl Steps { Step::TextInput { value: String::new(), is_secure: false, + is_showing_icon: false, }, Step::Debugger, Step::End, @@ -171,14 +178,32 @@ impl Steps { enum Step { Welcome, - Slider { value: u8 }, - RowsAndColumns { layout: Layout, spacing: u16 }, - Text { size: u16, color: Color }, - Radio { selection: Option }, - Toggler { can_continue: bool }, - Image { width: u16 }, + Slider { + value: u8, + }, + RowsAndColumns { + layout: Layout, + spacing: u16, + }, + Text { + size: u16, + color: Color, + }, + Radio { + selection: Option, + }, + Toggler { + can_continue: bool, + }, + Image { + width: u16, + }, Scrollable, - TextInput { value: String, is_secure: bool }, + TextInput { + value: String, + is_secure: bool, + is_showing_icon: bool, + }, Debugger, End, } @@ -194,6 +219,7 @@ pub enum StepMessage { ImageWidthChanged(u16), InputChanged(String), ToggleSecureInput(bool), + ToggleTextInputIcon(bool), DebugToggled(bool), TogglerChanged(bool), } @@ -256,6 +282,14 @@ impl<'a> Step { *can_continue = value; } } + StepMessage::ToggleTextInputIcon(toggle) => { + if let Step::TextInput { + is_showing_icon, .. + } = self + { + *is_showing_icon = toggle + } + } }; } @@ -303,9 +337,11 @@ impl<'a> Step { Self::rows_and_columns(*layout, *spacing) } Step::Scrollable => Self::scrollable(), - Step::TextInput { value, is_secure } => { - Self::text_input(value, *is_secure) - } + Step::TextInput { + value, + is_secure, + is_showing_icon, + } => Self::text_input(value, *is_secure, *is_showing_icon), Step::Debugger => Self::debugger(debug), Step::End => Self::end(), } @@ -530,8 +566,12 @@ impl<'a> Step { ) } - fn text_input(value: &str, is_secure: bool) -> Column<'a, StepMessage> { - let text_input = text_input( + fn text_input( + value: &str, + is_secure: bool, + is_showing_icon: bool, + ) -> Column<'a, StepMessage> { + let mut text_input = text_input( "Type something to continue...", value, StepMessage::InputChanged, @@ -539,6 +579,15 @@ impl<'a> Step { .padding(10) .size(30); + if is_showing_icon { + text_input = text_input.icon(text_input::Icon { + font: ICON_FONT, + code_point: '\u{e900}', + size: Some(35), + position: text_input::IconPosition::Right, + }); + } + Self::container("Text input") .push("Use a text input to ask for different kinds of information.") .push(if is_secure { @@ -551,6 +600,11 @@ impl<'a> Step { is_secure, StepMessage::ToggleSecureInput, )) + .push(checkbox( + "Show icon", + is_showing_icon, + StepMessage::ToggleTextInputIcon, + )) .push( "A text input produces a message every time it changes. It is \ very easy to keep track of its contents:", -- cgit From 0e2fc99eb864800d2d1522c015054d84cad078f4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 11 Apr 2023 05:13:56 +0200 Subject: Use `f32` for `Icon::size` and remove unnecessary conversions --- examples/tour/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/tour/src/main.rs') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 5edee850..6a1380d7 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -583,7 +583,7 @@ impl<'a> Step { text_input = text_input.icon(text_input::Icon { font: ICON_FONT, code_point: '\u{e900}', - size: Some(35), + size: Some(35.0), position: text_input::IconPosition::Right, }); } -- cgit From 9852b4b36442ef036f0b308f798e892ddaa06c2d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 11 Apr 2023 05:45:55 +0200 Subject: Move `Icon` layout logic to `layout` in `text_input` Also add `Icon::spacing` field. --- examples/tour/src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'examples/tour/src/main.rs') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 6a1380d7..8a1b8d5a 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -138,7 +138,7 @@ impl Steps { Step::Debugger, Step::End, ], - current: 0, + current: 8, } } @@ -582,8 +582,9 @@ impl<'a> Step { if is_showing_icon { text_input = text_input.icon(text_input::Icon { font: ICON_FONT, - code_point: '\u{e900}', + code_point: '\u{E900}', size: Some(35.0), + spacing: 10.0, position: text_input::IconPosition::Right, }); } -- cgit From cf9d8e01048845ee503a62eb55e634a76a0e9163 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 11 Apr 2023 05:54:51 +0200 Subject: Rename `IconPosition` to `Side` in `text_input` --- examples/tour/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/tour/src/main.rs') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 8a1b8d5a..40ab33c2 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -585,7 +585,7 @@ impl<'a> Step { code_point: '\u{E900}', size: Some(35.0), spacing: 10.0, - position: text_input::IconPosition::Right, + side: text_input::Side::Right, }); } -- cgit From c794d8ba788b388d4fb7a8ef1bba208b98e1bd02 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 11 Apr 2023 05:56:34 +0200 Subject: Collapse `Font` import in `tour` example --- examples/tour/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/tour/src/main.rs') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 40ab33c2..9ee386d4 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -5,8 +5,7 @@ use iced::widget::{ scrollable, slider, text, text_input, toggler, vertical_space, }; use iced::widget::{Button, Column, Container, Slider}; -use iced::Font; -use iced::{Color, Element, Length, Renderer, Sandbox, Settings}; +use iced::{Color, Element, Font, Length, Renderer, Sandbox, Settings}; const ICON_FONT: Font = Font::External { name: "Icons", -- cgit From aa0be30656e30d116e60a5d06557aea27442ce76 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 11 Apr 2023 05:57:01 +0200 Subject: Move `ICON_FONT` constant in `tour` to `text_input` helper --- examples/tour/src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'examples/tour/src/main.rs') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 9ee386d4..e9b9fb3a 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -7,11 +7,6 @@ use iced::widget::{ use iced::widget::{Button, Column, Container, Slider}; use iced::{Color, Element, Font, Length, Renderer, Sandbox, Settings}; -const ICON_FONT: Font = Font::External { - name: "Icons", - bytes: include_bytes!("../fonts/icons.ttf"), -}; - pub fn main() -> iced::Result { env_logger::init(); @@ -570,6 +565,11 @@ impl<'a> Step { is_secure: bool, is_showing_icon: bool, ) -> Column<'a, StepMessage> { + const ICON_FONT: Font = Font::External { + name: "Icons", + bytes: include_bytes!("../fonts/icons.ttf"), + }; + let mut text_input = text_input( "Type something to continue...", value, -- cgit From 45015e37d4123f01b546337e741820975fccf66a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 11 Apr 2023 05:57:31 +0200 Subject: Fix `current` step in `tour` --- examples/tour/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/tour/src/main.rs') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index e9b9fb3a..90868877 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -132,7 +132,7 @@ impl Steps { Step::Debugger, Step::End, ], - current: 8, + current: 0, } } -- cgit From f10e936f00d4b83dcacfdebd2727b1a5cd1add95 Mon Sep 17 00:00:00 2001 From: Dan Mishin Date: Fri, 3 Mar 2023 10:01:49 +0300 Subject: Introduce disabled state for `TextInput` --- examples/tour/src/main.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'examples/tour/src/main.rs') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 90868877..3b4cfd2d 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -570,13 +570,10 @@ impl<'a> Step { bytes: include_bytes!("../fonts/icons.ttf"), }; - let mut text_input = text_input( - "Type something to continue...", - value, - StepMessage::InputChanged, - ) - .padding(10) - .size(30); + let mut text_input = text_input("Type something to continue...", value) + .on_change(StepMessage::InputChanged) + .padding(10) + .size(30); if is_showing_icon { text_input = text_input.icon(text_input::Icon { -- cgit From e6a93e960c3ac71a74f11555fd2d225c185f6e8c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 12 Apr 2023 04:13:36 +0200 Subject: Rename `on_change` to `on_input` for `TextInput` --- examples/tour/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/tour/src/main.rs') diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 3b4cfd2d..16ee19c0 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -571,7 +571,7 @@ impl<'a> Step { }; let mut text_input = text_input("Type something to continue...", value) - .on_change(StepMessage::InputChanged) + .on_input(StepMessage::InputChanged) .padding(10) .size(30); -- cgit