fix(diff-viewer): simplify blame gutter to avatar hover
This commit is contained in:
@@ -671,31 +671,6 @@ void drawCodeLineNumber(int value, float x, float y, ImU32 color) {
|
||||
ImGui::GetWindowDrawList()->AddText({x, y}, color, text.c_str());
|
||||
}
|
||||
|
||||
std::string ellipsizeText(std::string_view text, float max_width) {
|
||||
if (text.empty() || max_width <= 0.0f) return {};
|
||||
|
||||
std::string display{text};
|
||||
if (ImGui::CalcTextSize(display.c_str()).x <= max_width) return display;
|
||||
|
||||
constexpr const char* overflow = "...";
|
||||
const float overflow_width = ImGui::CalcTextSize(overflow).x;
|
||||
if (overflow_width >= max_width) return overflow;
|
||||
|
||||
while (!display.empty() && ImGui::CalcTextSize(display.c_str()).x + overflow_width > max_width) {
|
||||
display.pop_back();
|
||||
}
|
||||
display += overflow;
|
||||
return display;
|
||||
}
|
||||
|
||||
void drawEllipsizedText(ImDrawList* draw, ImVec2 position, ImU32 color, std::string_view text,
|
||||
float max_width, const ImVec2& clip_min, const ImVec2& clip_max) {
|
||||
const std::string display = ellipsizeText(text, max_width);
|
||||
if (display.empty()) return;
|
||||
draw->PushClipRect(clip_min, clip_max, true);
|
||||
draw->AddText(position, color, display.c_str());
|
||||
draw->PopClipRect();
|
||||
}
|
||||
}
|
||||
|
||||
void DiffViewer::open(RepositoryView& repository, GitManager& manager, const std::string& path,
|
||||
@@ -1104,7 +1079,7 @@ void DiffViewer::draw(RepositoryView& repository, GitManager& manager, AvatarCac
|
||||
ImGui::TextDisabled("No blame data is available for this file.");
|
||||
} else {
|
||||
SyntaxState syntax;
|
||||
const float info_width = scaled(270.0f, scale);
|
||||
const float info_width = scaled(34.0f, scale);
|
||||
const float line_number_width = scaled(48.0f, scale);
|
||||
const float code_gutter = info_width + line_number_width + scaled(14.0f, scale);
|
||||
for (size_t index = 0; index < blame_lines_.size(); ++index) {
|
||||
@@ -1113,7 +1088,7 @@ void DiffViewer::draw(RepositoryView& repository, GitManager& manager, AvatarCac
|
||||
const ImVec2 line_minimum = ImGui::GetCursorScreenPos();
|
||||
const ImU32 accent = blameColor(line.hash, line.show_attribution ? 255 : 190);
|
||||
const ImU32 background = line.show_attribution ? IM_COL32(39, 42, 50, 150) : IM_COL32(31, 34, 40, 105);
|
||||
const float blame_row_height = line.show_attribution ? scaled(28.0f, scale) : scaled(21.0f, scale);
|
||||
const float blame_row_height = scaled(21.0f, scale);
|
||||
drawCodeLine(line.text, language, syntax, scale, background, code_gutter, content_width,
|
||||
blame_row_height, wrap_columns);
|
||||
ImDrawList* draw = ImGui::GetWindowDrawList();
|
||||
@@ -1123,8 +1098,8 @@ void DiffViewer::draw(RepositoryView& repository, GitManager& manager, AvatarCac
|
||||
drawCodeLineNumber(line.line_number, line_minimum.x + info_width + scaled(6.0f, scale),
|
||||
line_minimum.y + scaled(2.0f, scale), IM_COL32(126, 132, 142, 255));
|
||||
if (line.show_attribution) {
|
||||
const float avatar_size = scaled(16.0f, scale);
|
||||
const ImVec2 avatar_min{line_minimum.x + scaled(8.0f, scale), line_minimum.y + scaled(2.0f, scale)};
|
||||
const float avatar_size = scaled(14.0f, scale);
|
||||
const ImVec2 avatar_min{line_minimum.x + scaled(10.0f, scale), line_minimum.y + scaled(3.0f, scale)};
|
||||
const unsigned int avatar_texture = avatars ? avatars->textureFor(line.email) : 0;
|
||||
if (avatar_texture) {
|
||||
draw->AddImageRounded(ImTextureRef(static_cast<ImTextureID>(avatar_texture)),
|
||||
@@ -1134,18 +1109,16 @@ void DiffViewer::draw(RepositoryView& repository, GitManager& manager, AvatarCac
|
||||
draw->AddRectFilled(avatar_min, {avatar_min.x + avatar_size, avatar_min.y + avatar_size},
|
||||
accent, scaled(3.0f, scale));
|
||||
}
|
||||
const float info_x = avatar_min.x + avatar_size + scaled(8.0f, scale);
|
||||
const float info_right = line_minimum.x + info_width - scaled(10.0f, scale);
|
||||
const float info_text_width = std::max(0.0f, info_right - info_x);
|
||||
const ImVec2 info_clip_min{info_x, line_minimum.y};
|
||||
const ImVec2 info_clip_max{info_right, line_maximum.y};
|
||||
const std::string author = line.author.empty() ? "Unknown author" : line.author;
|
||||
std::string summary = line.summary.empty() ? "(no summary)" : line.summary;
|
||||
if (!line.date.empty()) summary += " " + line.date;
|
||||
drawEllipsizedText(draw, {info_x, line_minimum.y + scaled(1.0f, scale)},
|
||||
IM_COL32(216, 220, 226, 255), author, info_text_width, info_clip_min, info_clip_max);
|
||||
drawEllipsizedText(draw, {info_x, line_minimum.y + scaled(10.0f, scale)},
|
||||
IM_COL32(134, 140, 151, 255), summary, info_text_width, info_clip_min, info_clip_max);
|
||||
if (ImGui::IsMouseHoveringRect(avatar_min, {avatar_min.x + avatar_size, avatar_min.y + avatar_size})) {
|
||||
const std::string author = line.author.empty() ? "Unknown author" : line.author;
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::TextUnformatted(author.c_str());
|
||||
if (!line.summary.empty())
|
||||
ImGui::TextDisabled("%s", line.summary.c_str());
|
||||
if (!line.date.empty())
|
||||
ImGui::TextDisabled("%s", line.date.c_str());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
} else {
|
||||
draw->AddText({line_minimum.x + scaled(16.0f, scale), line_minimum.y + scaled(2.0f, scale)},
|
||||
IM_COL32(92, 99, 110, 255), "...");
|
||||
|
||||
Reference in New Issue
Block a user