Skip to content

Commit

Permalink
Move menu code from gui.cpp to gui/app.c
Browse files Browse the repository at this point in the history
Makes more sense like that.
  • Loading branch information
guillaumechereau committed Dec 31, 2023
1 parent 6c88390 commit 1fd412c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
* goxel. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef GUI_HAS_MENU
# define GUI_HAS_MENU 1
#endif

#ifndef GUI_HAS_SCROLLBARS
# define GUI_HAS_SCROLLBARS 1
#endif
Expand All @@ -33,7 +29,6 @@ extern "C" {

void gui_app(void);
void gui_render_panel(void);
void gui_menu(void);
}

#ifndef typeof
Expand Down Expand Up @@ -552,15 +547,22 @@ static int check_action_shortcut(action_t *action, void *user)
return 0;
}

static void render_menu(void)
bool gui_menu_bar_begin(void)
{
ImGui::PushStyleColor(ImGuiCol_PopupBg, COLOR(MENU, INNER, 0));
ImGui::PushStyleColor(ImGuiCol_Text, COLOR(MENU, TEXT, 0));
if (ImGui::BeginMainMenuBar()) {
gui_menu();
ImGui::EndMainMenuBar();
return true;
} else {
ImGui::PopStyleColor(2);
return false;
}
}

void gui_menu_bar_end(void)
{
ImGui::PopStyleColor(2);
ImGui::EndMainMenuBar();
}

static void render_popups(int index)
Expand Down Expand Up @@ -686,8 +688,6 @@ static void gui_iter(const inputs_t *inputs)

ImGui::NewFrame();

if (GUI_HAS_MENU) render_menu();

gui_app();
render_popups(0);

Expand Down
2 changes: 2 additions & 0 deletions src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ void gui_on_popup_closed(void (*func)(int v));
void gui_popup_body_begin(void);
void gui_popup_body_end(void);

bool gui_menu_bar_begin(void);
void gui_menu_bar_end(void);
bool gui_menu_begin(const char *label);
void gui_menu_end(void);
bool gui_menu_item(int action, const char *label, bool enabled);
Expand Down
15 changes: 14 additions & 1 deletion src/gui/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@
# define GUI_HAS_HELP 1
#endif

#ifndef GUI_HAS_MENU
# define GUI_HAS_MENU 1
#endif


#ifndef YOCTO
# define YOCTO 1
#endif


void gui_menu(void);
void gui_tools_panel(void);
void gui_top_bar(void);
void gui_palette_panel(void);
Expand Down Expand Up @@ -153,7 +159,14 @@ void gui_app(void)
const theme_t *theme = theme_get();
float x = 0, y = 0;

y += theme->sizes.item_height + 2;
if (GUI_HAS_MENU) {
if (gui_menu_bar_begin()) {
gui_menu();
gui_menu_bar_end();
}
y += theme->sizes.item_height + 2;
}

gui_window_begin("Top Bar", x, y, 0, 0);
gui_top_bar();
gui_window_end();
Expand Down

0 comments on commit 1fd412c

Please sign in to comment.