fix(ui): improve text size and contrast
This commit is contained in:
@@ -40,19 +40,19 @@ void parseRange(const std::string& header, char marker, int& line) {
|
|||||||
|
|
||||||
ImU32 syntaxColor(const std::string& text) {
|
ImU32 syntaxColor(const std::string& text) {
|
||||||
const size_t first = text.find_first_not_of(" \t");
|
const size_t first = text.find_first_not_of(" \t");
|
||||||
if (first == std::string::npos) return IM_COL32(188, 192, 199, 255);
|
if (first == std::string::npos) return IM_COL32(210, 214, 220, 255);
|
||||||
const std::string_view value(text.c_str() + first, text.size() - first);
|
const std::string_view value(text.c_str() + first, text.size() - first);
|
||||||
if (value.starts_with("//") || value.starts_with("# ")) return IM_COL32(105, 158, 102, 255);
|
if (value.starts_with("//") || value.starts_with("# ")) return IM_COL32(129, 184, 125, 255);
|
||||||
if (value.starts_with('#')) return IM_COL32(187, 134, 204, 255);
|
if (value.starts_with('#')) return IM_COL32(205, 157, 222, 255);
|
||||||
static constexpr const char* keywords[] = {
|
static constexpr const char* keywords[] = {
|
||||||
"class ", "struct ", "enum ", "if ", "else", "for ", "while ", "return ",
|
"class ", "struct ", "enum ", "if ", "else", "for ", "while ", "return ",
|
||||||
"const ", "static ", "void ", "bool ", "int ", "float ", "auto ", "namespace "
|
"const ", "static ", "void ", "bool ", "int ", "float ", "auto ", "namespace "
|
||||||
};
|
};
|
||||||
for (const char* keyword : keywords)
|
for (const char* keyword : keywords)
|
||||||
if (value.starts_with(keyword)) return IM_COL32(102, 153, 204, 255);
|
if (value.starts_with(keyword)) return IM_COL32(124, 177, 228, 255);
|
||||||
if (value.find('"') != std::string_view::npos || value.find('\'') != std::string_view::npos)
|
if (value.find('"') != std::string_view::npos || value.find('\'') != std::string_view::npos)
|
||||||
return IM_COL32(206, 145, 120, 255);
|
return IM_COL32(226, 166, 140, 255);
|
||||||
return IM_COL32(198, 201, 207, 255);
|
return IM_COL32(218, 221, 226, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compactButton(const char* label, bool active = false) {
|
bool compactButton(const char* label, bool active = false) {
|
||||||
@@ -248,14 +248,14 @@ void DiffViewer::draw(RepositoryView& repository, GitManager& manager, float sca
|
|||||||
if (old_number) std::snprintf(old_buffer, sizeof(old_buffer), "%d", old_number);
|
if (old_number) std::snprintf(old_buffer, sizeof(old_buffer), "%d", old_number);
|
||||||
if (new_number) std::snprintf(new_buffer, sizeof(new_buffer), "%d", new_number);
|
if (new_number) std::snprintf(new_buffer, sizeof(new_buffer), "%d", new_number);
|
||||||
draw->AddText({minimum.x + scaled(5, scale), minimum.y + scaled(2, scale)},
|
draw->AddText({minimum.x + scaled(5, scale), minimum.y + scaled(2, scale)},
|
||||||
IM_COL32(123, 128, 138, 255), old_buffer);
|
IM_COL32(158, 164, 174, 255), old_buffer);
|
||||||
draw->AddText({minimum.x + number_width + scaled(5, scale), minimum.y + scaled(2, scale)},
|
draw->AddText({minimum.x + number_width + scaled(5, scale), minimum.y + scaled(2, scale)},
|
||||||
IM_COL32(123, 128, 138, 255), new_buffer);
|
IM_COL32(158, 164, 174, 255), new_buffer);
|
||||||
const char marker = kind == LineKind::added ? '+' : kind == LineKind::removed ? '-' : ' ';
|
const char marker = kind == LineKind::added ? '+' : kind == LineKind::removed ? '-' : ' ';
|
||||||
char marker_text[2]{marker, 0};
|
char marker_text[2]{marker, 0};
|
||||||
draw->AddText({minimum.x + number_width * 2 + scaled(5, scale), minimum.y + scaled(2, scale)},
|
draw->AddText({minimum.x + number_width * 2 + scaled(5, scale), minimum.y + scaled(2, scale)},
|
||||||
kind == LineKind::added ? IM_COL32(87, 190, 112, 255) :
|
kind == LineKind::added ? IM_COL32(87, 190, 112, 255) :
|
||||||
kind == LineKind::removed ? IM_COL32(220, 97, 97, 255) : IM_COL32(110, 115, 125, 255), marker_text);
|
kind == LineKind::removed ? IM_COL32(220, 97, 97, 255) : IM_COL32(148, 154, 164, 255), marker_text);
|
||||||
draw->AddText({minimum.x + number_width * 2 + scaled(22, scale), minimum.y + scaled(2, scale)},
|
draw->AddText({minimum.x + number_width * 2 + scaled(22, scale), minimum.y + scaled(2, scale)},
|
||||||
syntaxColor(text), text.c_str());
|
syntaxColor(text), text.c_str());
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -158,8 +158,8 @@ void apply_style(float scale) {
|
|||||||
const auto color = [](int red, int green, int blue, int alpha = 255) {
|
const auto color = [](int red, int green, int blue, int alpha = 255) {
|
||||||
return ImVec4(red / 255.0f, green / 255.0f, blue / 255.0f, alpha / 255.0f);
|
return ImVec4(red / 255.0f, green / 255.0f, blue / 255.0f, alpha / 255.0f);
|
||||||
};
|
};
|
||||||
style.Colors[ImGuiCol_Text] = color(199, 203, 209);
|
style.Colors[ImGuiCol_Text] = color(218, 221, 226);
|
||||||
style.Colors[ImGuiCol_TextDisabled] = color(116, 121, 130);
|
style.Colors[ImGuiCol_TextDisabled] = color(154, 159, 168);
|
||||||
style.Colors[ImGuiCol_WindowBg] = color(28, 30, 35);
|
style.Colors[ImGuiCol_WindowBg] = color(28, 30, 35);
|
||||||
style.Colors[ImGuiCol_MenuBarBg] = color(31, 31, 31);
|
style.Colors[ImGuiCol_MenuBarBg] = color(31, 31, 31);
|
||||||
style.Colors[ImGuiCol_ChildBg] = color(28, 30, 35);
|
style.Colors[ImGuiCol_ChildBg] = color(28, 30, 35);
|
||||||
@@ -200,7 +200,7 @@ void load_fonts(float scale) {
|
|||||||
config.OversampleV = 2;
|
config.OversampleV = 2;
|
||||||
config.PixelSnapH = false;
|
config.PixelSnapH = false;
|
||||||
config.RasterizerDensity = 1.0f;
|
config.RasterizerDensity = 1.0f;
|
||||||
const float size = 16.0f * scale;
|
const float size = 18.0f * scale;
|
||||||
if (!io.Fonts->AddFontFromFileTTF(GITREE_ASSET_DIR "/OpenSans-Regular.ttf", size, &config))
|
if (!io.Fonts->AddFontFromFileTTF(GITREE_ASSET_DIR "/OpenSans-Regular.ttf", size, &config))
|
||||||
io.Fonts->AddFontDefault();
|
io.Fonts->AddFontDefault();
|
||||||
|
|
||||||
@@ -234,15 +234,15 @@ bool sidebar_collapse_row(const char* id, const std::string& label, bool default
|
|||||||
bool open = storage->GetBool(state_id, default_open);
|
bool open = storage->GetBool(state_id, default_open);
|
||||||
const ImVec2 size{
|
const ImVec2 size{
|
||||||
std::max(ui(24.0f), ImGui::GetContentRegionAvail().x - reserved_width),
|
std::max(ui(24.0f), ImGui::GetContentRegionAvail().x - reserved_width),
|
||||||
ui(22.0f),
|
ui(24.0f),
|
||||||
};
|
};
|
||||||
const bool clicked = ImGui::InvisibleButton("##collapse", size);
|
const bool clicked = ImGui::InvisibleButton("##collapse", size);
|
||||||
const ImVec2 minimum = ImGui::GetItemRectMin();
|
const ImVec2 minimum = ImGui::GetItemRectMin();
|
||||||
const ImVec2 maximum = ImGui::GetItemRectMax();
|
const ImVec2 maximum = ImGui::GetItemRectMax();
|
||||||
ImDrawList* draw = ImGui::GetWindowDrawList();
|
ImDrawList* draw = ImGui::GetWindowDrawList();
|
||||||
if (ImGui::IsItemHovered()) draw->AddRectFilled(minimum, maximum, IM_COL32(51, 55, 63, 220));
|
if (ImGui::IsItemHovered()) draw->AddRectFilled(minimum, maximum, IM_COL32(51, 55, 63, 220));
|
||||||
constexpr ImU32 icon_color = IM_COL32(112, 118, 128, 255);
|
constexpr ImU32 icon_color = IM_COL32(144, 150, 160, 255);
|
||||||
constexpr ImU32 text_color = IM_COL32(176, 181, 189, 255);
|
constexpr ImU32 text_color = IM_COL32(207, 211, 218, 255);
|
||||||
const float y = minimum.y + (size.y - ImGui::GetFontSize()) * 0.5f;
|
const float y = minimum.y + (size.y - ImGui::GetFontSize()) * 0.5f;
|
||||||
draw->AddText({minimum.x + ui(3.0f), y}, icon_color,
|
draw->AddText({minimum.x + ui(3.0f), y}, icon_color,
|
||||||
open ? ICON_FA_CHEVRON_DOWN : ICON_FA_CHEVRON_RIGHT);
|
open ? ICON_FA_CHEVRON_DOWN : ICON_FA_CHEVRON_RIGHT);
|
||||||
@@ -265,15 +265,15 @@ bool sidebar_collapse_row(const char* id, const std::string& label, bool default
|
|||||||
|
|
||||||
bool sidebar_item_row(const char* icon, const std::string& text, const std::string& id) {
|
bool sidebar_item_row(const char* icon, const std::string& text, const std::string& id) {
|
||||||
ImGui::PushID(id.c_str());
|
ImGui::PushID(id.c_str());
|
||||||
const bool clicked = ImGui::InvisibleButton("##sidebar_item", {-1, ui(22.0f)});
|
const bool clicked = ImGui::InvisibleButton("##sidebar_item", {-1, ui(24.0f)});
|
||||||
const ImVec2 minimum = ImGui::GetItemRectMin();
|
const ImVec2 minimum = ImGui::GetItemRectMin();
|
||||||
const ImVec2 maximum = ImGui::GetItemRectMax();
|
const ImVec2 maximum = ImGui::GetItemRectMax();
|
||||||
ImDrawList* draw = ImGui::GetWindowDrawList();
|
ImDrawList* draw = ImGui::GetWindowDrawList();
|
||||||
if (ImGui::IsItemHovered()) draw->AddRectFilled(minimum, maximum, IM_COL32(51, 55, 63, 210));
|
if (ImGui::IsItemHovered()) draw->AddRectFilled(minimum, maximum, IM_COL32(51, 55, 63, 210));
|
||||||
const float y = minimum.y + (maximum.y - minimum.y - ImGui::GetFontSize()) * 0.5f;
|
const float y = minimum.y + (maximum.y - minimum.y - ImGui::GetFontSize()) * 0.5f;
|
||||||
draw->PushClipRect(minimum, maximum, true);
|
draw->PushClipRect(minimum, maximum, true);
|
||||||
draw->AddText({minimum.x + ui(3.0f), y}, IM_COL32(108, 114, 124, 255), icon);
|
draw->AddText({minimum.x + ui(3.0f), y}, IM_COL32(142, 148, 158, 255), icon);
|
||||||
draw->AddText({minimum.x + ui(23.0f), y}, IM_COL32(174, 179, 187, 255), text.c_str());
|
draw->AddText({minimum.x + ui(23.0f), y}, IM_COL32(205, 209, 216, 255), text.c_str());
|
||||||
draw->PopClipRect();
|
draw->PopClipRect();
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
return clicked;
|
return clicked;
|
||||||
@@ -505,7 +505,7 @@ void draw_sidebar(float width) {
|
|||||||
if (!section_open[index]) continue;
|
if (!section_open[index]) continue;
|
||||||
++open_count;
|
++open_count;
|
||||||
}
|
}
|
||||||
const float header_space = (ui(22.0f) + 1.0f) * 2.0f;
|
const float header_space = (ui(24.0f) + 1.0f) * 2.0f;
|
||||||
const float splitter_space = ui(5.0f) * open_count;
|
const float splitter_space = ui(5.0f) * open_count;
|
||||||
const float body_space = std::max(0.0f, ImGui::GetContentRegionAvail().y - header_space - splitter_space);
|
const float body_space = std::max(0.0f, ImGui::GetContentRegionAvail().y - header_space - splitter_space);
|
||||||
std::array<float, 4> section_heights{};
|
std::array<float, 4> section_heights{};
|
||||||
@@ -663,7 +663,7 @@ void draw_commit_table() {
|
|||||||
line_width += spacing + badge_width;
|
line_width += spacing + badge_width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
row_heights[index] = std::max(ui(22.0f), lines * ui(21.0f) + ui(1.0f));
|
row_heights[index] = std::max(ui(24.0f), lines * ui(23.0f) + ui(1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersInnerV |
|
ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersInnerV |
|
||||||
@@ -682,7 +682,7 @@ void draw_commit_table() {
|
|||||||
ImGui::TableSetupColumn("COMMIT DATE / TIME", ImGuiTableColumnFlags_WidthFixed, ui(180.0f));
|
ImGui::TableSetupColumn("COMMIT DATE / TIME", ImGuiTableColumnFlags_WidthFixed, ui(180.0f));
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableHeadersRow();
|
||||||
if (!repo().working_files.empty()) {
|
if (!repo().working_files.empty()) {
|
||||||
ImGui::TableNextRow(0, ui(22.0f));
|
ImGui::TableNextRow(0, ui(24.0f));
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetColumnIndex(0);
|
||||||
if (ImGui::Selectable("##working_tree", repo().selected_commit == -1,
|
if (ImGui::Selectable("##working_tree", repo().selected_commit == -1,
|
||||||
ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap))
|
ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap))
|
||||||
@@ -746,7 +746,7 @@ void draw_commit_table() {
|
|||||||
const float badge_width = ref_badge_width(commit.refs[ref_index]);
|
const float badge_width = ref_badge_width(commit.refs[ref_index]);
|
||||||
if (chip_x > reference_origin.x + ui(3.0f) && chip_x + badge_width > chip_right) {
|
if (chip_x > reference_origin.x + ui(3.0f) && chip_x + badge_width > chip_right) {
|
||||||
chip_x = reference_origin.x + ui(3.0f);
|
chip_x = reference_origin.x + ui(3.0f);
|
||||||
chip_y += ui(21.0f);
|
chip_y += ui(23.0f);
|
||||||
}
|
}
|
||||||
ImGui::SetCursorScreenPos({chip_x, chip_y});
|
ImGui::SetCursorScreenPos({chip_x, chip_y});
|
||||||
draw_ref_badge(commit.refs[ref_index], i * 1000 + ref_index, commit.lane);
|
draw_ref_badge(commit.refs[ref_index], i * 1000 + ref_index, commit.lane);
|
||||||
@@ -790,7 +790,7 @@ void draw_file_row(const std::string& path, FileChangeKind kind, int id,
|
|||||||
if (ImGui::IsItemHovered()) draw->AddRectFilled(minimum, maximum, IM_COL32(48, 52, 60, 255));
|
if (ImGui::IsItemHovered()) draw->AddRectFilled(minimum, maximum, IM_COL32(48, 52, 60, 255));
|
||||||
const float y = minimum.y + (maximum.y - minimum.y - ImGui::GetFontSize()) * 0.5f;
|
const float y = minimum.y + (maximum.y - minimum.y - ImGui::GetFontSize()) * 0.5f;
|
||||||
draw->AddText({minimum.x + ui(4.0f), y}, ImGui::ColorConvertFloat4ToU32(change_color(kind)), change_icon(kind));
|
draw->AddText({minimum.x + ui(4.0f), y}, ImGui::ColorConvertFloat4ToU32(change_color(kind)), change_icon(kind));
|
||||||
draw->AddText({minimum.x + ui(20.0f), y}, IM_COL32(174, 179, 187, 255), path.c_str());
|
draw->AddText({minimum.x + ui(20.0f), y}, IM_COL32(205, 209, 216, 255), path.c_str());
|
||||||
if (ImGui::BeginPopupContextItem()) {
|
if (ImGui::BeginPopupContextItem()) {
|
||||||
if (working_file && !staged && ImGui::MenuItem(ICON_FA_CIRCLE_PLUS " Stage file"))
|
if (working_file && !staged && ImGui::MenuItem(ICON_FA_CIRCLE_PLUS " Stage file"))
|
||||||
g_git_manager->stageFile(repo(), git_path, g_notice);
|
g_git_manager->stageFile(repo(), git_path, g_notice);
|
||||||
@@ -1114,7 +1114,7 @@ bool toolbar_action(const char* id, const char* label, const char* icon, const c
|
|||||||
ImDrawList* draw = ImGui::GetWindowDrawList();
|
ImDrawList* draw = ImGui::GetWindowDrawList();
|
||||||
if (enabled && ImGui::IsItemHovered())
|
if (enabled && ImGui::IsItemHovered())
|
||||||
draw->AddRectFilled(minimum, maximum, IM_COL32(62, 66, 75, 210));
|
draw->AddRectFilled(minimum, maximum, IM_COL32(62, 66, 75, 210));
|
||||||
const ImU32 text_color = enabled ? IM_COL32(199, 203, 209, 255) : IM_COL32(105, 109, 117, 255);
|
const ImU32 text_color = enabled ? IM_COL32(218, 221, 226, 255) : IM_COL32(139, 144, 153, 255);
|
||||||
const ImVec2 label_size = ImGui::CalcTextSize(label);
|
const ImVec2 label_size = ImGui::CalcTextSize(label);
|
||||||
const ImVec2 icon_size = ImGui::CalcTextSize(icon);
|
const ImVec2 icon_size = ImGui::CalcTextSize(icon);
|
||||||
draw->AddText({minimum.x + (maximum.x - minimum.x - label_size.x) * 0.5f, minimum.y},
|
draw->AddText({minimum.x + (maximum.x - minimum.x - label_size.x) * 0.5f, minimum.y},
|
||||||
@@ -1173,7 +1173,7 @@ bool toolbar_selector(const char* id, const char* label, const std::string& valu
|
|||||||
const ImVec2 maximum = ImGui::GetItemRectMax();
|
const ImVec2 maximum = ImGui::GetItemRectMax();
|
||||||
ImDrawList* draw = ImGui::GetWindowDrawList();
|
ImDrawList* draw = ImGui::GetWindowDrawList();
|
||||||
if (ImGui::IsItemHovered()) draw->AddRectFilled(minimum, maximum, IM_COL32(62, 66, 75, 200));
|
if (ImGui::IsItemHovered()) draw->AddRectFilled(minimum, maximum, IM_COL32(62, 66, 75, 200));
|
||||||
draw->AddText({minimum.x + ui(8), minimum.y}, IM_COL32(151, 156, 165, 255), label);
|
draw->AddText({minimum.x + ui(8), minimum.y}, IM_COL32(177, 182, 190, 255), label);
|
||||||
const float value_width = maximum.x - minimum.x - ui(34.0f);
|
const float value_width = maximum.x - minimum.x - ui(34.0f);
|
||||||
std::string displayed = value;
|
std::string displayed = value;
|
||||||
if (ImGui::CalcTextSize(displayed.c_str()).x > value_width) {
|
if (ImGui::CalcTextSize(displayed.c_str()).x > value_width) {
|
||||||
@@ -1188,8 +1188,8 @@ bool toolbar_selector(const char* id, const char* label, const std::string& valu
|
|||||||
}
|
}
|
||||||
displayed += ellipsis;
|
displayed += ellipsis;
|
||||||
}
|
}
|
||||||
draw->AddText({minimum.x + ui(8), minimum.y + ui(18)}, IM_COL32(210, 213, 218, 255), displayed.c_str());
|
draw->AddText({minimum.x + ui(8), minimum.y + ui(18)}, IM_COL32(226, 229, 233, 255), displayed.c_str());
|
||||||
draw->AddText({maximum.x - ui(18), minimum.y + ui(18)}, IM_COL32(130, 135, 144, 255),
|
draw->AddText({maximum.x - ui(18), minimum.y + ui(18)}, IM_COL32(160, 165, 174, 255),
|
||||||
trailing_arrow ? ICON_FA_ANGLE_RIGHT : ICON_FA_CARET_DOWN);
|
trailing_arrow ? ICON_FA_ANGLE_RIGHT : ICON_FA_CARET_DOWN);
|
||||||
if (displayed != value && ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort))
|
if (displayed != value && ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort))
|
||||||
ImGui::SetTooltip("%s", value.c_str());
|
ImGui::SetTooltip("%s", value.c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user