overlay: address small polish issues (#543)

* Make a custom widget for truncated text that shows a tooltip only when
truncated
* Use the above widget more consistently in various places
* Ensure tooltips still show even when the preceding widget is disabled
This commit is contained in:
bicarus
2026-01-30 19:17:44 -08:00
committed by GitHub
parent 3ad88ef15c
commit 875a0f0765
4 changed files with 45 additions and 60 deletions
+14 -2
View File
@@ -93,14 +93,14 @@ namespace ImGui {
thickness);
}
std::string TruncateText(const std::string& p_text, float p_truncated_width) {
std::string TruncateText(const std::string& p_text, float p_truncated_width, bool &truncated) {
std::string truncated_text = p_text;
const float text_width =
ImGui::CalcTextSize(p_text.c_str(), nullptr, true).x;
if (text_width > p_truncated_width) {
truncated = true;
constexpr const char* ELLIPSIS = " ...";
const float ellipsis_size = ImGui::CalcTextSize(ELLIPSIS).x;
@@ -122,6 +122,18 @@ namespace ImGui {
return truncated_text;
}
void TextTruncated(const std::string& p_text, float p_truncated_width) {
if (p_text.empty()) {
ImGui::TextDisabled("-");
return;
}
bool truncated = false;
ImGui::TextUnformatted(TruncateText(p_text, p_truncated_width, truncated).c_str());
if (truncated && ImGui::IsItemHovered()) {
ImGui::HelpTooltip(p_text.c_str());
}
}
bool AddButton(const std::string& tooltip) {
ImGui::PushID(tooltip.c_str());
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.1f, 0.6f, 0.1f, 0.3f));
+1 -1
View File
@@ -13,7 +13,7 @@ namespace ImGui {
void Knob(float fraction, float size, float thickness = 2.f,
float pos_x = -1.f, float pos_y = -1.f);
std::string TruncateText(const std::string& p_text, float p_truncated_width);
void TextTruncated(const std::string& p_text, float p_truncated_width);
bool AddButton(const std::string& tooltip);
bool DeleteButton(const std::string& tooltip);
bool ClearButton(const std::string& tooltip);