| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include "module/sophiar_monitor.h"
- #include "core/imgui_utility.hpp"
- struct sophiar_monitor::impl {
- create_config conf;
- explicit impl(const create_config &_conf) {
- conf = _conf;
- }
- void show_item(const std::string &var_name,
- const std::string &show_name,
- bool last = false) {
- auto var = conf.sophiar_conn->query_transform_variable(var_name);
- bool var_ok = var.has_value();
- if (var_ok) {
- ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4) ImColor(0, 255, 0));
- } else {
- ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4) ImColor(255, 0, 0));
- }
- ImGui::Checkbox(show_name.c_str(), &var_ok);
- ImGui::PopStyleColor();
- if (!last) {
- ImGui::SameLine();
- }
- }
- void show() {
- for (auto k = 0; k < conf.item_list.size(); ++k) {
- auto &item = conf.item_list[k];
- show_item(item.var_name, item.disp_name,
- (k + 1) == conf.item_list.size());
- }
- }
- };
- sophiar_monitor::sophiar_monitor(const create_config &conf)
- : pimpl(std::make_unique<impl>(conf)) {
- }
- sophiar_monitor::~sophiar_monitor() = default;
- sophiar_monitor::item_list_type
- sophiar_monitor::item_list_from_yaml(const YAML::Node &_conf) {
- auto item_num = _conf.size();
- auto ret = item_list_type(item_num);
- for (auto k = 0; k < item_num; ++k) {
- auto conf = _conf[k];
- ret[k].disp_name = LOAD_STR("name");
- ret[k].var_name = LOAD_STR("var");
- }
- return ret;
- }
- void sophiar_monitor::show() {
- pimpl->show();
- }
|