style.cpp

cross platform rendering playground

src/editor/style.cpp

3.31 KB
#ifdef ENABLE_EDITOR
#define IMGUI_DEFINE_MATH_OPERATORS
#include "editor.h"

#include <imgui.h>

namespace editor {

constexpr ImVec4 ACCENT{0.26f, 0.59f, 0.98f, 1.00f};
constexpr ImVec4 ACCENT_DIM{0.26f, 0.59f, 0.98f, 0.45f};
constexpr ImVec4 WARNING{0.95f, 0.75f, 0.30f, 1.00f};
constexpr ImVec4 DANGER{0.90f, 0.42f, 0.40f, 1.00f};
constexpr ImVec4 MUTED{0.55f, 0.57f, 0.60f, 1.00f};
constexpr ImVec4 PLAYING{0.35f, 0.82f, 0.45f, 1.00f};
constexpr ImVec4 IDLE{0.78f, 0.80f, 0.84f, 1.00f};

ImVec4 grey(f32 v, f32 a = 1.f) {
    return {v, v, v, a};
}

void apply_style(f32 scale, ImGuiStyle &style) {
    style.WindowMenuButtonPosition = ImGuiDir_None;

    style.FramePadding.y = 7.0f;
    style.DockingSeparatorSize = 1.0f;
    style.SeparatorTextBorderSize = 1.0f;
    style.GrabRounding = 4.0f;

    style.WindowBorderSize = 1.0f;
    style.WindowRounding = 6.0f;

    style.ChildBorderSize = 1.0f;
    style.ChildRounding = 6.0f;

    style.PopupBorderSize = 1.0f;
    style.PopupRounding = 6.0f;

    style.FrameBorderSize = 0.0f;
    style.FrameRounding = 4.0f;

    style.MenuItemRounding = 4.0f;
    style.ScrollbarPadding = 0.0f;
    style.ScrollbarSize = 14.0f;

    ImVec4 *c = style.Colors;

    c[ImGuiCol_Text] = grey(0.88f);
    c[ImGuiCol_TextDisabled] = MUTED;

    c[ImGuiCol_WindowBg] = grey(0.125f);
    c[ImGuiCol_ChildBg] = grey(0.125f);
    c[ImGuiCol_PopupBg] = grey(0.15f, 0.98f);
    c[ImGuiCol_MenuBarBg] = grey(0.125f);

    c[ImGuiCol_Border] = grey(0.24f);
    c[ImGuiCol_BorderShadow] = grey(0.f, 0.f);

    c[ImGuiCol_FrameBg] = grey(0.20f);
    c[ImGuiCol_FrameBgHovered] = grey(0.26f);
    c[ImGuiCol_FrameBgActive] = grey(0.30f);

    c[ImGuiCol_TitleBg] = grey(0.10f);
    c[ImGuiCol_TitleBgActive] = grey(0.16f);
    c[ImGuiCol_TitleBgCollapsed] = grey(0.10f);

    c[ImGuiCol_ScrollbarBg] = grey(0.11f);
    c[ImGuiCol_ScrollbarGrab] = grey(0.28f);
    c[ImGuiCol_ScrollbarGrabHovered] = grey(0.35f);
    c[ImGuiCol_ScrollbarGrabActive] = grey(0.42f);

    c[ImGuiCol_CheckMark] = ACCENT;
    c[ImGuiCol_SliderGrab] = {0.35f, 0.55f, 0.80f, 1.00f};
    c[ImGuiCol_SliderGrabActive] = ACCENT;

    c[ImGuiCol_Button] = grey(0.22f);
    c[ImGuiCol_ButtonHovered] = grey(0.30f);
    c[ImGuiCol_ButtonActive] = ACCENT_DIM;

    c[ImGuiCol_Header] = grey(0.24f);
    c[ImGuiCol_HeaderHovered] = grey(0.30f);
    c[ImGuiCol_HeaderActive] = ACCENT_DIM;

    c[ImGuiCol_Separator] = grey(0.24f);
    c[ImGuiCol_SeparatorHovered] = ACCENT_DIM;
    c[ImGuiCol_SeparatorActive] = ACCENT;

    c[ImGuiCol_ResizeGrip] = grey(0.f, 0.f);
    c[ImGuiCol_ResizeGripHovered] = ACCENT_DIM;
    c[ImGuiCol_ResizeGripActive] = ACCENT;

    c[ImGuiCol_Tab] = grey(0.16f);
    c[ImGuiCol_TabHovered] = grey(0.28f);
    c[ImGuiCol_TabSelected] = grey(0.24f);
    c[ImGuiCol_TabSelectedOverline] = grey(0.0f, 0.0f);
    c[ImGuiCol_TabDimmed] = grey(0.13f);
    c[ImGuiCol_TabDimmedSelected] = grey(0.20f);

    c[ImGuiCol_TableHeaderBg] = grey(0.18f);
    c[ImGuiCol_TableBorderStrong] = grey(0.26f);
    c[ImGuiCol_TableBorderLight] = grey(0.20f);
    c[ImGuiCol_TableRowBg] = grey(0.f, 0.f);
    c[ImGuiCol_TableRowBgAlt] = grey(1.f, 0.03f);

    c[ImGuiCol_TextSelectedBg] = ACCENT_DIM;
    c[ImGuiCol_DragDropTarget] = WARNING;
    c[ImGuiCol_NavCursor] = ACCENT;
    c[ImGuiCol_ModalWindowDimBg] = grey(0.05f, 0.65f);
}

} // namespace editor

#endif // ENABLE_EDITOR