The UI codebase was suffering with complexity due to the need to manually convert between two different coordinate systems: - Top-down "screen coordinates" used by SDL for input and windowing. - Bottom-up "GL coordinates" used by low-level renderers. This was making layout calculations diffucult and is bug prone. With this commit, I'm introducing a 'UIRenderer' abstraction layer that wraps the low-level 'ShapeRenderer' and 'TextRenderer'. This is responsible for centralising all coordinate system conversations. All UI components has been refactored to use the 'UIRenderer' so the entire UI code opeates exclusively in a single, top-down screen coordinate system as one would expect.
		
			
				
	
	
		
			39 lines
		
	
	
		
			792 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			792 B
		
	
	
	
		
			C++
		
	
	
	
	
	
#pragma once
 | 
						|
 | 
						|
#include <string>
 | 
						|
#include <vector>
 | 
						|
#include <functional>
 | 
						|
#include <SDL3/SDL_events.h>
 | 
						|
 | 
						|
#include "ui/ui_renderer.h"
 | 
						|
 | 
						|
struct MenuItem {
 | 
						|
  std::string label;
 | 
						|
  std::function<void()> action;
 | 
						|
};
 | 
						|
 | 
						|
struct Menu {
 | 
						|
  std::string label;
 | 
						|
  std::vector<MenuItem> items;
 | 
						|
  bool is_open = false;
 | 
						|
};
 | 
						|
 | 
						|
class MenuBar {
 | 
						|
public:
 | 
						|
  MenuBar(int height);
 | 
						|
  ~MenuBar(void);
 | 
						|
 | 
						|
  void add_menu(const std::string& label);
 | 
						|
  void add_menu_item(const std::string& menu_label, const std::string& item_label,
 | 
						|
                     std::function<void()> action);
 | 
						|
 | 
						|
  void handle_event(SDL_Event* event, int window_x, int window_y);
 | 
						|
  void render(UIRenderer* ui_renderer, int x, int y, int width);
 | 
						|
 | 
						|
  int get_height(void) const;
 | 
						|
private:
 | 
						|
  int _height;
 | 
						|
  std::vector<Menu> _menus;
 | 
						|
  int _open_menu_index = -1;
 | 
						|
};
 |