mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 20:05:06 +00:00

Currently, any number of menubars can be plugged in and out of a window. This is unnecessary complexity, since we only need one menubar on a window. This commit removes most of the logic for dynamically attaching and detaching menubars and makes one menubar always available. The menubar is only considered existent if it has at least a single menu in it (in other words, an empty menubar will not be shown). This commit additionally fixes a bug wherein menus added after a menubar has been attached would not have their rects properly setup, and would therefore appear glitched out on the top left corner of the menubar.
26 lines
885 B
C++
26 lines
885 B
C++
/*
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "Menubar.h"
|
|
#include "WindowManager.h"
|
|
|
|
namespace WindowServer {
|
|
|
|
void Menubar::layout_menu(Menu& menu, Gfx::IntRect window_rect)
|
|
{
|
|
// FIXME: Maybe move this to the theming system?
|
|
static constexpr auto menubar_menu_margin = 14;
|
|
|
|
auto& wm = WindowManager::the();
|
|
auto menubar_rect = Gfx::WindowTheme::current().menubar_rect(Gfx::WindowTheme::WindowType::Normal, window_rect, wm.palette(), 1);
|
|
|
|
int text_width = wm.font().width(Gfx::parse_ampersand_string(menu.name()));
|
|
menu.set_rect_in_window_menubar({ m_next_menu_location.x(), 0, text_width + menubar_menu_margin, menubar_rect.height() });
|
|
m_next_menu_location.translate_by(menu.rect_in_window_menubar().width(), 0);
|
|
}
|
|
|
|
}
|