hide chat input when not typing

Former-commit-id: a1982ef2edf991c94cea359a2892cbf13ef8e980
This commit is contained in:
Imbris 2019-04-20 11:43:38 -04:00
parent 85dda5e505
commit 67584a49ce

View File

@ -83,34 +83,42 @@ impl Chat {
self.new_messages = false;
}
// Only show if it has the keyboard captured
// Chat input with rectangle as background
let text_edit = TextEdit::new(&self.input)
.w(460.0)
.restrict_to_height(false)
.line_spacing(2.0)
.font_size(15)
.font_id(font);
let y = match text_edit.get_y_dimension(ui_widgets) {
Dimension::Absolute(y) => y + 6.0,
_ => 0.0,
};
Rectangle::fill([470.0, y])
.rgba(0.0, 0.0, 0.0, 0.8)
.bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0)
.w(470.0)
.set(self.ids.input_bg, ui_widgets);
if let Some(str) = text_edit
.top_left_with_margins_on(self.ids.input_bg, 1.0, 1.0)
.set(self.ids.input, ui_widgets)
{
self.input = str.to_string();
self.input.retain(|c| c != '\n');
let keyboard_captured = ui_widgets.global_input().current.widget_capturing_keyboard.map_or(false, |id| id == self.ids.input);
if keyboard_captured {
let text_edit = TextEdit::new(&self.input)
.w(460.0)
.restrict_to_height(false)
.line_spacing(2.0)
.font_size(15)
.font_id(font);
let y = match text_edit.get_y_dimension(ui_widgets) {
Dimension::Absolute(y) => y + 6.0,
_ => 0.0,
};
Rectangle::fill([470.0, y])
.rgba(0.0, 0.0, 0.0, 0.8)
.bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0)
.w(470.0)
.set(self.ids.input_bg, ui_widgets);
if let Some(str) = text_edit
.top_left_with_margins_on(self.ids.input_bg, 1.0, 1.0)
.set(self.ids.input, ui_widgets)
{
self.input = str.to_string();
self.input.retain(|c| c != '\n');
}
}
// Message box
Rectangle::fill([470.0, 174.0])
.rgba(0.0, 0.0, 0.0, 0.4)
.up_from(self.ids.input_bg, 0.0)
.and(|r| if keyboard_captured {
r.up_from(self.ids.input_bg, 0.0)
} else {
r.bottom_left_with_margins_on(ui_widgets.window, 10.0, 10.0)
})
.set(self.ids.message_box_bg, ui_widgets);
let (mut items, _) = List::flow_down(self.messages.len() + 1)
.top_left_of(self.ids.message_box_bg)