fix: text input icon render
This commit is contained in:
parent
accb65b7ec
commit
533e099cf6
2 changed files with 33 additions and 5 deletions
|
|
@ -54,6 +54,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
pub enum Message {
|
||||
Input1(String),
|
||||
Input2(String),
|
||||
Ignore,
|
||||
ToggleHide,
|
||||
}
|
||||
|
||||
/// The [`App`] stores application-specific state.
|
||||
|
|
@ -62,6 +64,7 @@ pub struct App {
|
|||
nav_model: nav_bar::Model,
|
||||
input_1: String,
|
||||
input_2: String,
|
||||
hidden: bool,
|
||||
}
|
||||
|
||||
/// Implement [`cosmic::Application`] to integrate with COSMIC.
|
||||
|
|
@ -101,6 +104,7 @@ impl cosmic::Application for App {
|
|||
nav_model,
|
||||
input_1: String::new(),
|
||||
input_2: String::new(),
|
||||
hidden: true,
|
||||
};
|
||||
|
||||
let command = app.update_title();
|
||||
|
|
@ -128,6 +132,10 @@ impl cosmic::Application for App {
|
|||
Message::Input2(v) => {
|
||||
self.input_2 = v;
|
||||
}
|
||||
Message::Ignore => {}
|
||||
Message::ToggleHide => {
|
||||
self.hidden = !self.hidden;
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
|
@ -144,8 +152,20 @@ impl cosmic::Application for App {
|
|||
let centered = cosmic::widget::container(
|
||||
column![
|
||||
text,
|
||||
cosmic::widget::text_input::text_input("", &self.input_1)
|
||||
.on_input(Message::Input1)
|
||||
.on_clear(Message::Ignore),
|
||||
cosmic::widget::text_input::secure_input(
|
||||
"",
|
||||
&self.input_1,
|
||||
Some(Message::ToggleHide),
|
||||
self.hidden
|
||||
)
|
||||
.on_input(Message::Input1),
|
||||
cosmic::widget::text_input::text_input("", &self.input_1).on_input(Message::Input1),
|
||||
cosmic::widget::text_input::text_input("", &self.input_2).on_input(Message::Input2),
|
||||
cosmic::widget::text_input::search_input("", &self.input_2)
|
||||
.on_input(Message::Input2)
|
||||
.on_clear(Message::Ignore),
|
||||
]
|
||||
.width(iced::Length::Fill)
|
||||
.height(iced::Length::Shrink)
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ where
|
|||
value: Option<&Value>,
|
||||
style: &renderer::Style,
|
||||
) {
|
||||
let text_layout = self.text_layout(layout.clone());
|
||||
let text_layout = self.text_layout(layout);
|
||||
draw(
|
||||
renderer,
|
||||
theme,
|
||||
|
|
@ -2008,7 +2008,7 @@ pub fn draw<'a, Message>(
|
|||
|
||||
let mut children_layout = layout.children();
|
||||
let bounds = layout.bounds();
|
||||
let text_bounds = text_layout.bounds();
|
||||
let text_bounds = children_layout.next().unwrap().bounds();
|
||||
|
||||
let is_mouse_over = cursor_position.is_over(bounds);
|
||||
|
||||
|
|
@ -2115,8 +2115,11 @@ pub fn draw<'a, Message>(
|
|||
let mut child_index = 0;
|
||||
let leading_icon_tree = children.get(child_index);
|
||||
// draw the start icon in the text input
|
||||
let has_start_icon = icon.is_some();
|
||||
if let (Some(icon), Some(tree)) = (icon, leading_icon_tree) {
|
||||
let icon_layout = children_layout.next().unwrap();
|
||||
let mut children = text_layout.children();
|
||||
let _ = children.next().unwrap();
|
||||
let icon_layout = children.next().unwrap();
|
||||
|
||||
icon.as_widget().draw(
|
||||
tree,
|
||||
|
|
@ -2292,7 +2295,12 @@ pub fn draw<'a, Message>(
|
|||
|
||||
// draw the end icon in the text input
|
||||
if let (Some(icon), Some(tree)) = (trailing_icon, trailing_icon_tree) {
|
||||
let icon_layout = children_layout.next().unwrap();
|
||||
let mut children = text_layout.children();
|
||||
let mut icon_layout = children.next().unwrap();
|
||||
if has_start_icon {
|
||||
icon_layout = children.next().unwrap();
|
||||
}
|
||||
icon_layout = children.next().unwrap();
|
||||
|
||||
icon.as_widget().draw(
|
||||
tree,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue