From 404f65867d5ecb4920d096374e0990ca2fb79362 Mon Sep 17 00:00:00 2001 From: Ritchie Cunningham Date: Tue, 14 Oct 2025 18:52:47 +0100 Subject: [PATCH] [Refactor] Separate MenuBar bg and text rendering. --- client/src/ui/editor.cpp | 19 +++++++++++-------- client/src/ui/menu_bar.cpp | 15 +++++---------- client/src/ui/menu_bar.h | 3 ++- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/client/src/ui/editor.cpp b/client/src/ui/editor.cpp index 44d437c..b1bf9b7 100644 --- a/client/src/ui/editor.cpp +++ b/client/src/ui/editor.cpp @@ -52,17 +52,20 @@ void Editor::render(const RenderContext& context, int x, int y_screen, int y_gl, int content_y = y_screen + menu_bar_height; int content_height = height - menu_bar_height; - /* - * Render editor in two passes to ensure the dropdown - * menu appears on top of the main text view. - */ - /* Pass 1: Main Content. */ - context.ui_renderer->begin_text(); - _menu_bar->render_bar(context.ui_renderer, x, y_screen, width); + /* Pass 1: Main Bar Background.*/ + context.ui_renderer->begin_shapes(); + _menu_bar->render_bar_bg(context.ui_renderer, x, y_screen, width); + context.ui_renderer->flush_shapes(); + + /* Pass 2: Main text view. */ _view->render(context.ui_renderer, x, content_y, width, content_height, context.show_cursor); + + /* Pass 3: Menu bar text and dropdown. */ + context.ui_renderer->begin_text(); + _menu_bar->render_bar_text(context.ui_renderer, x, y_screen, width); context.ui_renderer->flush_text(); - /* Pass 2: Dropdown Menu. */ + /* Pass 4: Dropdown menu. */ context.ui_renderer->begin_text(); _menu_bar->render_dropdown(context.ui_renderer, x, y_screen, width); context.ui_renderer->flush_text(); diff --git a/client/src/ui/menu_bar.cpp b/client/src/ui/menu_bar.cpp index 205fd28..e0d4e34 100644 --- a/client/src/ui/menu_bar.cpp +++ b/client/src/ui/menu_bar.cpp @@ -72,25 +72,20 @@ void MenuBar::handle_event(SDL_Event* event, int window_x, int window_y) { } } -void MenuBar::render_bar(UIRenderer* ui_renderer, int x, int y, int width) { +void MenuBar::render_bar_bg(UIRenderer* ui_renderer, int x, int y, int width) { const Color bg_color = { 0.15f, 0.17f, 0.19f }; - const Color text_color = { 0.9f, 0.9f, 0.9f }; - - ui_renderer->begin_shapes(); - ui_renderer->begin_text(); - ui_renderer->draw_rect(x, y, width, _height, bg_color); +} + +void MenuBar::render_bar_text(UIRenderer *ui_renderer, int x, int y, int width) { + const Color text_color = { 0.9f, 0.9f, 0.9f }; int menu_x = x; for(size_t i = 0; i < _menus.size(); ++i) { int menu_width = 60; ui_renderer->render_text(_menus[i].label.c_str(), menu_x+10, y+20, text_color); - menu_x += menu_width; } - - ui_renderer->flush_shapes(); - ui_renderer->flush_text(); } void MenuBar::render_dropdown(UIRenderer* ui_renderer, int x, int y, int width ) { diff --git a/client/src/ui/menu_bar.h b/client/src/ui/menu_bar.h index 06ed1ae..7774f3a 100644 --- a/client/src/ui/menu_bar.h +++ b/client/src/ui/menu_bar.h @@ -28,7 +28,8 @@ public: std::function action); void handle_event(SDL_Event* event, int window_x, int window_y); - void render_bar(UIRenderer* ui_renderer, int x, int y, int width); + void render_bar_bg(UIRenderer* ui_renderer, int x, int y, int width); + void render_bar_text(UIRenderer* ui_renderer, int x, int y, int width); void render_dropdown(UIRenderer* ui_renderer, int x, int y, int width); int get_height(void) const;