Fixes and improvements
This commit is contained in:
committed by
Guillaume Meunier
parent
12834824ab
commit
e4b4bfa66d
@@ -115,6 +115,9 @@ constexpr float font_modal_title = 1.2; // modal heading, x base font size
|
||||
constexpr float label_line_gap = 5; // title to description
|
||||
constexpr float label_bottom_pad = 6; // breathing room below the description
|
||||
constexpr float nav_section_gap = 18; // space above a sidebar section header
|
||||
|
||||
constexpr ImVec2 card_item_spacing = {12, 10}; // ItemSpacing pushed around a card section
|
||||
constexpr float setting_control_width = 480; // width of the control in a setting row
|
||||
} // namespace metrics
|
||||
|
||||
// Theme in effect, call current().apply() after mutating
|
||||
|
||||
@@ -224,6 +224,31 @@ button_colors colors_for(button_style s, const theme & t)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string icon_label(const char * icon, const std::string & label)
|
||||
{
|
||||
return std::string(icon) + " " + label;
|
||||
}
|
||||
|
||||
float button_width(const std::string & label)
|
||||
{
|
||||
return ImGui::CalcTextSize(label.c_str()).x + metrics::button_padding.x * 2;
|
||||
}
|
||||
|
||||
float button_width(const char * icon, const std::string & label)
|
||||
{
|
||||
ImGui::PushFont(nullptr, ImGui::GetFontSize() * metrics::button_label_glyph);
|
||||
const float icon_w = ImGui::CalcTextSize(icon).x;
|
||||
ImGui::PopFont();
|
||||
const float gap = ImGui::GetFontSize() * 0.4f;
|
||||
return icon_w + gap + ImGui::CalcTextSize(label.c_str()).x + metrics::button_padding.x * 2;
|
||||
}
|
||||
|
||||
ImVec2 chip_size(const std::string & label)
|
||||
{
|
||||
const ImVec2 ts = ImGui::CalcTextSize(label.c_str());
|
||||
return {ts.x + metrics::chip_padding.x * 2, ts.y + metrics::chip_padding.y * 2};
|
||||
}
|
||||
|
||||
bool button(const std::string & label, button_style s, const ImVec2 & size)
|
||||
{
|
||||
const theme & t = current();
|
||||
@@ -866,7 +891,10 @@ bool nav_item(const char * icon, const std::string & label, bool selected)
|
||||
hover_haptic();
|
||||
|
||||
ImDrawList * draw = window->DrawList;
|
||||
const ImVec4 bg = selected ? t.control : (hovered ? t.control_hovered : ImVec4{0, 0, 0, 0});
|
||||
// Subtle accent tint at a fixed alpha so the highlight reads the same in every
|
||||
// theme, instead of the per-theme control surface whose contrast varies.
|
||||
ImVec4 bg = t.accent;
|
||||
bg.w = selected ? 0.16f : (hovered ? 0.08f : 0);
|
||||
if (bg.w > 0)
|
||||
draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding);
|
||||
|
||||
|
||||
@@ -52,6 +52,19 @@ void row_separator();
|
||||
// enough for a multi-line label.
|
||||
float setting_label(const std::string & title, const std::string & description, float control_width);
|
||||
|
||||
// "<icon> <label>" with the standard two-space gap, for chips and text buttons that
|
||||
// take a single label string with an embedded glyph.
|
||||
std::string icon_label(const char * icon, const std::string & label);
|
||||
|
||||
// Auto-fit width of a button, matching what button() lays out when size.x is left at 0.
|
||||
// Use to reserve/right-align a button before drawing it. The icon overload accounts for
|
||||
// the leading glyph drawn at metrics::button_label_glyph.
|
||||
float button_width(const std::string & label);
|
||||
float button_width(const char * icon, const std::string & label);
|
||||
|
||||
// Footprint of a chip() with standard padding (no dot, no height override).
|
||||
ImVec2 chip_size(const std::string & label);
|
||||
|
||||
bool button(const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0});
|
||||
// Same, with a larger leading icon glyph drawn before the label
|
||||
bool button(const char * icon, const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0});
|
||||
@@ -135,6 +148,13 @@ struct list_row_result
|
||||
{
|
||||
ImVec2 min, max; // row rect (screen) for right-aligning trailing controls
|
||||
bool clicked; // the row body was clicked
|
||||
|
||||
// Screen position for a trailing control of the given size, right-aligned to right_x
|
||||
// and vertically centred in the row. Feed to ImGui::SetCursorScreenPos.
|
||||
ImVec2 trailing(float right_x, const ImVec2 & size) const
|
||||
{
|
||||
return {right_x - size.x, min.y + (max.y - min.y - size.y) * 0.5f};
|
||||
}
|
||||
};
|
||||
|
||||
// List row: leading thumbnail (image, if non-zero) or icon box, title and muted subtitle.
|
||||
|
||||
Reference in New Issue
Block a user