diff options
author | Shannon Booth <shannon.ml.booth@gmail.com> | 2020-02-11 20:33:38 +1300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-11 11:00:09 +0100 |
commit | 97508844dc8a94f442d6800f2560fedf882becbc (patch) | |
tree | 4efa2d6e48318bc94e387e1e0bb998c2c74c7bc4 /Servers | |
parent | 14f9a29502ae96c76e1a58fb00e075c6f15ce1f1 (diff) | |
download | serenity-97508844dc8a94f442d6800f2560fedf882becbc.zip |
WindowServer: Use early return to reduce nesting
Diffstat (limited to 'Servers')
-rw-r--r-- | Servers/WindowServer/Menu.cpp | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/Servers/WindowServer/Menu.cpp b/Servers/WindowServer/Menu.cpp index e0e3726d0f..e1f6fcba1d 100644 --- a/Servers/WindowServer/Menu.cpp +++ b/Servers/WindowServer/Menu.cpp @@ -125,33 +125,36 @@ void Menu::redraw() Window& Menu::ensure_menu_window() { + if (m_menu_window) + return *m_menu_window; + int width = this->content_width(); - if (!m_menu_window) { - Gfx::Point next_item_location(frame_thickness(), frame_thickness()); - for (auto& item : m_items) { - int height = 0; - if (item.type() == MenuItem::Text) - height = item_height(); - else if (item.type() == MenuItem::Separator) - height = 8; - item.set_rect({ next_item_location, { width - frame_thickness() * 2, height } }); - next_item_location.move_by(0, height); - } - int window_height_available = Screen::the().height() - MenuManager::the().menubar_rect().height() - frame_thickness() * 2; - int max_window_height = (window_height_available / item_height()) * item_height() + frame_thickness() * 2; - int content_height = m_items.is_empty() ? 0 : (m_items.last().rect().bottom() + 1) + frame_thickness(); - int window_height = min(max_window_height, content_height); - if (window_height < content_height) { - m_scrollable = true; - m_max_scroll_offset = item_count() - window_height / item_height() + 2; - } + Gfx::Point next_item_location(frame_thickness(), frame_thickness()); + for (auto& item : m_items) { + int height = 0; + if (item.type() == MenuItem::Text) + height = item_height(); + else if (item.type() == MenuItem::Separator) + height = 8; + item.set_rect({ next_item_location, { width - frame_thickness() * 2, height } }); + next_item_location.move_by(0, height); + } - auto window = Window::construct(*this, WindowType::Menu); - window->set_rect(0, 0, width, window_height); - m_menu_window = move(window); - draw(); + int window_height_available = Screen::the().height() - MenuManager::the().menubar_rect().height() - frame_thickness() * 2; + int max_window_height = (window_height_available / item_height()) * item_height() + frame_thickness() * 2; + int content_height = m_items.is_empty() ? 0 : (m_items.last().rect().bottom() + 1) + frame_thickness(); + int window_height = min(max_window_height, content_height); + if (window_height < content_height) { + m_scrollable = true; + m_max_scroll_offset = item_count() - window_height / item_height() + 2; } + + auto window = Window::construct(*this, WindowType::Menu); + window->set_rect(0, 0, width, window_height); + m_menu_window = move(window); + draw(); + return *m_menu_window; } |