Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab control #427

Closed
ghost opened this issue Dec 4, 2015 · 2 comments
Closed

Tab control #427

ghost opened this issue Dec 4, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 4, 2015

Hi,

I have write a small ImGUI::Tab control... I just want to share the code, maybe integrate it or improve it ;-)

IMGUI_API bool Tab(unsigned int index, const char* label, const char* tooltip, int* selected)
{
    ImGuiStyle& style = ImGui::GetStyle();
    ImVec2 itemSpacing = style.ItemSpacing;
    ImVec4 color = style.Colors[ImGuiCol_Button];
    ImVec4 colorActive = style.Colors[ImGuiCol_ButtonActive];
    ImVec4 colorHover = style.Colors[ImGuiCol_ButtonHovered];
    style.ItemSpacing.x = 1;

    if (index > 0)
        ImGui::SameLine();

    // push the style
    if (index == *selected)
    {
        style.Colors[ImGuiCol_Button] = colorActive;
        style.Colors[ImGuiCol_ButtonActive] = colorActive;
        style.Colors[ImGuiCol_ButtonHovered] = colorActive;
    }
    else
    {
        style.Colors[ImGuiCol_Button] = color;
        style.Colors[ImGuiCol_ButtonActive] = colorActive;
        style.Colors[ImGuiCol_ButtonHovered] = colorHover;
    }

    // Draw the button
    if (ImGui::Button(label))
        *selected = index;

    if (ImGui::IsItemHovered())
    {
        ImGui::BeginTooltip();
        ImGui::Text("%s", tooltip);
        ImGui::EndTooltip();
    }

    // Restore the style
    style.Colors[ImGuiCol_Button] = color;
    style.Colors[ImGuiCol_ButtonActive] = colorActive;
    style.Colors[ImGuiCol_ButtonHovered] = colorHover;
    style.ItemSpacing = itemSpacing;

    return *selected == index;
}
@ocornut
Copy link
Owner

ocornut commented Dec 4, 2015

Thanks. It was fine to post it in #261 , may I delete this duplicate? Better if you add a screenshot over there in addition.

Functions typically return a bool when widget is activated / value is modified.

@ghost
Copy link
Author

ghost commented Dec 4, 2015

Yes sure you can delete/move it ... it is a new code (just for your info) !
Right, it just returns if the tab is selected or not... it can be changed easily of course !

@ocornut ocornut mentioned this issue Dec 4, 2015
@ocornut ocornut closed this as completed Dec 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant