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