Вопрос slider size grab

Начинающий
Статус
Оффлайн
Регистрация
25 Сен 2022
Сообщения
11
Реакции[?]
2
Поинты[?]
0
По чему меняются размеры rect_filledoВ если меняется значение в меню

C++:
bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, bool minimum_damage, float power)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return false;

    //if (window->DC.CurrLineTextBaseOffset != window->DC.PrevLineTextBaseOffset)
    //    SetCursorPosY(GetCursorPosY() + c_menu::get().dpi_scale * 8.f);
    //
    SetCursorPosX(GetCursorPosX() + c_menu::get().dpi_scale * 3.f);

    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const ImGuiID id = window->GetID(label);

    const float w = CalcItemWidth();
    const ImVec2 label_size = CalcTextSize(label, NULL, true);
    const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(160 + w, label_size.y + style.FramePadding.y * 2.0f));
    const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));


    //const float w = CalcItemWidth() - c_menu::get().dpi_scale * 3.f;

    //const ImVec2 label_size = CalcTextSize(label, NULL, true);
    //const ImRect frame_bb(window->DC.CursorPos + ImVec2(120, 0), window->DC.CursorPos + ImVec2(200, 4));
    //const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0));

    const ImRect slider_bb(window->DC.CursorPos + ImVec2(120, 0), window->DC.CursorPos + ImVec2(200, 4));
 
    ItemSize(total_bb, style.FramePadding.y);
    if (!ItemAdd(total_bb, id, &frame_bb))
        return false;

    // Default format string when passing NULL
    if (format == NULL)
        format = DataTypeGetInfo(data_type)->PrintFmt;
    else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.)
        format = PatchFormatStringFloatToInt(format);

    // Tabbing or CTRL-clicking on Slider turns it into an input box
    const bool hovered = ItemHoverable(frame_bb, id);
    bool temp_input_is_active = TempInputIsActive(id);
    bool temp_input_start = false;
    if (!temp_input_is_active)
    {
        const bool focus_requested = FocusableItemRegister(window, id);
        const bool clicked = (hovered && g.IO.MouseClicked[0]);
        if (focus_requested || clicked || g.NavActivateId == id || g.NavInputId == id)
        {
            SetActiveID(id, window);
            SetFocusID(id, window);
            FocusWindow(window);
            g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right);
        }
    }

    // Our current specs do NOT clamp when using CTRL+Click manual input, but we should eventually add a flag for that..
    if (temp_input_is_active || temp_input_start)
        return TempInputScalar(slider_bb, id, label, data_type, p_data, format);// , p_min, p_max);
    
    // Draw frame
    const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
    float deltatime = 1.5f * ImGui::GetIO().DeltaTime;

    ImRect grab_bb;
    const bool value_changed = SliderBehavior(slider_bb, id, data_type, p_data, p_min, p_max, format, power, ImGuiSliderFlags_None, &grab_bb);
    if (value_changed)
        MarkItemEdited(id);

    //const ImU32 frame_col = GetColorU32(g.HoveredId == id ? ImGuiCol_FrameBg : ImGuiCol_FrameBg);
    RenderNavHighlight(slider_bb, id);

    RenderFrame(slider_bb.Min, slider_bb.Max, ImColor(14, 14, 14), true);

    //// Slider behavior
    //ImRect grab_bb;
    //const bool value_changed = SliderBehavior(frame_bb, id, data_type, p_data, p_min, p_max, format, power, ImGuiSliderFlags_None, &grab_bb);
    //if (value_changed)
    //    MarkItemEdited(id);

    if (grab_bb.Max.x > grab_bb.Min.x)
    {
        window->DrawList->AddRectFilled(ImVec2(grab_bb.Min.x - 3, grab_bb.Min.y - 7), ImVec2(grab_bb.Max.x + 3, grab_bb.Max.y + 7), ImColor(255, 255, 255), 4);
    }

    //// Menu name function.
    char value_buf[64];
    const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, p_data, format);

    PushFont(c_menu::get().gothamtwo);
    if (label_size.x > 0.0f)
        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x - 356, frame_bb.Min.y + style.FramePadding.y + 1.0f), label);
        //RenderText(ImVec2(grab_bb.Min.x - 3, grab_bb.Min.y + 0), label);
    PopFont();
    
    IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags);
    return value_changed;
}
 
Сверху Снизу