feat(refs): match compact outline reference chips

This commit is contained in:
2026-06-18 18:53:49 -05:00
parent 5cd1578dc9
commit 6f27fac9fb
3 changed files with 86 additions and 19 deletions

View File

@@ -46,6 +46,13 @@ float g_ui_scale = 1.0f;
float g_sidebar_width = 230.0f;
WindowManager* g_window_manager = nullptr;
GitManager* g_git_manager = nullptr;
ImFont* g_outline_icon_font = nullptr;
float g_outline_icon_size = 15.0f;
constexpr const char* ICON_TB_CHECK = "\xee\xa9\x9e";
constexpr const char* ICON_TB_CLOUD = "\xee\xa9\xb6";
constexpr const char* ICON_TB_DEVICE_LAPTOP = "\xee\xad\xa4";
constexpr const char* ICON_TB_TAG = "\xee\xa4\x80";
float ui(float value) { return value * g_ui_scale; }
RepositoryView& repo() { return *g_tabs.at(g_active_tab); }
@@ -153,6 +160,19 @@ void load_fonts(float scale) {
icon_config.GlyphMinAdvanceX = size;
io.Fonts->AddFontFromFileTTF(
GITREE_ASSET_DIR "/fa-solid-900.ttf", size, &icon_config, icon_ranges);
static constexpr ImWchar outline_ranges[] = {
0xE900, 0xE900,
0xEA5E, 0xEA5E,
0xEA76, 0xEA76,
0xEB64, 0xEB64,
0,
};
ImFontConfig outline_config;
outline_config.PixelSnapH = true;
g_outline_icon_size = size;
g_outline_icon_font = io.Fonts->AddFontFromFileTTF(
GITREE_ASSET_DIR "/tabler-icons-outline.ttf", size, &outline_config, outline_ranges);
apply_style(scale);
}
@@ -350,37 +370,62 @@ void draw_sidebar(float width) {
}
void draw_ref_badge(const RefBadge& badge, int index, int lane) {
std::string text;
if (badge.current) text += ICON_FA_CHECK " ";
(void)lane;
std::string display_name = badge.name;
if (badge.kind == RefKind::remote) {
const size_t slash = display_name.find('/');
if (slash != std::string::npos) display_name.erase(0, slash + 1);
}
text += display_name;
if (badge.worktree) text += std::string(" ") + ICON_FA_COMPUTER;
if (badge.kind == RefKind::remote) text += std::string(" ") + ICON_FA_CLOUD;
if (badge.kind == RefKind::tag) text += std::string(" ") + ICON_FA_TAG;
const ImVec4 lane_color = ImGui::ColorConvertU32ToFloat4(GraphRenderer::laneColor(lane));
const float brightness = badge.current ? 0.78f : 0.38f;
const ImVec4 color = ImVec4(lane_color.x * brightness, lane_color.y * brightness,
lane_color.z * brightness, 1.0f);
ImGui::PushStyleColor(ImGuiCol_Button, color);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(color.x + 0.06f, color.y + 0.06f, color.z + 0.06f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, color);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, ui(2.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {ui(6.0f), ui(1.5f)});
const std::string id = text + "##ref_badge_" + std::to_string(index);
ImGui::Button(id.c_str());
const bool show_cloud = badge.kind == RefKind::remote || badge.upstream;
const bool show_tag = badge.kind == RefKind::tag;
const ImVec2 label_size = ImGui::CalcTextSize(display_name.c_str());
const auto icon_width = [](const char* icon) {
return g_outline_icon_font
? g_outline_icon_font->CalcTextSizeA(g_outline_icon_size, 1000.0f, 0.0f, icon).x
: 0.0f;
};
float content_width = label_size.x;
if (badge.current) content_width += icon_width(ICON_TB_CHECK) + ui(5.0f);
if (badge.worktree) content_width += ui(5.0f) + icon_width(ICON_TB_DEVICE_LAPTOP);
if (show_cloud) content_width += ui(5.0f) + icon_width(ICON_TB_CLOUD);
if (show_tag) content_width += ui(5.0f) + icon_width(ICON_TB_TAG);
const ImVec2 chip_size{content_width + ui(12.0f), ui(23.0f)};
ImGui::PushID(index);
ImGui::InvisibleButton("##ref_badge", chip_size);
const ImVec2 minimum = ImGui::GetItemRectMin();
const ImVec2 maximum = ImGui::GetItemRectMax();
ImDrawList* draw = ImGui::GetWindowDrawList();
ImU32 background = badge.current ? IM_COL32(17, 105, 123, 255) : IM_COL32(20, 65, 76, 255);
if (ImGui::IsItemHovered()) background = badge.current
? IM_COL32(22, 123, 142, 255) : IM_COL32(25, 79, 92, 255);
draw->AddRectFilled(minimum, maximum, background, ui(2.0f));
float x = minimum.x + ui(6.0f);
const float text_y = minimum.y + (chip_size.y - ImGui::GetFontSize()) * 0.5f;
const float icon_y = minimum.y + (chip_size.y - g_outline_icon_size) * 0.5f;
const ImU32 color = badge.current ? IM_COL32(242, 247, 249, 255) : IM_COL32(201, 214, 218, 255);
const auto draw_icon = [&](const char* icon) {
if (!g_outline_icon_font) return;
draw->AddText(g_outline_icon_font, g_outline_icon_size, {x, icon_y}, color, icon);
x += icon_width(icon) + ui(5.0f);
};
if (badge.current) draw_icon(ICON_TB_CHECK);
draw->AddText({x, text_y}, color, display_name.c_str());
x += label_size.x + ui(5.0f);
if (badge.worktree) draw_icon(ICON_TB_DEVICE_LAPTOP);
if (show_cloud) draw_icon(ICON_TB_CLOUD);
if (show_tag) draw_icon(ICON_TB_TAG);
if (ImGui::BeginPopupContextItem()) {
if (badge.kind == RefKind::local && ImGui::MenuItem(ICON_FA_CODE_BRANCH " Checkout"))
g_git_manager->checkoutBranch(repo(), badge.name, g_notice);
if (ImGui::MenuItem(ICON_FA_COPY " Copy ref name")) ImGui::SetClipboardText(badge.name.c_str());
ImGui::EndPopup();
}
ImGui::PopStyleVar(2);
ImGui::PopStyleColor(3);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort)) ImGui::SetTooltip("%s", badge.name.c_str());
ImGui::PopID();
}
void draw_commit_table() {
@@ -769,6 +814,7 @@ void draw_licenses_popup() {
{"iZo", "MIT License", "https://dock-it.dev/Idea-Studios/iZo"},
{"Inter", "SIL Open Font License 1.1", "https://github.com/rsms/inter"},
{"Font Awesome Free", "SIL Open Font License 1.1", "https://github.com/FortAwesome/Font-Awesome"},
{"Tabler Icons", "MIT License", "https://github.com/tabler/tabler-icons"},
};
for (const auto& dependency : dependencies) {
ImGui::TableNextRow();

21
vendor/fonts/LICENSE-Tabler-Icons.txt vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020-2026 Paweł Kuna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

BIN
vendor/fonts/tabler-icons-outline.ttf vendored Normal file

Binary file not shown.