Fix ComboBox widget not displaying selection text
This commit is contained in:
parent
6d379b7fce
commit
bc1bde0d5c
2 changed files with 50 additions and 3 deletions
|
|
@ -311,7 +311,20 @@ where
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
limits: &layout::Limits,
|
limits: &layout::Limits,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
self.text_input.layout(tree, renderer, limits)
|
let is_focused = {
|
||||||
|
let text_input_state = tree.children[0]
|
||||||
|
.state
|
||||||
|
.downcast_ref::<text_input::State<Renderer::Paragraph>>();
|
||||||
|
|
||||||
|
text_input_state.is_focused()
|
||||||
|
};
|
||||||
|
|
||||||
|
self.text_input.layout(
|
||||||
|
&mut tree.children[0],
|
||||||
|
renderer,
|
||||||
|
limits,
|
||||||
|
(!is_focused).then_some(&self.selection),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tag(&self) -> widget::tree::Tag {
|
fn tag(&self) -> widget::tree::Tag {
|
||||||
|
|
@ -665,7 +678,15 @@ where
|
||||||
menu,
|
menu,
|
||||||
&filtered_options.options,
|
&filtered_options.options,
|
||||||
hovered_option,
|
hovered_option,
|
||||||
|x| (self.on_selected)(x),
|
|x| {
|
||||||
|
tree.children[0]
|
||||||
|
.state
|
||||||
|
.downcast_mut::<text_input::State<Renderer::Paragraph>>(
|
||||||
|
)
|
||||||
|
.unfocus();
|
||||||
|
|
||||||
|
(self.on_selected)(x)
|
||||||
|
},
|
||||||
self.on_option_hovered.as_deref(),
|
self.on_option_hovered.as_deref(),
|
||||||
)
|
)
|
||||||
.width(bounds.width)
|
.width(bounds.width)
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,32 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lays out the [`TextInput`], overriding its [`Value`] if provided.
|
||||||
|
///
|
||||||
|
/// [`Renderer`]: text::Renderer
|
||||||
|
pub fn layout(
|
||||||
|
&self,
|
||||||
|
tree: &mut Tree,
|
||||||
|
renderer: &Renderer,
|
||||||
|
limits: &layout::Limits,
|
||||||
|
value: Option<&Value>,
|
||||||
|
) -> layout::Node {
|
||||||
|
layout(
|
||||||
|
renderer,
|
||||||
|
limits,
|
||||||
|
self.width,
|
||||||
|
self.padding,
|
||||||
|
self.size,
|
||||||
|
self.font,
|
||||||
|
self.line_height,
|
||||||
|
self.icon.as_ref(),
|
||||||
|
tree.state.downcast_mut::<State<Renderer::Paragraph>>(),
|
||||||
|
value.unwrap_or(&self.value),
|
||||||
|
&self.placeholder,
|
||||||
|
self.is_secure,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Draws the [`TextInput`] with the given [`Renderer`], overriding its
|
/// Draws the [`TextInput`] with the given [`Renderer`], overriding its
|
||||||
/// [`Value`] if provided.
|
/// [`Value`] if provided.
|
||||||
///
|
///
|
||||||
|
|
@ -1411,7 +1437,7 @@ fn find_cursor_position<P: text::Paragraph>(
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
unicode_segmentation::UnicodeSegmentation::graphemes(
|
unicode_segmentation::UnicodeSegmentation::graphemes(
|
||||||
&value[..char_offset],
|
&value[..char_offset.min(value.len())],
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
.count(),
|
.count(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue