3 changed files with 176 additions and 130 deletions
@ -1,127 +1,138 @@ |
|||
#include "imgui_ext.hpp" |
|||
#include "imgui.h" |
|||
#include <X11/X.h> |
|||
#include <iostream> |
|||
#include <spdlog/spdlog.h> |
|||
|
|||
namespace ImGui { |
|||
|
|||
bool InputIntBounded( |
|||
const char* label, |
|||
int* val, |
|||
int lower_bound, |
|||
int upper_bound, |
|||
int step, |
|||
int step_fast, |
|||
ImGuiInputTextFlags flags) |
|||
{ |
|||
int unbounded_val = *val; |
|||
if (ImGui::InputInt(label, &unbounded_val, step, step_fast, flags)) { |
|||
if (unbounded_val >= lower_bound && unbounded_val <= upper_bound) { |
|||
*val = unbounded_val; |
|||
return true; |
|||
bool InputIntBounded( |
|||
const char *label, |
|||
int *val, |
|||
int lower_bound, |
|||
int upper_bound, |
|||
int step, |
|||
int step_fast, |
|||
ImGuiInputTextFlags flags) { |
|||
int unbounded_val = *val; |
|||
if (ImGui::InputInt(label, &unbounded_val, step, step_fast, flags)) { |
|||
if (unbounded_val >= lower_bound && unbounded_val <= upper_bound) { |
|||
*val = unbounded_val; |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
bool InputDoubleBounded( |
|||
const char* label, |
|||
double* val, |
|||
double lower_bound, |
|||
double upper_bound, |
|||
double step, |
|||
double step_fast, |
|||
const char* format, |
|||
ImGuiInputTextFlags flags) |
|||
{ |
|||
double unbounded_val = *val; |
|||
if (ImGui::InputDouble( |
|||
label, &unbounded_val, step, step_fast, format, flags)) { |
|||
if (unbounded_val >= lower_bound && unbounded_val <= upper_bound) { |
|||
*val = unbounded_val; |
|||
return true; |
|||
bool InputDoubleBounded( |
|||
const char *label, |
|||
double *val, |
|||
double lower_bound, |
|||
double upper_bound, |
|||
double step, |
|||
double step_fast, |
|||
const char *format, |
|||
ImGuiInputTextFlags flags) { |
|||
double unbounded_val = *val; |
|||
if (ImGui::InputDouble( |
|||
label, &unbounded_val, step, step_fast, format, flags)) { |
|||
if (unbounded_val >= lower_bound && unbounded_val <= upper_bound) { |
|||
*val = unbounded_val; |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
bool DragDouble( |
|||
const char* label, |
|||
double* v, |
|||
double v_speed, |
|||
double v_min, |
|||
double v_max, |
|||
const char* format, |
|||
float power) |
|||
{ |
|||
bool DragDouble( |
|||
const char *label, |
|||
double *v, |
|||
double v_speed, |
|||
double v_min, |
|||
double v_max, |
|||
const char *format, |
|||
float power) { |
|||
|
|||
return DragScalar( |
|||
label, ImGuiDataType_Double, v, float(v_speed), &v_min, &v_max, format, |
|||
power); |
|||
} |
|||
return DragScalar( |
|||
label, ImGuiDataType_Double, v, float(v_speed), &v_min, &v_max, format, |
|||
power); |
|||
} |
|||
|
|||
bool DoubleColorEdit3(const char* label, Eigen::RowVector3d& color) |
|||
{ |
|||
Eigen::Vector3f color_f = color.cast<float>(); |
|||
bool changed = false; |
|||
if (ImGui::ColorEdit3( |
|||
label, color_f.data(), |
|||
ImGuiColorEditFlags_NoInputs |
|||
bool DoubleColorEdit3(const char *label, Eigen::RowVector3d &color) { |
|||
Eigen::Vector3f color_f = color.cast<float>(); |
|||
bool changed = false; |
|||
if (ImGui::ColorEdit3( |
|||
label, color_f.data(), |
|||
ImGuiColorEditFlags_NoInputs |
|||
| ImGuiColorEditFlags_PickerHueWheel)) { |
|||
color = color_f.cast<double>(); |
|||
changed = true; |
|||
color = color_f.cast<double>(); |
|||
changed = true; |
|||
} |
|||
return changed; |
|||
} |
|||
return changed; |
|||
} |
|||
|
|||
void HelpMarker(const char* desc) |
|||
{ |
|||
ImGui::TextDisabled("(?)"); |
|||
if (ImGui::IsItemHovered()) { |
|||
ImGui::BeginTooltip(); |
|||
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); |
|||
ImGui::TextUnformatted(desc); |
|||
ImGui::PopTextWrapPos(); |
|||
ImGui::EndTooltip(); |
|||
void HelpMarker(const char *desc) { |
|||
ImGui::TextDisabled("(?)"); |
|||
if (ImGui::IsItemHovered()) { |
|||
ImGui::BeginTooltip(); |
|||
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); |
|||
ImGui::TextUnformatted(desc); |
|||
ImGui::PopTextWrapPos(); |
|||
ImGui::EndTooltip(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void TreeNodeJson(const nlohmann::json json) |
|||
{ |
|||
static const ImVec4 label_color = |
|||
ImVec4(241.f / 255.f, 196.f / 255.f, 15.f / 255.f, 1.0f); |
|||
ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing() * 0.1f); |
|||
ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, ImGui::GetFontSize() * 1); |
|||
for (auto& j : json.items()) { |
|||
if (j.value().is_object()) { |
|||
ImGui::PushStyleColor(ImGuiCol_Text, label_color); |
|||
if (ImGui::TreeNode(j.key().c_str())) { |
|||
ImGui::PopStyleColor(); |
|||
TreeNodeJson(j.value()); |
|||
ImGui::TreePop(); |
|||
} else { |
|||
ImGui::PopStyleColor(); |
|||
} |
|||
} else { |
|||
ImGui::Bullet(); |
|||
ImGui::TextColored(label_color, "%s: ", j.key().c_str()); |
|||
ImGui::SameLine(); |
|||
if (j.value().is_number_float()) { |
|||
ImGui::Text("%g", j.value().get<double>()); |
|||
void TreeNodeJson(const nlohmann::json json) { |
|||
static const ImVec4 label_color = |
|||
// ImVec4(241.f / 255.f, 196.f / 255.f, 15.f / 255.f, 1.0f);
|
|||
ImVec4(0.9, 0.9, 0.9, 1.0f); |
|||
ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing() * 0.1f); |
|||
ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, ImGui::GetFontSize() * 1); |
|||
for (auto &j: json.items()) { |
|||
if (j.value().is_object()) { |
|||
ImGui::PushStyleColor(ImGuiCol_Text, label_color); |
|||
if (ImGui::TreeNode(j.key().c_str())) { |
|||
ImGui::PopStyleColor(); |
|||
TreeNodeJson(j.value()); |
|||
ImGui::TreePop(); |
|||
} else { |
|||
ImGui::PopStyleColor(); |
|||
} |
|||
} else { |
|||
ImGui::Text("%s", j.value().dump().c_str()); |
|||
ImGui::Bullet(); |
|||
ImGui::TextColored(label_color, "%s: ", j.key().c_str()); |
|||
ImGui::SameLine(); |
|||
if (j.value().is_number_float()) { |
|||
ImGui::Text("%g", j.value().get<double>()); |
|||
} else if (j.value().is_array()) { |
|||
std::string the_arr; |
|||
char buffer[20]; |
|||
for (int i = 0; i < j.value().size(); ++i) { |
|||
double the_val = j.value()[i].get<double>(); |
|||
if (the_val == 0) { |
|||
buffer[0] = '0'; |
|||
buffer[1] = '\0'; |
|||
} else { |
|||
sprintf(buffer, "%.2e", the_val); |
|||
} |
|||
the_arr += (i > 0 ? std::string(" ,") : std::string("")) + std::string(buffer); |
|||
} |
|||
ImGui::Text("%s", the_arr.c_str()); |
|||
} else { |
|||
spdlog::error("wrong json data!"); |
|||
} |
|||
} |
|||
} |
|||
ImGui::PopStyleVar(); |
|||
ImGui::Indent(ImGui::GetTreeNodeToLabelSpacing() * 0.1f); |
|||
} |
|||
ImGui::PopStyleVar(); |
|||
ImGui::Indent(ImGui::GetTreeNodeToLabelSpacing() * 0.1f); |
|||
} |
|||
|
|||
void reload_font(int font_size) |
|||
{ |
|||
ImGuiIO& io = ImGui::GetIO(); |
|||
io.Fonts->Clear(); |
|||
io.Fonts->AddFontFromFileTTF("/home/oo/project/vscode/rigid_ipc/rigid-ipc/src/viewer/DroidSans.ttf", 14.0f, nullptr, |
|||
io.Fonts->GetGlyphRangesChineseFull()); |
|||
} |
|||
void reload_font(int font_size) { |
|||
ImGuiIO &io = ImGui::GetIO(); |
|||
io.Fonts->Clear(); |
|||
io.Fonts->AddFontFromFileTTF("/home/oo/project/vscode/rigid_ipc/rigid-ipc/src/viewer/DroidSans.ttf", 14.0f, |
|||
nullptr, |
|||
io.Fonts->GetGlyphRangesChineseFull()); |
|||
} |
|||
|
|||
} // namespace ImGui
|
|||
|
Loading…
Reference in new issue