How can you change the border size of the current child window when is being hovered


Is there a way to change the border size of the current child window when is being hovered? The code below doesn’t work as expected. I can see that the right window is identified as hovered but it has no border:

ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.f);

ImGui::Begin(_name.c_str(), 0, 
    ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_HorizontalScrollbar);

const int nrLayouts = 15;
const ImVec2 layoutSize{ 1024, 1024 };
const ImGuiWindowFlags layoutFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove;
for (int i = 0; i < nrLayouts; i++) {
    std::string layoutName{ std::string("Layout##") + std::to_string(i) };

    if (ImGui::BeginChild(layoutName.c_str(), layoutSize, true)) {

        if (ImGui::IsWindowHovered()) {
            ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 2.f);
            ImGui::Text("Layout HOVERED: %i", i);
        } else {
            ImGui::Text("Layout: %i", i);

    ImGui::SameLine(0.f, 100.f);



The bordersize is used by BeginChild() so you are setting it too late.

That’s not possible with the public API but you could technically compare GImGui->HoveredWindow to your window prior to calling BeginChild().

Or, most reasonably you can just draw a border yourself using the ImDrawList api.

Thank you so much for the quick replay. Doing this fixed the problem:

       if (ImGui::IsWindowHovered()) {
            auto wPos = ImGui::GetWindowPos();
            auto wSize = ImGui::GetWindowSize();
            ImGui::GetWindowDrawList()->AddRect(wPos, { wPos.x + wSize.x, wPos.y + wSize.y }, ImColor(1.f, 1.f, 1.f, 1.f), 20.f);
            ImGui::Text("Layout HOVERED: %i", i);