Add subtitle system to imgui backend, and use it.
Some checks failed
Build / build-gentoo (push) Successful in 2m0s
Build / download-system-deps (push) Successful in 5m23s
Build / get-source-code (push) Successful in 13m49s
Build / build-deb (push) Failing after 5m19s
Build / build-appimage (push) Successful in 4m35s
Build / build-android (push) Failing after 2m50s
Build / build-windows (push) Failing after 7m18s

This commit is contained in:
Zachary Hall 2025-01-15 08:54:52 -08:00
parent 84b324e01c
commit 0bcb5d42d2
3 changed files with 36 additions and 8 deletions

View file

@ -17,6 +17,8 @@
#include <log.hpp>
#include <options.hpp>
#include <web_functions.hpp>
#include <fmt/core.h>
#include <fmt/format.h>
using std::vector;
using namespace Looper::Options;
void RendererBackend::on_resize() {
@ -222,7 +224,8 @@ RendererBackend::~RendererBackend() {
renderer_backend = nullptr;
}
void RendererBackend::SetWindowTitle(const char *title) {
SDL_SetWindowTitle(window, title);
this->title_text = title;
update_real_title();
}
void RendererBackend::GuiFunction() {
// Do nothing by default.
@ -414,12 +417,11 @@ bool RendererBackend::BeginMainMenuBar() {
if (ImGui::BeginMainMenuBar()) {
ImVec2 winsize = ImGui::GetWindowSize();
float texsize = winsize.y;
ImGui::SetCursorPosX(0);
ImGui::SetCursorPosY(0);
ImGui::SetCursorPosX(0);
ImGui::SetCursorPosY(0);
ImGui::Image((ImTextureID)(icon_texture), ImVec2(texsize, texsize));
//ImGui::SetCursorPosY((winsize.y - ImGui::GetFrameHeight()) / 2);
ImGui::TextUnformatted(SDL_GetWindowTitle(window));
menubar_start = ImGui::GetCursorPosX();
ImGui::TextUnformatted(title_text.c_str());
menubar_start = ImGui::GetCursorPosX();
return true;
} else {
return false;
@ -470,10 +472,28 @@ SDL_HitTestResult RendererBackend::HitTest(SDL_Window *window, const SDL_Point *
}
}
void RendererBackend::SetSubtitle(const char *subtitle) {
this->subtitle = subtitle;
update_real_title();
}
void RendererBackend::update_real_title() {
if (subtitle == "") {
SDL_SetWindowTitle(window, title_text.c_str());
} else {
SDL_SetWindowTitle(window, fmt::format("{} - {}", subtitle, title_text).c_str());
}
}
void RendererBackend::EndMainMenuBar() {
#ifndef __EMSCRIPTEN__
menubar_end = ImGui::GetCursorPosX();
ImVec2 size = ImGui::GetWindowSize();
if (subtitle != "") {
ImVec4 text_color = ImGui::GetStyleColorVec4(ImGuiCol_Text);
text_color.w *= 0.5;
ImGui::PushStyleColor(ImGuiCol_Text, text_color);
ImGui::TextUnformatted(subtitle.c_str());
ImGui::PopStyleColor();
}
float btnw = size.y;
int btn_count = 3;
ImVec2 btn_size(btnw, btnw);

View file

@ -30,6 +30,9 @@ class RendererBackend {
int menubar_start;
int menubar_end;
int title_btn_start;
std::string subtitle;
std::string title_text;
void update_real_title();
public:
bool is_fullscreen();
bool is_maximized();
@ -55,6 +58,10 @@ class RendererBackend {
const char *prefPath;
ImVec4 accent_color = ImVec4(0.75, 1.0, 1.0, 1.0);
int Run();
void SetSubtitle(const char *subtitle);
inline void ClearSubtitle() {
SetSubtitle("");
}
void SetWindowTitle(const char *title);
virtual void Init();
virtual void GuiFunction();

View file

@ -154,6 +154,7 @@ void MainLoop::Init() {
}
}
theme->Apply(accent_color, (float)scale);
SetWindowTitle("Looper");
FileLoaded();
}
void MainLoop::Drop(std::string file) {
@ -201,9 +202,9 @@ void MainLoop::FileLoaded() {
auto file_maybe = playback->get_current_title();
if (file_maybe.has_value()) {
auto name = file_maybe.value();
SetWindowTitle((name + std::string(" - Looper")).c_str());
SetSubtitle(name.c_str());
} else {
SetWindowTitle("Looper");
ClearSubtitle();
}
streams = playback->get_streams();
properties = playback->get_property_list();