mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +00:00
LibGUI: Let Widgets track their focus proxy delegators
And update them on relevant events.
This commit is contained in:
parent
4aa608aa71
commit
3b18226fcb
2 changed files with 31 additions and 1 deletions
|
@ -633,6 +633,11 @@ void Widget::update()
|
||||||
if (rect().is_empty())
|
if (rect().is_empty())
|
||||||
return;
|
return;
|
||||||
update(rect());
|
update(rect());
|
||||||
|
|
||||||
|
for (auto& it : m_focus_delegators) {
|
||||||
|
if (!it.is_null() && !it->rect().is_empty())
|
||||||
|
it->update(it->rect());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::update(Gfx::IntRect const& rect)
|
void Widget::update(Gfx::IntRect const& rect)
|
||||||
|
@ -726,10 +731,28 @@ void Widget::set_focus_proxy(Widget* proxy)
|
||||||
{
|
{
|
||||||
if (m_focus_proxy == proxy)
|
if (m_focus_proxy == proxy)
|
||||||
return;
|
return;
|
||||||
|
if (proxy)
|
||||||
|
proxy->add_focus_delegator(this);
|
||||||
|
else if (m_focus_proxy)
|
||||||
|
m_focus_proxy->remove_focus_delegator(this);
|
||||||
m_focus_proxy = proxy;
|
m_focus_proxy = proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::add_focus_delegator(Widget* delegator)
|
||||||
|
{
|
||||||
|
m_focus_delegators.remove_all_matching([&](auto& entry) {
|
||||||
|
return entry.is_null() || entry == delegator;
|
||||||
|
});
|
||||||
|
m_focus_delegators.append(delegator);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::remove_focus_delegator(Widget* delegator)
|
||||||
|
{
|
||||||
|
m_focus_delegators.remove_first_matching([&](auto& entry) {
|
||||||
|
return entry == delegator;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
FocusPolicy Widget::focus_policy() const
|
FocusPolicy Widget::focus_policy() const
|
||||||
{
|
{
|
||||||
if (m_focus_proxy)
|
if (m_focus_proxy)
|
||||||
|
|
|
@ -226,6 +226,9 @@ public:
|
||||||
Widget const* focus_proxy() const { return m_focus_proxy; }
|
Widget const* focus_proxy() const { return m_focus_proxy; }
|
||||||
void set_focus_proxy(Widget*);
|
void set_focus_proxy(Widget*);
|
||||||
|
|
||||||
|
Vector<WeakPtr<Widget>>& focus_delegators() { return m_focus_delegators; }
|
||||||
|
Vector<WeakPtr<Widget>> const& focus_delegators() const { return m_focus_delegators; }
|
||||||
|
|
||||||
void set_focus_policy(FocusPolicy policy);
|
void set_focus_policy(FocusPolicy policy);
|
||||||
FocusPolicy focus_policy() const;
|
FocusPolicy focus_policy() const;
|
||||||
|
|
||||||
|
@ -406,6 +409,9 @@ protected:
|
||||||
|
|
||||||
void show_or_hide_tooltip();
|
void show_or_hide_tooltip();
|
||||||
|
|
||||||
|
void add_focus_delegator(Widget*);
|
||||||
|
void remove_focus_delegator(Widget*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool is_widget() const final { return true; }
|
virtual bool is_widget() const final { return true; }
|
||||||
|
|
||||||
|
@ -453,6 +459,7 @@ private:
|
||||||
String m_title { String::empty() };
|
String m_title { String::empty() };
|
||||||
|
|
||||||
WeakPtr<Widget> m_focus_proxy;
|
WeakPtr<Widget> m_focus_proxy;
|
||||||
|
Vector<WeakPtr<Widget>> m_focus_delegators;
|
||||||
FocusPolicy m_focus_policy { FocusPolicy::NoFocus };
|
FocusPolicy m_focus_policy { FocusPolicy::NoFocus };
|
||||||
|
|
||||||
AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> m_override_cursor { Gfx::StandardCursor::None };
|
AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> m_override_cursor { Gfx::StandardCursor::None };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue