diff options
| author | 2023-04-11 06:18:52 +0200 | |
|---|---|---|
| committer | 2023-04-11 06:18:52 +0200 | |
| commit | ff24f9040c822fa7706087091e92ebee1e5211c5 (patch) | |
| tree | 18e5a9053b092cb9d0d9f0b95f35b1bdeb6aaa7f /examples/tour | |
| parent | 931b30dc5ac17b65b1fb996cb4b87fc946c410e3 (diff) | |
| parent | 927c3a8caaefc241c48d6200266d286e20dc2076 (diff) | |
| download | iced-ff24f9040c822fa7706087091e92ebee1e5211c5.tar.gz iced-ff24f9040c822fa7706087091e92ebee1e5211c5.tar.bz2 iced-ff24f9040c822fa7706087091e92ebee1e5211c5.zip  | |
Merge pull request #1702 from casperstorm/feat/text_input_handle
Added `Icon` to `text_input`
Diffstat (limited to 'examples/tour')
| -rw-r--r-- | examples/tour/fonts/icons.ttf | bin | 0 -> 1612 bytes | |||
| -rw-r--r-- | examples/tour/src/main.rs | 80 | 
2 files changed, 67 insertions, 13 deletions
diff --git a/examples/tour/fonts/icons.ttf b/examples/tour/fonts/icons.ttf Binary files differnew file mode 100644 index 00000000..bfe8a24b --- /dev/null +++ b/examples/tour/fonts/icons.ttf diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index de063d00..90868877 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -5,7 +5,7 @@ use iced::widget::{      scrollable, slider, text, text_input, toggler, vertical_space,  };  use iced::widget::{Button, Column, Container, Slider}; -use iced::{Color, Element, Length, Renderer, Sandbox, Settings}; +use iced::{Color, Element, Font, Length, Renderer, Sandbox, Settings};  pub fn main() -> iced::Result {      env_logger::init(); @@ -127,6 +127,7 @@ impl Steps {                  Step::TextInput {                      value: String::new(),                      is_secure: false, +                    is_showing_icon: false,                  },                  Step::Debugger,                  Step::End, @@ -171,14 +172,32 @@ impl Steps {  enum Step {      Welcome, -    Slider { value: u8 }, -    RowsAndColumns { layout: Layout, spacing: u16 }, -    Text { size: u16, color: Color }, -    Radio { selection: Option<Language> }, -    Toggler { can_continue: bool }, -    Image { width: u16 }, +    Slider { +        value: u8, +    }, +    RowsAndColumns { +        layout: Layout, +        spacing: u16, +    }, +    Text { +        size: u16, +        color: Color, +    }, +    Radio { +        selection: Option<Language>, +    }, +    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 +213,7 @@ pub enum StepMessage {      ImageWidthChanged(u16),      InputChanged(String),      ToggleSecureInput(bool), +    ToggleTextInputIcon(bool),      DebugToggled(bool),      TogglerChanged(bool),  } @@ -256,6 +276,14 @@ impl<'a> Step {                      *can_continue = value;                  }              } +            StepMessage::ToggleTextInputIcon(toggle) => { +                if let Step::TextInput { +                    is_showing_icon, .. +                } = self +                { +                    *is_showing_icon = toggle +                } +            }          };      } @@ -303,9 +331,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 +560,17 @@ 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> { +        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,              StepMessage::InputChanged, @@ -539,6 +578,16 @@ 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.0), +                spacing: 10.0, +                side: text_input::Side::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:",  | 
