Text input (#143)

* update: iced 0.10.0

* wip: text input

* wip: text inputs with icons and buttons

* wip: improve text input

* refactor: text input styling

* chore: add scale factor

* chore(text_input): add winit example and do some cleanup
This commit is contained in:
Ashley Wulber 2023-08-23 10:59:26 -04:00 committed by GitHub
parent fcdefcd8fb
commit db8e791b87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 3017 additions and 4 deletions

View file

@ -13,9 +13,10 @@ use cosmic::{
iced_widget::text,
theme::{self, Theme},
widget::{
button, cosmic_container, header_bar, nav_bar, nav_bar_toggle,
button, cosmic_container, header_bar, icon, inline_input, nav_bar, nav_bar_toggle,
rectangle_tracker::{rectangle_tracker_subscription, RectangleTracker, RectangleUpdate},
scrollable, segmented_button, segmented_selection, settings, IconSource,
scrollable, search_input, secure_input, segmented_button, segmented_selection, settings,
text_input, IconSource,
},
Element, ElementExt,
};
@ -127,6 +128,8 @@ pub struct Window {
rectangle_tracker: Option<RectangleTracker<u32>>,
pub selection: segmented_button::SingleSelectModel,
timeline: Timeline,
input_value: String,
secure_input_visible: bool,
}
impl Window {
@ -183,12 +186,13 @@ pub enum Message {
Drag,
Minimize,
Maximize,
InputChanged,
Rectangle(RectangleUpdate<u32>),
NavBar(segmented_button::Entity),
Ignore,
Selection(segmented_button::Entity),
Tick(Instant),
InputChanged(String),
ToggleVisible,
}
impl Window {
@ -305,7 +309,6 @@ impl Application for Window {
Message::Minimize => return set_mode_window(window::Id(0), window::Mode::Hidden),
Message::Maximize => return toggle_maximize(window::Id(0)),
Message::RowSelected(row) => println!("Selected row {row}"),
Message::InputChanged => {}
Message::Rectangle(r) => match r {
RectangleUpdate::Rectangle(_) => {}
RectangleUpdate::Init(t) => {
@ -315,6 +318,12 @@ impl Application for Window {
Message::Ignore => {}
Message::Selection(key) => self.selection.activate(key),
Message::Tick(now) => self.timeline.now(now),
Message::InputChanged(v) => {
self.input_value = v;
}
Message::ToggleVisible => {
self.secure_input_visible = !self.secure_input_visible;
}
}
Command::none()
@ -476,6 +485,41 @@ impl Application for Window {
.padding(16)
.style(cosmic::theme::Container::Secondary),
))
.add(settings::item(
"Text Input",
text_input("test", &self.input_value)
.width(Length::Fill)
.on_input(Message::InputChanged),
))
.add(settings::item(
"Text Input",
secure_input(
"test",
&self.input_value,
Some(Message::ToggleVisible),
!self.secure_input_visible,
)
.label("Test Secure Input Label")
.helper_text("password")
.width(Length::Fill)
.on_input(Message::InputChanged),
))
.add(settings::item(
"Text Input",
search_input(
"search for stuff",
&self.input_value,
Some(Message::InputChanged("".to_string())),
)
.width(Length::Fill)
.on_input(Message::InputChanged),
))
.add(settings::item(
"Text Input",
inline_input(&self.input_value)
.width(Length::Fill)
.on_input(Message::InputChanged),
))
.into(),
])
.into();

View file

@ -504,6 +504,10 @@ impl State {
.size(20)
.id(INPUT_ID.clone())
.into(),
cosmic::widget::text_input("test", &self.entry_value)
.width(Length::Fill)
.on_input(Message::InputChanged)
.into(),
])
.into()
}