mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 18:02:44 +00:00 
			
		
		
		
	 611370e7dc
			
		
	
	
		611370e7dc
		
	
	
	
	
		
			
			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.
		
			
				
	
	
		
			49 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  * Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include "Menu.h"
 | |
| #include <AK/Function.h>
 | |
| #include <AK/IterationDecision.h>
 | |
| #include <AK/Vector.h>
 | |
| 
 | |
| namespace WindowServer {
 | |
| 
 | |
| class Menubar {
 | |
| public:
 | |
|     void add_menu(Menu& menu, Gfx::IntRect window_rect)
 | |
|     {
 | |
|         // FIXME: Check against duplicate menu additions.
 | |
|         m_menus.append(menu);
 | |
|         layout_menu(menu, window_rect);
 | |
|     }
 | |
| 
 | |
|     bool has_menus()
 | |
|     {
 | |
|         return !m_menus.is_empty();
 | |
|     }
 | |
| 
 | |
|     void for_each_menu(Function<IterationDecision(Menu&)> callback)
 | |
|     {
 | |
|         for (auto& menu : m_menus) {
 | |
|             if (callback(menu) == IterationDecision::Break)
 | |
|                 return;
 | |
|         }
 | |
|     }
 | |
| 
 | |
| private:
 | |
|     void layout_menu(Menu&, Gfx::IntRect window_rect);
 | |
| 
 | |
|     Vector<Menu&> m_menus;
 | |
| 
 | |
|     // FIXME: This doesn't support removing menus from a menubar or inserting a
 | |
|     //        menu in the middle.
 | |
|     Gfx::IntPoint m_next_menu_location { 0, 0 };
 | |
| };
 | |
| 
 | |
| }
 |