feat(gui): add status bar

This commit is contained in:
Rodrigo Verdiani 2025-12-27 19:58:29 -03:00
parent 34d08212f8
commit a9a0393066
3 changed files with 40 additions and 1 deletions

3
app.c
View File

@ -13,7 +13,8 @@ void App_Init(App_t *app) {
System_QueryMetrics(&app->metrics);
if (!Window_Init(app->metrics.screenWidth, app->metrics.screenHeight)) {
// TODO: start this window maximized
if (!Window_Init(800, 600)) {
return;
}

35
gui.c
View File

@ -27,6 +27,7 @@ void Gui_Init(Gui_t *gui) {
cImGui_ImplSDLRenderer3_Init(renderer);
gui->isPreferencesDialogOpen = false;
gui->statusBarText = "Welcome to Tibia!";
}
void Gui_ProcessEvent(const SDL_Event *event) {
@ -41,6 +42,7 @@ void Gui_StartRender() {
void Gui_Render(Gui_t *gui, ConfigParams_t *configParams) {
Gui_RenderMainMenu(gui);
Gui_RenderStatusBar(gui);
Gui_RenderPreferences_Dialog(gui, configParams);
}
@ -122,6 +124,39 @@ void Gui_RenderMainMenu(Gui_t *gui) {
ImGui_EndMainMenuBar();
}
void Gui_RenderStatusBar(const Gui_t* gui) {
const ImGuiViewport *viewport = ImGui_GetMainViewport();
const float height = ImGui_GetFrameHeight();
const ImVec2 position = {viewport->Pos.x, viewport->Pos.y + viewport->Size.y - height};
const ImVec2 size = {viewport->Size.x, height};
ImGui_SetNextWindowPosEx(position, ImGuiCond_Always, (ImVec2){0.0f, 0.0f});
ImGui_SetNextWindowSize(size, ImGuiCond_Always);
// Remove rounding, borders and reduce padding
ImGui_PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui_PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui_PushStyleVarImVec2(ImGuiStyleVar_WindowPadding, (ImVec2){8.0f, 2.0f});
// Set background and text colors
ImGui_PushStyleColorImVec4(ImGuiCol_WindowBg, (ImVec4){0.85f, 0.85f, 0.85f, 1.0f});
ImGui_PushStyleColorImVec4(ImGuiCol_Text, (ImVec4){0.0f, 0.0f, 0.0f, 1.0f});
const ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNav;
if (ImGui_Begin("StatusBar", NULL, windowFlags)) {
ImGui_Text(gui->statusBarText);
}
ImGui_End();
ImGui_PopStyleColorEx(2);
ImGui_PopStyleVarEx(3);
}
void Gui_RenderPreferences_Dialog(Gui_t *gui, ConfigParams_t *configParams) {
if (!gui->isPreferencesDialogOpen) {
return;

3
gui.h
View File

@ -11,6 +11,7 @@
typedef struct Gui {
bool isPreferencesDialogOpen;
char* statusBarText;
} Gui_t;
void Gui_Init(Gui_t* gui);
@ -21,6 +22,8 @@ void Gui_FinishRender();
void Gui_Shutdown();
void Gui_RenderMainMenu(Gui_t* gui);
void Gui_RenderStatusBar(const Gui_t* gui);
void Gui_RenderPreferences_Dialog(Gui_t* gui, ConfigParams_t* configParams);
#endif //TIBIA_GUI_H