diff options
| author | 2019-10-30 03:31:07 +0100 | |
|---|---|---|
| committer | 2019-10-30 03:31:07 +0100 | |
| commit | 63cd0fd8eb1eebae8de7d5141c846fc4ea55d702 (patch) | |
| tree | e0a427a35435ad5fe5ce98a0b5050a1026a80207 /core | |
| parent | 85916c9e8710ee90cbf37d384acbb6d208ff1da3 (diff) | |
| download | iced-63cd0fd8eb1eebae8de7d5141c846fc4ea55d702.tar.gz iced-63cd0fd8eb1eebae8de7d5141c846fc4ea55d702.tar.bz2 iced-63cd0fd8eb1eebae8de7d5141c846fc4ea55d702.zip | |
Draft `TextInput` widget structure
Also started a `todos` example to showcase it!
Diffstat (limited to '')
| -rw-r--r-- | core/src/widget.rs | 8 | ||||
| -rw-r--r-- | core/src/widget/text_input.rs | 84 | 
2 files changed, 88 insertions, 4 deletions
| diff --git a/core/src/widget.rs b/core/src/widget.rs index 3ee8e347..41c4c6a8 100644 --- a/core/src/widget.rs +++ b/core/src/widget.rs @@ -17,18 +17,18 @@ pub mod button;  pub mod scrollable;  pub mod slider;  pub mod text; +pub mod text_input;  #[doc(no_inline)]  pub use button::Button; - +#[doc(no_inline)] +pub use scrollable::Scrollable;  #[doc(no_inline)]  pub use slider::Slider; -  #[doc(no_inline)]  pub use text::Text; -  #[doc(no_inline)] -pub use scrollable::Scrollable; +pub use text_input::TextInput;  pub use checkbox::Checkbox;  pub use column::Column; diff --git a/core/src/widget/text_input.rs b/core/src/widget/text_input.rs new file mode 100644 index 00000000..2f20635f --- /dev/null +++ b/core/src/widget/text_input.rs @@ -0,0 +1,84 @@ +use crate::Length; + +pub struct TextInput<'a, Message> { +    pub state: &'a mut State, +    pub placeholder: String, +    pub value: String, +    pub width: Length, +    pub max_width: Length, +    pub padding: u16, +    pub size: Option<u16>, +    pub on_change: Box<dyn Fn(String) -> Message>, +    pub on_submit: Option<Message>, +} + +#[derive(Debug, Default)] +pub struct State {} + +impl<'a, Message> TextInput<'a, Message> { +    pub fn new<F>( +        state: &'a mut State, +        placeholder: &str, +        value: &str, +        on_change: F, +    ) -> Self +    where +        F: 'static + Fn(String) -> Message, +    { +        Self { +            state, +            placeholder: String::from(placeholder), +            value: String::from(value), +            width: Length::Fill, +            max_width: Length::Shrink, +            padding: 0, +            size: None, +            on_change: Box::new(on_change), +            on_submit: None, +        } +    } + +    /// Sets the width of the [`TextInput`]. +    /// +    /// [`TextInput`]: struct.TextInput.html +    pub fn width(mut self, width: Length) -> Self { +        self.width = width; +        self +    } + +    /// Sets the maximum width of the [`TextInput`]. +    /// +    /// [`TextInput`]: struct.TextInput.html +    pub fn max_width(mut self, max_width: Length) -> Self { +        self.max_width = max_width; +        self +    } + +    /// Sets the padding of the [`TextInput`]. +    /// +    /// [`TextInput`]: struct.TextInput.html +    pub fn padding(mut self, units: u16) -> Self { +        self.padding = units; +        self +    } + +    pub fn size(mut self, size: u16) -> Self { +        self.size = Some(size); +        self +    } + +    pub fn on_submit(mut self, message: Message) -> Self { +        self.on_submit = Some(message); +        self +    } +} + +impl<'a, Message> std::fmt::Debug for TextInput<'a, Message> +where +    Message: std::fmt::Debug, +{ +    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +        // TODO: Complete once stabilized +        f.debug_struct("TextInput").finish() +    } +} | 
