Skip to content

Commit

Permalink
Gui: avoid hardcodding item height
Browse files Browse the repository at this point in the history
Instead I added a function got retreive the height when we need it for
layout.

In preparation of supporting different font sizes.
  • Loading branch information
guillaumechereau committed Oct 20, 2024
1 parent 8ae26ff commit e457f00
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1999,3 +1999,9 @@ void gui_set_current_pos_x(float x)
{
ImGui::SetCursorPosX(x);
}

float gui_get_item_height(void)
{
ImGuiStyle& style = ImGui::GetStyle();
return style.FramePadding.y * 2 + ImGui::GetFontSize();
}
1 change: 1 addition & 0 deletions src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,6 @@ void gui_context_menu_button(const char *label, int icon);
*/
float gui_get_current_pos_x(void);
void gui_set_current_pos_x(float x);
float gui_get_item_height(void);

#endif // GUI_H
8 changes: 3 additions & 5 deletions src/gui/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
#define INITIAL_FILTER_OFFSET 10
#define RELATIVE_FILTER_OFFSET 40

// Note: duplicated from gui.cpp! To remove.
static const float ITEM_HEIGHT = 18;

void gui_edit_panel(void);
void gui_menu(void);
void gui_tools_panel(void);
Expand Down Expand Up @@ -199,6 +196,7 @@ void gui_app(void)
int flags;
int i;
filter_layout_state_t filter_layout_state;
const float item_height = gui_get_item_height();

goxel.show_export_viewport = false;

Expand All @@ -211,7 +209,7 @@ void gui_app(void)
render_hints(goxel.hints);
gui_menu_bar_end();
}
y = ITEM_HEIGHT + 2;
y = item_height + 2;
}

gui_window_begin("Top Bar", x, y, 0, 0, 0);
Expand Down Expand Up @@ -259,5 +257,5 @@ void gui_app(void)
(goxel.gui.current_panel == PANEL_RENDER ||
PANELS[PANEL_RENDER].detached);

gui_view_cube(goxel.gui.viewport[2] - 128, ITEM_HEIGHT + 2, 128, 128);
gui_view_cube(goxel.gui.viewport[2] - 128, item_height + 2, 128, 128);
}

0 comments on commit e457f00

Please sign in to comment.