fix(sidebar): constrain sections within viewport

This commit is contained in:
2026-06-18 19:08:26 -05:00
parent 828b91e66d
commit 5bf04b619e

View File

@@ -323,8 +323,8 @@ void section(const char* label, const std::vector<std::string>& items, const cha
const char* add_tooltip, const char* add_notice, SidebarItemKind kind, size_t section_index,
float body_height) {
const bool open = sidebar_section_header(label, static_cast<int>(items.size()), add_tooltip, add_notice);
if (open) {
ImGui::BeginChild((std::string(label) + "##body").c_str(), {-1, std::max(ui(1.0f), body_height)});
if (open && body_height >= ui(1.0f)) {
ImGui::BeginChild((std::string(label) + "##body").c_str(), {-1, body_height});
for (const auto& item : items) {
sidebar_item_row(item_icon, item, item);
sidebar_item_context(item, kind);
@@ -392,8 +392,8 @@ void branch_section(const char* label, const std::vector<std::string>& branches,
const char* group_icon, const char* add_tooltip, const char* add_notice, bool remote,
size_t section_index, float body_height) {
const bool open = sidebar_section_header(label, static_cast<int>(branches.size()), add_tooltip, add_notice);
if (open) {
ImGui::BeginChild((std::string(label) + "##body").c_str(), {-1, std::max(ui(1.0f), body_height)});
if (open && body_height >= ui(1.0f)) {
ImGui::BeginChild((std::string(label) + "##body").c_str(), {-1, body_height});
BranchNode root;
for (const auto& branch : branches) {
if (g_filter[0] && branch.find(g_filter.data()) == std::string::npos) continue;
@@ -411,13 +411,18 @@ void branch_section(const char* label, const std::vector<std::string>& branches,
void draw_sidebar(float width) {
ImGui::BeginChild("sidebar", {width, -ui(28.0f)}, ImGuiChildFlags_Borders,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
if (ImGui::Button(ICON_FA_LIST " List", {ui(98), ui(30)})) {}
const float mode_button_width = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
if (ImGui::Button(ICON_FA_LIST " List", {mode_button_width, ui(30)})) {}
ImGui::SameLine();
if (ImGui::Button(ICON_FA_LAYER_GROUP " Workspace", {ui(102), ui(30)})) {}
if (ImGui::Button(ICON_FA_LAYER_GROUP " Workspace", {mode_button_width, ui(30)})) {}
ImGui::TextDisabled(ICON_FA_EYE " VIEWING %d", static_cast<int>(repo().local_branches.size() + repo().remote_branches.size()));
ImGui::SetNextItemWidth(-1);
ImGui::InputTextWithHint("##filter", ICON_FA_MAGNIFYING_GLASS " Search branches...", g_filter.data(), g_filter.size());
ImGui::Spacing();
ImGui::BeginChild("sidebar_sections", {-1, -1}, ImGuiChildFlags_None,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
const ImVec2 section_spacing = ImGui::GetStyle().ItemSpacing;
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {section_spacing.x, 0.0f});
constexpr const char* section_ids[] = {
ICON_FA_HOUSE " LOCAL",
@@ -434,8 +439,8 @@ void draw_sidebar(float width) {
desired_height += g_user_data->sidebarSectionHeight(index);
++open_count;
}
const float header_space = (ImGui::GetTextLineHeightWithSpacing() + ui(5.0f)) * section_open.size();
const float splitter_space = ui(12.0f) * open_count;
const float header_space = (ui(22.0f) + 1.0f) * static_cast<float>(section_open.size());
const float splitter_space = ui(5.0f) * open_count;
const float body_space = std::max(0.0f, ImGui::GetContentRegionAvail().y - header_space - splitter_space);
std::array<float, 4> section_heights{};
if (desired_height > 0.0f) {
@@ -453,6 +458,8 @@ void draw_sidebar(float width) {
"Add worktree", "Worktree creation is not wired yet", SidebarItemKind::worktree, 2, section_heights[2]);
section(ICON_FA_CUBES " SUBMODULES", repo().submodules, ICON_FA_CUBES,
"Add submodule", "Submodule creation is not wired yet", SidebarItemKind::submodule, 3, section_heights[3]);
ImGui::PopStyleVar();
ImGui::EndChild();
ImGui::EndChild();
}