166 lines
4.5 KiB
C++
166 lines
4.5 KiB
C++
#pragma once
|
|
|
|
#include "StyleTokens.h"
|
|
|
|
#include <imgui.h>
|
|
|
|
namespace XCEngine {
|
|
namespace Editor {
|
|
namespace UI {
|
|
|
|
inline float DefaultControlLabelWidth() {
|
|
return InspectorPropertyLabelWidth();
|
|
}
|
|
|
|
inline ImVec2 DefaultControlCellPadding() {
|
|
return ControlCellPadding();
|
|
}
|
|
|
|
inline ImVec2 DefaultControlFramePadding() {
|
|
return ControlFramePadding();
|
|
}
|
|
|
|
inline void PushControlRowStyles() {
|
|
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, DefaultControlCellPadding());
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, DefaultControlFramePadding());
|
|
}
|
|
|
|
template <typename DrawControlFn>
|
|
inline auto DrawControlRow(
|
|
const char* label,
|
|
float columnWidth,
|
|
DrawControlFn&& drawControl) -> decltype(drawControl()) {
|
|
using Result = decltype(drawControl());
|
|
|
|
Result result{};
|
|
ImGui::PushID(label);
|
|
PushControlRowStyles();
|
|
|
|
if (ImGui::BeginTable("##ControlRow", 2, ImGuiTableFlags_NoSavedSettings)) {
|
|
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
|
ImGui::TableSetupColumn("##control", ImGuiTableColumnFlags_WidthStretch);
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + ControlRowHeightOffset());
|
|
|
|
ImGui::TableNextColumn();
|
|
ImGui::AlignTextToFramePadding();
|
|
ImGui::TextUnformatted(label);
|
|
|
|
ImGui::TableNextColumn();
|
|
result = drawControl();
|
|
|
|
ImGui::EndTable();
|
|
}
|
|
|
|
ImGui::PopStyleVar(2);
|
|
ImGui::PopID();
|
|
return result;
|
|
}
|
|
|
|
inline void StyleVarPush(ImGuiStyleVar idx, float val) {
|
|
ImGui::PushStyleVar(idx, val);
|
|
}
|
|
|
|
inline void StyleVarPush(ImGuiStyleVar idx, ImVec2 val) {
|
|
ImGui::PushStyleVar(idx, val);
|
|
}
|
|
|
|
inline void StyleColorPush(ImGuiCol idx, ImU32 col) {
|
|
ImGui::PushStyleColor(idx, col);
|
|
}
|
|
|
|
inline void StyleColorPush(ImGuiCol idx, ImVec4 col) {
|
|
ImGui::PushStyleColor(idx, col);
|
|
}
|
|
|
|
inline void PopStyleVar(int count = 1) {
|
|
ImGui::PopStyleVar(count);
|
|
}
|
|
|
|
inline void PopStyleColor(int count = 1) {
|
|
ImGui::PopStyleColor(count);
|
|
}
|
|
|
|
inline void PushPopupWindowStyle() {
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, PopupWindowPadding());
|
|
}
|
|
|
|
inline bool BeginPopup(const char* str_id, ImGuiWindowFlags flags = 0) {
|
|
PushPopupWindowStyle();
|
|
bool is_open = ImGui::BeginPopup(str_id, flags);
|
|
if (!is_open) {
|
|
ImGui::PopStyleVar();
|
|
}
|
|
return is_open;
|
|
}
|
|
|
|
inline bool BeginPopupContextItem(const char* str_id = nullptr, ImGuiPopupFlags popup_flags = ImGuiPopupFlags_MouseButtonRight) {
|
|
PushPopupWindowStyle();
|
|
bool is_open = ImGui::BeginPopupContextItem(str_id, popup_flags);
|
|
if (!is_open) {
|
|
ImGui::PopStyleVar();
|
|
}
|
|
return is_open;
|
|
}
|
|
|
|
inline bool BeginPopupContextWindow(const char* str_id = nullptr, ImGuiPopupFlags popup_flags = ImGuiPopupFlags_MouseButtonRight) {
|
|
PushPopupWindowStyle();
|
|
bool is_open = ImGui::BeginPopupContextWindow(str_id, popup_flags);
|
|
if (!is_open) {
|
|
ImGui::PopStyleVar();
|
|
}
|
|
return is_open;
|
|
}
|
|
|
|
inline bool BeginModalPopup(
|
|
const char* name,
|
|
bool* p_open = nullptr,
|
|
ImGuiWindowFlags flags = ImGuiWindowFlags_AlwaysAutoResize) {
|
|
PushPopupWindowStyle();
|
|
bool is_open = ImGui::BeginPopupModal(name, p_open, flags);
|
|
if (!is_open) {
|
|
ImGui::PopStyleVar();
|
|
}
|
|
return is_open;
|
|
}
|
|
|
|
inline void EndPopup() {
|
|
ImGui::EndPopup();
|
|
ImGui::PopStyleVar();
|
|
}
|
|
|
|
inline void BeginDisabled(bool disabled = true) {
|
|
if (disabled) {
|
|
ImGui::BeginDisabled();
|
|
}
|
|
}
|
|
|
|
inline void EndDisabled(bool disabled = true) {
|
|
if (disabled) {
|
|
ImGui::EndDisabled();
|
|
}
|
|
}
|
|
|
|
inline void DrawCurrentWindowBottomBorder(ImU32 color = PanelDividerColor()) {
|
|
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
|
const ImVec2 min = ImGui::GetWindowPos();
|
|
const ImVec2 max = ImVec2(min.x + ImGui::GetWindowSize().x, min.y + ImGui::GetWindowSize().y);
|
|
drawList->AddLine(ImVec2(min.x, max.y - 1.0f), ImVec2(max.x, max.y - 1.0f), color);
|
|
}
|
|
|
|
inline bool ToolbarButton(const char* label, bool active = false, ImVec2 size = ImVec2(0.0f, 0.0f)) {
|
|
const ImVec4 buttonColor = ToolbarButtonColor(active);
|
|
const ImVec4 hoverColor = ToolbarButtonHoveredColor(active);
|
|
const ImVec4 activeColor = ToolbarButtonActiveColor();
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, buttonColor);
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, hoverColor);
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, activeColor);
|
|
const bool pressed = ImGui::Button(label, size);
|
|
ImGui::PopStyleColor(3);
|
|
return pressed;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|