Display top contents in hover widget when focused

This commit is contained in:
Héctor Ramón Jiménez 2024-08-08 01:25:15 +02:00
parent 422568dee4
commit 0ce81a0e0e
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -4,7 +4,8 @@ use crate::checkbox::{self, Checkbox};
use crate::combo_box::{self, ComboBox};
use crate::container::{self, Container};
use crate::core;
use crate::core::widget::operation;
use crate::core::widget::operation::{self, Operation};
use crate::core::window;
use crate::core::{Element, Length, Pixels, Widget};
use crate::keyed;
use crate::overlay;
@ -397,6 +398,7 @@ where
struct Hover<'a, Message, Theme, Renderer> {
base: Element<'a, Message, Theme, Renderer>,
top: Element<'a, Message, Theme, Renderer>,
is_top_focused: bool,
is_top_overlay_active: bool,
}
@ -472,7 +474,9 @@ where
viewport,
);
if cursor.is_over(layout.bounds()) || self.is_top_overlay_active
if cursor.is_over(layout.bounds())
|| self.is_top_focused
|| self.is_top_overlay_active
{
let (top_layout, top_tree) = children.next().unwrap();
@ -515,6 +519,24 @@ where
) -> event::Status {
let mut children = layout.children().zip(&mut tree.children);
let (base_layout, base_tree) = children.next().unwrap();
let (top_layout, top_tree) = children.next().unwrap();
if matches!(event, Event::Window(window::Event::RedrawRequested(_)))
{
let mut count_focused = operation::focusable::count();
self.top.as_widget_mut().operate(
top_tree,
top_layout,
renderer,
&mut operation::black_box(&mut count_focused),
);
self.is_top_focused = match count_focused.finish() {
operation::Outcome::Some(count) => count.focused.is_some(),
_ => false,
};
}
let top_status = if matches!(
event,
@ -523,10 +545,9 @@ where
| mouse::Event::ButtonReleased(_)
)
) || cursor.is_over(layout.bounds())
|| self.is_top_focused
|| self.is_top_overlay_active
{
let (top_layout, top_tree) = children.next().unwrap();
self.top.as_widget_mut().on_event(
top_tree,
event.clone(),
@ -612,6 +633,7 @@ where
Element::new(Hover {
base: base.into(),
top: top.into(),
is_top_focused: false,
is_top_overlay_active: false,
})
}