| 20 | #include "../boxedwineui.h" |
| 21 | |
| 22 | void drawAppBar(const std::vector<AppButton>& buttons, int selected, ImFont* font) { |
| 23 | if (font) { |
| 24 | ImGui::PushFont(font); |
| 25 | } |
| 26 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f)); |
| 27 | ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0); |
| 28 | ImGui::BeginGroup(); |
| 29 | int selectedButton = -1; |
| 30 | float buttonHeight = ImGui::GetTextLineHeight() + ImGui::GetStyle().FramePadding.y + GlobalSettings::scaleFloatUI(10.0f); |
| 31 | for (int i=0;i<(int)buttons.size();i++) { |
| 32 | if (selected == i) { |
| 33 | ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_ButtonActive)); |
| 34 | } else { |
| 35 | ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg)); |
| 36 | } |
| 37 | BString name = " "+buttons[i].name + " "; |
| 38 | if (ImGui::Button(name.c_str(), ImVec2(0.0, buttonHeight))) { |
| 39 | selectedButton = i; // don't call onSelect here because the styles were changed |
| 40 | } |
| 41 | ImGui::PopStyleColor(); |
| 42 | ImGui::SameLine(); |
| 43 | } |
| 44 | ImGui::EndGroup(); |
| 45 | ImGui::PopStyleVar(2); |
| 46 | if (font) { |
| 47 | ImGui::PopFont(); |
| 48 | } |
| 49 | if (selectedButton>=0) { |
| 50 | buttons[selectedButton].onSelect(); |
| 51 | } |
| 52 | } |