fix(client): keep nutrient readouts on stable single-line rows
This commit is contained in:
+29
-11
@@ -7,6 +7,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <imgui.h>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
@@ -658,9 +659,20 @@ void dot(ImU32 color, bool hollow = false) {
|
||||
// One table row: a nutrient's dot and name, a bar filled to `share`, and a value.
|
||||
void nutrient_row(std::size_t channel, const char* name, float share, const std::string& value,
|
||||
bool highlight = false, const std::string& tip = {}) {
|
||||
// Quantities are readouts, not prose: wrapping one changes every later row's baseline.
|
||||
ImGui::PushTextWrapPos(-1);
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
dot(nutrient_colors.at(channel));
|
||||
if (highlight) {
|
||||
const auto at = ImGui::GetCursorScreenPos();
|
||||
const float line = ImGui::GetTextLineHeight();
|
||||
const float marker_width = ImGui::CalcTextSize("*").x;
|
||||
ImGui::GetWindowDrawList()->AddText({at.x + (line - marker_width) / 2, at.y},
|
||||
ImGui::ColorConvertFloat4ToU32(amber), "*");
|
||||
ImGui::Dummy({line, line});
|
||||
} else {
|
||||
dot(nutrient_colors.at(channel));
|
||||
}
|
||||
ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||
ImGui::TextUnformatted(name);
|
||||
ImGui::TableNextColumn();
|
||||
@@ -683,14 +695,7 @@ void nutrient_row(std::size_t channel, const char* name, float share, const std:
|
||||
ImGui::SetTooltip("%s", tip.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(value.c_str());
|
||||
}
|
||||
bool begin_nutrient_table(const char* id) {
|
||||
if (!ImGui::BeginTable(id, 3, ImGuiTableFlags_SizingFixedFit))
|
||||
return false;
|
||||
ImGui::TableSetupColumn("name", ImGuiTableColumnFlags_WidthFixed, px(104));
|
||||
ImGui::TableSetupColumn("bar", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthFixed, px(64));
|
||||
return true;
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
// Three significant digits in the largest unit that keeps the value at least 1.
|
||||
std::string scaled(std::uint64_t value, const std::array<const char*, 4>& units) {
|
||||
@@ -711,6 +716,20 @@ std::string energy_text(std::uint64_t picojoules) {
|
||||
std::string mass_text(std::uint64_t femtograms) {
|
||||
return scaled(femtograms, {"fg", "pg", "ng", "\xC2\xB5g"});
|
||||
}
|
||||
bool begin_nutrient_table(const char* id) {
|
||||
if (!ImGui::BeginTable(id, 3, ImGuiTableFlags_SizingFixedFit))
|
||||
return false;
|
||||
// Reserve the widest supported stock for this font/scale, never from the live
|
||||
// amount. Even the full uint64 range stays legible without growing the column.
|
||||
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
|
||||
const float value_width =
|
||||
std::ceil(std::max({px(64), ImGui::CalcTextSize(energy_text(maximum).c_str()).x,
|
||||
ImGui::CalcTextSize(mass_text(maximum).c_str()).x}));
|
||||
ImGui::TableSetupColumn("name", ImGuiTableColumnFlags_WidthFixed, px(104));
|
||||
ImGui::TableSetupColumn("bar", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthFixed, value_width);
|
||||
return true;
|
||||
}
|
||||
std::uint64_t mix(std::uint64_t x) noexcept {
|
||||
x += 0x9E3779B97F4A7C15ULL;
|
||||
x = (x ^ (x >> 30U)) * 0xBF58476D1CE4E5B9ULL;
|
||||
@@ -1353,8 +1372,7 @@ void hud_vitals(const PanelView& v, FormBuffers& form, bool compact) {
|
||||
if (limiting)
|
||||
tip += "\nThis is what is holding your growth back right now.";
|
||||
}
|
||||
nutrient_row(i + 1, nutrient_names.at(i + 1), share,
|
||||
mass_text(have) + (limiting ? " *" : ""), limiting, tip);
|
||||
nutrient_row(i + 1, nutrient_names.at(i + 1), share, mass_text(have), limiting, tip);
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user