pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping
https://pthom.github.io/hello_imgui
MIT License
678 stars 103 forks source link

Push/Pop TweakedTheme - Change theme per window #111

Closed colesnicov closed 6 months ago

colesnicov commented 6 months ago

Hello. Could you implement ImGuiTheme::Push(ImGuiTweakedTheme ...)/ImGuiTheme::Pop methods for ImGuiTheme? I would like to be able to apply a theme to only one window, or to one element or group of elements..

pthom commented 6 months ago

Hello,

This is actually a good idea. I just added this feature.

See https://github.com/pthom/hello_imgui/commit/f5c6f82b1f2691a7bb15718c56be36dcf2b0d3a9 (inside Hello ImGui)

And https://github.com/pthom/imgui_bundle/commit/90298ced9f7d3a8d97418d422400d5f4ae1c1fc7 (inside ImGui Bundle)

image
colesnicov commented 6 months ago

I modified part of the code from imgui demo.cpp. Specifically from the 'Style Editor':

static void Push(ImGuiStyle *_style_from) {
//  Main
    ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, _style_from->WindowPadding);
    ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, _style_from->FramePadding);
    ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, _style_from->ItemSpacing);
    ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, _style_from->ItemInnerSpacing);
    ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, _style_from->IndentSpacing);
    ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, _style_from->ScrollbarSize);
    ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, _style_from->GrabMinSize);
//  Borders
    ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, _style_from->WindowBorderSize);
    ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, _style_from->ChildBorderSize);
    ImGui::PushStyleVar(ImGuiStyleVar_PopupBorderSize, _style_from->PopupBorderSize);
    ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, _style_from->FrameBorderSize);
    ImGui::PushStyleVar(ImGuiStyleVar_TabBorderSize, _style_from->TabBorderSize);
    ImGui::PushStyleVar(ImGuiStyleVar_TabBarBorderSize, _style_from->TabBarBorderSize);
//  Rounding
    ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, _style_from->WindowRounding);
    ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, _style_from->ChildRounding);
    ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, _style_from->FrameRounding);
    ImGui::PushStyleVar(ImGuiStyleVar_PopupRounding, _style_from->PopupRounding);
    ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarRounding, _style_from->ScrollbarRounding);
    ImGui::PushStyleVar(ImGuiStyleVar_GrabRounding, _style_from->GrabRounding);
    ImGui::PushStyleVar(ImGuiStyleVar_TabRounding, _style_from->TabRounding);
//  Tables
    ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, _style_from->CellPadding);
    ImGui::PushStyleVar(ImGuiStyleVar_TableAngledHeadersAngle,
            _style_from->TableAngledHeadersAngle);
//  Widgets
    ImGui::PushStyleVar(ImGuiStyleVar_WindowTitleAlign, _style_from->WindowTitleAlign);
    ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, _style_from->ButtonTextAlign);
    ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, _style_from->SelectableTextAlign);
    ImGui::PushStyleVar(ImGuiStyleVar_SeparatorTextBorderSize,
            _style_from->SeparatorTextBorderSize);
    ImGui::PushStyleVar(ImGuiStyleVar_SeparatorTextAlign, _style_from->SeparatorTextAlign);
    ImGui::PushStyleVar(ImGuiStyleVar_SeparatorTextPadding, _style_from->SeparatorTextPadding);

//  Rendering
    ImGui::PushStyleVar(ImGuiStyleVar_Alpha, _style_from->Alpha);
    ImGui::PushStyleVar(ImGuiStyleVar_DisabledAlpha, _style_from->DisabledAlpha);

    //  Colors
    for (int i = 0; i < ImGuiCol_COUNT; i++) {
        ImGui::PushStyleColor(i, _style_from->Colors[i]);
    }
}

and

void Pop() {
    ImGui::PopStyleVar(ImGuiStyleVar_COUNT - 2);
    ImGui::PopStyleColor(ImGuiCol_COUNT);
}

Not all variables are set, some are global to the entire application. For example ImGuiStyleVar_TaouchExtraPadding and ImGuiStyleVar_AntiAliasedLines or Docking...