Support using system titlebar in Imgui backend
Some checks failed
Build / build-deb (push) Blocked by required conditions
Build / build-appimage (push) Blocked by required conditions
Build / build-android (push) Blocked by required conditions
Build / build-windows (push) Blocked by required conditions
Build / build-gentoo (push) Failing after 17s
Build / download-system-deps (push) Successful in 6m37s
Build / get-source-code (push) Has been cancelled
Some checks failed
Build / build-deb (push) Blocked by required conditions
Build / build-appimage (push) Blocked by required conditions
Build / build-android (push) Blocked by required conditions
Build / build-windows (push) Blocked by required conditions
Build / build-gentoo (push) Failing after 17s
Build / download-system-deps (push) Successful in 6m37s
Build / get-source-code (push) Has been cancelled
This commit is contained in:
parent
49ea484034
commit
68e067348b
4 changed files with 90 additions and 47 deletions
|
@ -412,15 +412,24 @@ void RendererBackend::BackendInit() {
|
|||
SDL_ShowWindow(window);
|
||||
started = true;
|
||||
}
|
||||
bool RendererBackend::UsingSystemTitlebar() {
|
||||
return enable_system_title_bar;
|
||||
}
|
||||
void RendererBackend::EnableSystemTitlebar(bool enabled) {
|
||||
enable_system_title_bar = true;
|
||||
SDL_SetWindowBordered(window, enable_system_title_bar ? SDL_TRUE : SDL_FALSE);
|
||||
}
|
||||
bool RendererBackend::BeginMainMenuBar() {
|
||||
main_menu_bar_used = true;
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
ImVec2 winsize = ImGui::GetWindowSize();
|
||||
float texsize = winsize.y;
|
||||
ImGui::SetCursorPosX(0);
|
||||
ImGui::SetCursorPosY(0);
|
||||
ImGui::Image((ImTextureID)(icon_texture), ImVec2(texsize, texsize));
|
||||
ImGui::TextUnformatted(title_text.c_str());
|
||||
if (!enable_system_title_bar) {
|
||||
ImVec2 winsize = ImGui::GetWindowSize();
|
||||
float texsize = winsize.y;
|
||||
ImGui::SetCursorPosX(0);
|
||||
ImGui::SetCursorPosY(0);
|
||||
ImGui::Image((ImTextureID)(icon_texture), ImVec2(texsize, texsize));
|
||||
ImGui::TextUnformatted(title_text.c_str());
|
||||
}
|
||||
menubar_start = ImGui::GetCursorPosX();
|
||||
return true;
|
||||
} else {
|
||||
|
@ -436,6 +445,7 @@ bool RendererBackend::is_maximized() {
|
|||
SDL_HitTestResult RendererBackend::HitTest(SDL_Window *window, const SDL_Point *area) {
|
||||
int w, h;
|
||||
bool rtop, rbottom, rleft, rright;
|
||||
if (enable_system_title_bar) return SDL_HITTEST_NORMAL;
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
rtop = area->y <= 4;
|
||||
rleft = area->x <= 4;
|
||||
|
@ -485,45 +495,47 @@ void RendererBackend::update_real_title() {
|
|||
}
|
||||
void RendererBackend::EndMainMenuBar() {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
menubar_end = ImGui::GetCursorPosX();
|
||||
ImVec2 size = ImGui::GetWindowSize();
|
||||
if (subtitle != "") {
|
||||
ImVec4 text_color = Theme::GetColor(LooperCol_Subtitle);
|
||||
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);
|
||||
ImGui::SetCursorPosY(0);
|
||||
static const size_t titlebar_btn_count = 3;
|
||||
const char *titlebar_icons[titlebar_btn_count] = {
|
||||
ICON_FK_WINDOW_MINIMIZE,
|
||||
is_maximized() ? ICON_FK_WINDOW_RESTORE : ICON_FK_WINDOW_MAXIMIZE,
|
||||
ICON_FK_WINDOW_CLOSE
|
||||
};
|
||||
float tmp = size.x;
|
||||
float padding = ImGui::GetStyle().FramePadding.x;
|
||||
float spacing = ImGui::GetStyle().ItemSpacing.x;
|
||||
for (size_t i = 0; i < titlebar_btn_count; i++) {
|
||||
tmp -= padding * 2.0f;
|
||||
// No need to use the correct index, as long as this is hit only once.
|
||||
if (i == 0) tmp -= spacing / 2.0f;
|
||||
else tmp -= spacing;
|
||||
tmp -= ImGui::CalcTextSize(titlebar_icons[i]).x;
|
||||
}
|
||||
title_btn_start = std::ceil(tmp);
|
||||
ImGui::SetCursorPosX(title_btn_start);
|
||||
if (ImGui::MenuItem(titlebar_icons[0])) {
|
||||
SDL_MinimizeWindow(window);
|
||||
}
|
||||
if (ImGui::MenuItem(titlebar_icons[1])) {
|
||||
if (is_maximized()) SDL_RestoreWindow(window);
|
||||
else SDL_MaximizeWindow(window);
|
||||
}
|
||||
if (ImGui::MenuItem(titlebar_icons[2])) {
|
||||
done = true;
|
||||
if (!enable_system_title_bar) {
|
||||
menubar_end = ImGui::GetCursorPosX();
|
||||
ImVec2 size = ImGui::GetWindowSize();
|
||||
if (subtitle != "") {
|
||||
ImVec4 text_color = Theme::GetColor(LooperCol_Subtitle);
|
||||
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);
|
||||
ImGui::SetCursorPosY(0);
|
||||
static const size_t titlebar_btn_count = 3;
|
||||
const char *titlebar_icons[titlebar_btn_count] = {
|
||||
ICON_FK_WINDOW_MINIMIZE,
|
||||
is_maximized() ? ICON_FK_WINDOW_RESTORE : ICON_FK_WINDOW_MAXIMIZE,
|
||||
ICON_FK_WINDOW_CLOSE
|
||||
};
|
||||
float tmp = size.x;
|
||||
float padding = ImGui::GetStyle().FramePadding.x;
|
||||
float spacing = ImGui::GetStyle().ItemSpacing.x;
|
||||
for (size_t i = 0; i < titlebar_btn_count; i++) {
|
||||
tmp -= padding * 2.0f;
|
||||
// No need to use the correct index, as long as this is hit only once.
|
||||
if (i == 0) tmp -= spacing / 2.0f;
|
||||
else tmp -= spacing;
|
||||
tmp -= ImGui::CalcTextSize(titlebar_icons[i]).x;
|
||||
}
|
||||
title_btn_start = std::ceil(tmp);
|
||||
ImGui::SetCursorPosX(title_btn_start);
|
||||
if (ImGui::MenuItem(titlebar_icons[0])) {
|
||||
SDL_MinimizeWindow(window);
|
||||
}
|
||||
if (ImGui::MenuItem(titlebar_icons[1])) {
|
||||
if (is_maximized()) SDL_RestoreWindow(window);
|
||||
else SDL_MaximizeWindow(window);
|
||||
}
|
||||
if (ImGui::MenuItem(titlebar_icons[2])) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ImGui::EndMainMenuBar();
|
||||
|
|
|
@ -31,7 +31,8 @@ class RendererBackend {
|
|||
int menubar_end;
|
||||
int title_btn_start;
|
||||
std::string subtitle;
|
||||
std::string title_text;
|
||||
std::string title_text;
|
||||
bool enable_system_title_bar;
|
||||
void update_real_title();
|
||||
public:
|
||||
bool is_fullscreen();
|
||||
|
@ -63,6 +64,8 @@ class RendererBackend {
|
|||
SetSubtitle("");
|
||||
}
|
||||
void SetWindowTitle(const char *title);
|
||||
bool UsingSystemTitlebar();
|
||||
void EnableSystemTitlebar(bool enabled);
|
||||
virtual void Init();
|
||||
virtual void GuiFunction();
|
||||
virtual void Deinit();
|
||||
|
|
|
@ -153,6 +153,7 @@ void MainLoop::Init() {
|
|||
theme = new Theme(darkPath);
|
||||
}
|
||||
}
|
||||
EnableSystemTitlebar(get_option<bool>("ui.imgui.enable_system_titlebar", false));
|
||||
theme->Apply(accent_color, (float)scale);
|
||||
SetWindowTitle("Looper");
|
||||
FileLoaded();
|
||||
|
@ -210,6 +211,29 @@ void MainLoop::FileLoaded() {
|
|||
properties = playback->get_property_list();
|
||||
boolean_properties.clear();
|
||||
double_properties.clear();
|
||||
int_properties.clear();
|
||||
string_properties.clear();
|
||||
for (auto &property : properties) {
|
||||
PropertyType type = property.type();
|
||||
auto name = property.path();
|
||||
auto val_maybe = playback->get_property(name);
|
||||
if (!val_maybe.has_value()) continue;
|
||||
auto val = val_maybe.value();
|
||||
switch (type) {
|
||||
case PropertyType::Int: {
|
||||
int_properties[name] = resolve_value<int>(val);
|
||||
} break;
|
||||
case PropertyType::Boolean: {
|
||||
boolean_properties[name] = resolve_value<bool>(val);
|
||||
} break;
|
||||
case PropertyType::String: {
|
||||
string_properties[name] = resolve_value<std::string>(val);
|
||||
} break;
|
||||
case PropertyType::Double: {
|
||||
double_properties[name] = resolve_value<double>(val);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void MainLoop::GuiFunction() {
|
||||
#if defined(__EMSCRIPTEN__)||defined(__ANDROID__)
|
||||
|
@ -573,6 +597,11 @@ void MainLoop::GuiFunction() {
|
|||
if (ImGui::Checkbox(_TR_CTX("Preference | Debug menu enable", "Enable debug menu in release builds"), &debug_mode)) {
|
||||
set_option<bool>("ui.imgui.debug_mode", debug_mode);
|
||||
}
|
||||
bool tmp_enable_system_title_bar = UsingSystemTitlebar();
|
||||
if (ImGui::Checkbox(_TR_CTX("Preference | System title bar", "Enable system title bar"), &tmp_enable_system_title_bar)) {
|
||||
EnableSystemTitlebar(tmp_enable_system_title_bar);
|
||||
set_option<bool>("ui.imgui.enable_system_titlebar", tmp_enable_system_title_bar);
|
||||
}
|
||||
if (ImGui::Button(_TRI_CTX(ICON_FK_MAGIC, "Preference | Related non-preference button", "Theme Editor"), ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), 0))) {
|
||||
theme_editor = true;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
using namespace std::filesystem;
|
||||
using std::string;
|
||||
#define IMGUI_FRONTEND
|
||||
|
||||
class MainLoop : public RendererBackend {
|
||||
bool show_demo_window = false;
|
||||
FileBrowser fileDialog = FileBrowser(false);
|
||||
|
|
Loading…
Add table
Reference in a new issue