mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
WindowServer: Draw a coolbar border around the hovered switcher item
This gives a small but nice indication that the switcher window list items are clickable. :^)
This commit is contained in:
parent
4c620dea83
commit
0f00e9a1c7
2 changed files with 31 additions and 11 deletions
|
@ -77,15 +77,28 @@ void WindowSwitcher::event(Core::Event& event)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& mouse_event = static_cast<MouseEvent&>(event);
|
auto& mouse_event = static_cast<MouseEvent&>(event);
|
||||||
if (mouse_event.type() == Event::MouseDown) {
|
int new_hovered_index = -1;
|
||||||
for (int i = 0; i < m_windows.size(); ++i) {
|
for (int i = 0; i < m_windows.size(); ++i) {
|
||||||
auto item_rect = this->item_rect(i);
|
auto item_rect = this->item_rect(i);
|
||||||
if (item_rect.contains(mouse_event.position())) {
|
if (item_rect.contains(mouse_event.position())) {
|
||||||
select_window_at_index(i);
|
new_hovered_index = i;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mouse_event.type() == Event::MouseMove) {
|
||||||
|
if (m_hovered_index != new_hovered_index) {
|
||||||
|
m_hovered_index = new_hovered_index;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_hovered_index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (mouse_event.type() == Event::MouseDown)
|
||||||
|
select_window_at_index(new_hovered_index);
|
||||||
|
|
||||||
event.accept();
|
event.accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +155,11 @@ void WindowSwitcher::select_window_at_index(int index)
|
||||||
auto* highlight_window = m_windows.at(index).ptr();
|
auto* highlight_window = m_windows.at(index).ptr();
|
||||||
ASSERT(highlight_window);
|
ASSERT(highlight_window);
|
||||||
WindowManager::the().set_highlight_window(highlight_window);
|
WindowManager::the().set_highlight_window(highlight_window);
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowSwitcher::redraw()
|
||||||
|
{
|
||||||
draw();
|
draw();
|
||||||
WindowManager::the().invalidate(m_rect);
|
WindowManager::the().invalidate(m_rect);
|
||||||
}
|
}
|
||||||
|
@ -172,6 +190,8 @@ void WindowSwitcher::draw()
|
||||||
text_color = palette.selection_text();
|
text_color = palette.selection_text();
|
||||||
rect_text_color = palette.threed_shadow1();
|
rect_text_color = palette.threed_shadow1();
|
||||||
} else {
|
} else {
|
||||||
|
if (index == m_hovered_index)
|
||||||
|
Gfx::StylePainter::paint_button(painter, item_rect, palette, Gfx::ButtonStyle::CoolBar, false, true);
|
||||||
text_color = palette.window_text();
|
text_color = palette.window_text();
|
||||||
rect_text_color = palette.threed_shadow2();
|
rect_text_color = palette.threed_shadow2();
|
||||||
}
|
}
|
||||||
|
@ -222,15 +242,13 @@ void WindowSwitcher::refresh()
|
||||||
if (!m_switcher_window)
|
if (!m_switcher_window)
|
||||||
m_switcher_window = Window::construct(*this, WindowType::WindowSwitcher);
|
m_switcher_window = Window::construct(*this, WindowType::WindowSwitcher);
|
||||||
m_switcher_window->set_rect(m_rect);
|
m_switcher_window->set_rect(m_rect);
|
||||||
draw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowSwitcher::refresh_if_needed()
|
void WindowSwitcher::refresh_if_needed()
|
||||||
{
|
{
|
||||||
if (m_visible) {
|
if (m_visible)
|
||||||
refresh();
|
refresh();
|
||||||
WindowManager::the().invalidate(m_rect);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ public:
|
||||||
Window* switcher_window() { return m_switcher_window.ptr(); }
|
Window* switcher_window() { return m_switcher_window.ptr(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void redraw();
|
||||||
void select_window_at_index(int index);
|
void select_window_at_index(int index);
|
||||||
Gfx::Rect item_rect(int index) const;
|
Gfx::Rect item_rect(int index) const;
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ private:
|
||||||
bool m_visible { false };
|
bool m_visible { false };
|
||||||
Vector<WeakPtr<Window>> m_windows;
|
Vector<WeakPtr<Window>> m_windows;
|
||||||
int m_selected_index { 0 };
|
int m_selected_index { 0 };
|
||||||
|
int m_hovered_index { -1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue