mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibGUI: Add Widget::repaint() to force an immediate repaint
In most situations, Widget::update() is preferable, since that allows us to coalesce repaints and avoid redundant work, reducing system load. However, there are some cases where you really want a paint to happen right away, to make sure that the user has a chance to see a short-lived visual state.
This commit is contained in:
parent
da86f4e384
commit
24651f854c
4 changed files with 33 additions and 0 deletions
|
@ -616,6 +616,22 @@ void Widget::update(const Gfx::IntRect& rect)
|
||||||
window->update(bound_by_widget.translated(window_relative_rect().location()));
|
window->update(bound_by_widget.translated(window_relative_rect().location()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::repaint()
|
||||||
|
{
|
||||||
|
if (rect().is_empty())
|
||||||
|
return;
|
||||||
|
repaint(rect());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::repaint(Gfx::IntRect const& rect)
|
||||||
|
{
|
||||||
|
auto* window = this->window();
|
||||||
|
if (!window)
|
||||||
|
return;
|
||||||
|
update(rect);
|
||||||
|
window->flush_pending_paints_immediately();
|
||||||
|
}
|
||||||
|
|
||||||
Gfx::IntRect Widget::window_relative_rect() const
|
Gfx::IntRect Widget::window_relative_rect() const
|
||||||
{
|
{
|
||||||
auto rect = relative_rect();
|
auto rect = relative_rect();
|
||||||
|
|
|
@ -136,9 +136,14 @@ public:
|
||||||
Gfx::IntRect rect() const { return { 0, 0, width(), height() }; }
|
Gfx::IntRect rect() const { return { 0, 0, width(), height() }; }
|
||||||
Gfx::IntSize size() const { return m_relative_rect.size(); }
|
Gfx::IntSize size() const { return m_relative_rect.size(); }
|
||||||
|
|
||||||
|
// Invalidate the widget (or an area thereof), causing a repaint to happen soon.
|
||||||
void update();
|
void update();
|
||||||
void update(const Gfx::IntRect&);
|
void update(const Gfx::IntRect&);
|
||||||
|
|
||||||
|
// Repaint the widget (or an area thereof) immediately.
|
||||||
|
void repaint();
|
||||||
|
void repaint(Gfx::IntRect const&);
|
||||||
|
|
||||||
bool is_focused() const;
|
bool is_focused() const;
|
||||||
void set_focus(bool, FocusSource = FocusSource::Programmatic);
|
void set_focus(bool, FocusSource = FocusSource::Programmatic);
|
||||||
|
|
||||||
|
|
|
@ -1204,4 +1204,14 @@ void Window::set_modified(bool modified)
|
||||||
WindowServerConnection::the().async_set_window_modified(m_window_id, modified);
|
WindowServerConnection::the().async_set_window_modified(m_window_id, modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::flush_pending_paints_immediately()
|
||||||
|
{
|
||||||
|
if (!m_window_id)
|
||||||
|
return;
|
||||||
|
if (m_pending_paint_event_rects.is_empty())
|
||||||
|
return;
|
||||||
|
MultiPaintEvent paint_event(move(m_pending_paint_event_rects), size());
|
||||||
|
handle_multi_paint_event(paint_event);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,6 +202,8 @@ public:
|
||||||
|
|
||||||
Menu& add_menu(String name);
|
Menu& add_menu(String name);
|
||||||
|
|
||||||
|
void flush_pending_paints_immediately();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Window(Core::Object* parent = nullptr);
|
Window(Core::Object* parent = nullptr);
|
||||||
virtual void wm_event(WMEvent&);
|
virtual void wm_event(WMEvent&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue