Search
 
SCRIPT & CODE EXAMPLE
 

CPP

ImGui button wit picture

// Declaration (.h file)
namespace ImGui {
// label is used as id
// <0 frame_padding uses default frame padding settings. 0 for no padding
IMGUI_API bool ImageButtonWithText(ImTextureID texId,const char* label,const ImVec2& imageSize=ImVec2(0,0), const ImVec2& uv0 = ImVec2(0,0),  const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1));
} // namespace ImGui

// Definition (.cpp file. Not sure if it needs "imgui_internal.h" or not)
namespace ImGui {
bool ImageButtonWithText(ImTextureID texId,const char* label,const ImVec2& imageSize, const ImVec2 &uv0, const ImVec2 &uv1, int frame_padding, const ImVec4 &bg_col, const ImVec4 &tint_col) {
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
    return false;

    ImVec2 size = imageSize;
    if (size.x<=0 && size.y<=0) {size.x=size.y=ImGui::GetTextLineHeightWithSpacing();}
    else {
        if (size.x<=0)          size.x=size.y;
        else if (size.y<=0)     size.y=size.x;
        size*=window->FontWindowScale*ImGui::GetIO().FontGlobalScale;
    }

    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;

    const ImGuiID id = window->GetID(label);
    const ImVec2 textSize = ImGui::CalcTextSize(label,NULL,true);
    const bool hasText = textSize.x>0;

    const float innerSpacing = hasText ? ((frame_padding >= 0) ? (float)frame_padding : (style.ItemInnerSpacing.x)) : 0.f;
    const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding;
    const ImVec2 totalSizeWithoutPadding(size.x+innerSpacing+textSize.x,size.y>textSize.y ? size.y : textSize.y);
    const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + totalSizeWithoutPadding + padding*2);
    ImVec2 start(0,0);
    start = window->DC.CursorPos + padding;if (size.y<textSize.y) start.y+=(textSize.y-size.y)*.5f;
    const ImRect image_bb(start, start + size);
    start = window->DC.CursorPos + padding;start.x+=size.x+innerSpacing;if (size.y>textSize.y) start.y+=(size.y-textSize.y)*.5f;
    ItemSize(bb);
    if (!ItemAdd(bb, &id))
    return false;

    bool hovered=false, held=false;
    bool pressed = ButtonBehavior(bb, id, &hovered, &held);

    // Render
    const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
    RenderFrame(bb.Min, bb.Max, col, true, ImClamp((float)ImMin(padding.x, padding.y), 0.0f, style.FrameRounding));
    if (bg_col.w > 0.0f)
    window->DrawList->AddRectFilled(image_bb.Min, image_bb.Max, GetColorU32(bg_col));

    window->DrawList->AddImage(texId, image_bb.Min, image_bb.Max, uv0, uv1, GetColorU32(tint_col));

    if (textSize.x>0) ImGui::RenderText(start,label);
    return pressed;
}
} // namespace ImGui
Comment

PREVIOUS NEXT
Code Example
Cpp :: intersection between vector c++ 
Cpp :: add input in c++ 
Cpp :: c++ custom hash 
Cpp :: read a whole line from the input 
Cpp :: cout stack in c++ 
Cpp :: declare a tab c++ 
Cpp :: std::future 
Cpp :: has substr c++ 
Cpp :: tabeau pseudo dynamique sur c++ 
Cpp :: DS1302 
Cpp :: c++ awitch statements 
Cpp :: copy assignment operator in c++ 
Cpp :: select elements from array C++ 
Cpp :: new in c++ 
Cpp :: find maximum sum of circular subarray 
Cpp :: memcpy in cpp 
Cpp :: cpp substring 
Cpp :: malloc 2d array cpp 
Cpp :: what destructor used for in c++ 
Cpp :: . The cout with the insertion operator (<<) is used to print a statement 
Cpp :: codeforces problem 1030A solution 
Cpp :: c++ string replace 
Cpp :: two dimensional array A[N,M] with the random numbers from 10 to 90. 
Cpp :: time_t c++ stack overflow 
Cpp :: Variabili globali c++ 
Cpp :: Summation of Natural Number Sequence with c and c++. 
Cpp :: static member fn , instance 
Cpp :: how to change the icon of an exe in c++ 
Cpp :: sqrt function in c++ 
Cpp :: c# unity rendering object 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =