Skip to content

Commit a1e579b

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent cbd1cdb commit a1e579b

25 files changed

+175
-633
lines changed

Diff for: Category.cpp

+8-32
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,19 @@ void Category::draw2D()
1414
{
1515
w->draw2D();
1616
++i;
17-
if(i != widgets.size())
18-
{
19-
IndentedSeparator();
20-
}
17+
if(i != widgets.size()) { IndentedSeparator(); }
2118
continue;
2219
}
2320
size_t j = i + 1;
24-
while(j < widgets.size() && widgets[j]->id.sid == w->id.sid)
25-
{
26-
++j;
27-
}
21+
while(j < widgets.size() && widgets[j]->id.sid == w->id.sid) { ++j; }
2822
ImGui::BeginTable(fmt::format("{}_table_{}", w->id.category, i).c_str(), j - i, ImGuiTableFlags_SizingStretchProp);
2923
for(; i < j; ++i)
3024
{
3125
ImGui::TableNextColumn();
3226
widgets[i]->draw2D();
3327
}
3428
ImGui::EndTable();
35-
if(i != widgets.size())
36-
{
37-
IndentedSeparator();
38-
}
29+
if(i != widgets.size()) { IndentedSeparator(); }
3930
}
4031
if(categories.size())
4132
{
@@ -61,35 +52,20 @@ void Category::draw2D()
6152

6253
void Category::draw3D()
6354
{
64-
for(auto & w : widgets)
65-
{
66-
w->draw3D();
67-
}
68-
for(auto & cat : categories)
69-
{
70-
cat->draw3D();
71-
}
55+
for(auto & w : widgets) { w->draw3D(); }
56+
for(auto & cat : categories) { cat->draw3D(); }
7257
}
7358

7459
void Category::started()
7560
{
76-
for(auto & w : widgets)
77-
{
78-
w->seen = false;
79-
}
80-
for(auto & cat : categories)
81-
{
82-
cat->started();
83-
}
61+
for(auto & w : widgets) { w->seen = false; }
62+
for(auto & cat : categories) { cat->started(); }
8463
}
8564

8665
void Category::stopped()
8766
{
8867
/** Clean up categories first */
89-
for(auto & cat : categories)
90-
{
91-
cat->stopped();
92-
}
68+
for(auto & cat : categories) { cat->stopped(); }
9369
/** Remove empty categories */
9470
{
9571
auto it = std::remove_if(categories.begin(), categories.end(),

Diff for: Category.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ struct Category
1919
std::vector<WidgetPtr> widgets;
2020
std::vector<CategoryPtr> categories;
2121

22-
inline bool empty() const
23-
{
24-
return widgets.size() == 0 && categories.size() == 0;
25-
}
22+
inline bool empty() const { return widgets.size() == 0 && categories.size() == 0; }
2623

2724
void draw2D();
2825
void draw3D();

Diff for: Client.cpp

+7-28
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ void Client::draw2D(ImVec2 windowSize)
7373
p.second->do_plot();
7474
ImGui::EndTabItem();
7575
}
76-
else
77-
{
78-
ImGui::PopFont();
79-
}
76+
else { ImGui::PopFont(); }
8077
}
8178
for(auto it = inactive_plots_.begin(); it != inactive_plots_.end();)
8279
{
@@ -93,10 +90,7 @@ void Client::draw2D(ImVec2 windowSize)
9390
ImGui::EndTabBar();
9491
}
9592
ImGui::End();
96-
if(!open_plots)
97-
{
98-
inactive_plots_.clear();
99-
}
93+
if(!open_plots) { inactive_plots_.clear(); }
10094
}
10195
}
10296

@@ -120,10 +114,7 @@ void Client::stopped()
120114
inactive_plots_.push_back(it->second);
121115
it = active_plots_.erase(it);
122116
}
123-
else
124-
{
125-
++it;
126-
}
117+
else { ++it; }
127118
}
128119
}
129120

@@ -214,10 +205,7 @@ void Client::form(const ElementId & id)
214205
template<typename T>
215206
std::optional<T> null_or_default(const T & value, bool user_default)
216207
{
217-
if(user_default)
218-
{
219-
return value;
220-
}
208+
if(user_default) { return value; }
221209
return std::nullopt;
222210
}
223211

@@ -299,24 +287,15 @@ auto Client::getCategory(const std::vector<std::string> & category) -> Category
299287
auto & cat = out.get();
300288
auto & next = category[i];
301289
auto it = std::find_if(cat.categories.begin(), cat.categories.end(), [&](auto & c) { return c->name == next; });
302-
if(it != cat.categories.end())
303-
{
304-
out = std::ref(*it->get());
305-
}
306-
else
307-
{
308-
out = *cat.categories.emplace_back(std::make_unique<Category>(next, cat.depth + 1));
309-
}
290+
if(it != cat.categories.end()) { out = std::ref(*it->get()); }
291+
else { out = *cat.categories.emplace_back(std::make_unique<Category>(next, cat.depth + 1)); }
310292
}
311293
return out.get();
312294
}
313295

314296
void Client::start_plot(uint64_t id, const std::string & title)
315297
{
316-
if(!active_plots_.count(id))
317-
{
318-
active_plots_[id] = std::make_shared<Plot>(title);
319-
}
298+
if(!active_plots_.count(id)) { active_plots_[id] = std::make_shared<Plot>(title); }
320299
if(active_plots_[id]->title() != title)
321300
{
322301
inactive_plots_.push_back(active_plots_[id]);

Diff for: Client.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ struct Client : public mc_control::ControllerClient
2727
/** Remove all elements */
2828
void clear();
2929

30-
inline const mc_rtc::Configuration & data() const noexcept
31-
{
32-
return data_;
33-
}
30+
inline const mc_rtc::Configuration & data() const noexcept { return data_; }
3431

35-
inline void set_bold_font(ImFont * font)
36-
{
37-
bold_font_ = font;
38-
}
32+
inline void set_bold_font(ImFont * font) { bold_font_ = font; }
3933

4034
protected:
4135
std::vector<char> buffer_ = std::vector<char>(65535);

Diff for: Plot.cpp

+22-63
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,10 @@ inline void range_to_limits(const mc_rtc::gui::plot::Range & range,
1717
if(range.min != -range.inf || range.max != range.inf)
1818
{
1919
limits = {range.min, range.max};
20-
if(range.min == -range.inf)
21-
{
22-
limits->first = plotRange.Min;
23-
}
24-
if(range.max == range.inf)
25-
{
26-
limits->second = plotRange.Max;
27-
}
28-
}
29-
else
30-
{
31-
limits = std::nullopt;
20+
if(range.min == -range.inf) { limits->first = plotRange.Min; }
21+
if(range.max == range.inf) { limits->second = plotRange.Max; }
3222
}
23+
else { limits = std::nullopt; }
3324
}
3425

3526
} // namespace
@@ -64,7 +55,8 @@ void Plot::plot_point(uint64_t did,
6455
mc_rtc::gui::plot::Style style,
6556
mc_rtc::gui::plot::Side side)
6657
{
67-
auto get_plot = [&]() -> PlotLine & {
58+
auto get_plot = [&]() -> PlotLine &
59+
{
6860
if(!plots_.count(did))
6961
{
7062
plots_[did] = {};
@@ -87,10 +79,7 @@ void Plot::plot_polygon(uint64_t did,
8779
mc_rtc::gui::plot::Side side)
8880
{
8981
auto & poly = polygons_[did];
90-
if(poly.polygon != polygon)
91-
{
92-
poly.polygon = polygon;
93-
}
82+
if(poly.polygon != polygon) { poly.polygon = polygon; }
9483
poly.label = label;
9584
poly.side = side;
9685
side == Side::Left ? y_plots_++ : y2_plots_++;
@@ -102,10 +91,7 @@ void Plot::plot_polygons(uint64_t did,
10291
mc_rtc::gui::plot::Side side)
10392
{
10493
auto & group = polygonGroups_[did];
105-
if(group.polygons != polygons)
106-
{
107-
group.polygons = polygons;
108-
}
94+
if(group.polygons != polygons) { group.polygons = polygons; }
10995
group.label = label;
11096
group.side = side;
11197
side == Side::Left ? y_plots_++ : y2_plots_++;
@@ -122,52 +108,34 @@ void Plot::do_plot()
122108
y_flags = ImPlotAxisFlags_NoDecorations;
123109
y_label = nullptr;
124110
}
125-
else
126-
{
127-
y2_flags |= ImPlotAxisFlags_NoGridLines;
128-
}
111+
else { y2_flags |= ImPlotAxisFlags_NoGridLines; }
129112
const char * y2_label = y2_label_.c_str();
130113
if(y2_plots_ == 0)
131114
{
132115
y2_flags = ImPlotAxisFlags_NoDecorations;
133116
y2_label = nullptr;
134117
}
135118
bool do_ = ImPlot::BeginPlot(fmt::format("{}##{}", title_, uid_).c_str(), ImVec2{-1, 0}, ImPlotFlags_YAxis2);
136-
if(!do_)
137-
{
138-
return;
139-
}
119+
if(!do_) { return; }
140120
ImPlot::SetupAxis(ImAxis_X1, x_label_.c_str(), x_flags);
141-
if(y_plots_ != 0)
142-
{
143-
ImPlot::SetupAxis(ImAxis_Y1, y_label, y_flags);
144-
}
145-
if(y2_plots_ != 0)
146-
{
147-
ImPlot::SetupAxis(ImAxis_Y2, y2_label, y2_flags);
148-
}
149-
if(x_limits_)
150-
{
151-
ImPlot::SetupAxisLimits(ImAxis_X1, x_limits_->first, x_limits_->second, ImGuiCond_Always);
152-
}
153-
if(y_limits_)
154-
{
155-
ImPlot::SetupAxisLimits(ImAxis_Y1, y_limits_->first, y_limits_->second, ImGuiCond_Always);
156-
}
157-
if(y2_limits_)
121+
if(y_plots_ != 0) { ImPlot::SetupAxis(ImAxis_Y1, y_label, y_flags); }
122+
if(y2_plots_ != 0) { ImPlot::SetupAxis(ImAxis_Y2, y2_label, y2_flags); }
123+
if(x_limits_) { ImPlot::SetupAxisLimits(ImAxis_X1, x_limits_->first, x_limits_->second, ImGuiCond_Always); }
124+
if(y_limits_) { ImPlot::SetupAxisLimits(ImAxis_Y1, y_limits_->first, y_limits_->second, ImGuiCond_Always); }
125+
if(y2_limits_) { ImPlot::SetupAxisLimits(ImAxis_Y2, y2_limits_->first, y2_limits_->second, ImGuiCond_Always); }
126+
auto toImVec4 = [](const Color & color)
158127
{
159-
ImPlot::SetupAxisLimits(ImAxis_Y2, y2_limits_->first, y2_limits_->second, ImGuiCond_Always);
160-
}
161-
auto toImVec4 = [](const Color & color) {
162128
return ImVec4{static_cast<float>(color.r), static_cast<float>(color.g), static_cast<float>(color.b),
163129
static_cast<float>(color.a)};
164130
};
165-
auto toImU32 = [](const Color & color) {
131+
auto toImU32 = [](const Color & color)
132+
{
166133
return ImGui::ColorConvertFloat4ToU32({static_cast<float>(color.r), static_cast<float>(color.g),
167134
static_cast<float>(color.b), static_cast<float>(color.a)});
168135
};
169136
ImPlot::PushStyleVar(ImPlotStyleVar_FitPadding, ImVec2{0.1f, 0.1f});
170-
auto plot_poly = [this, &toImU32](const PolygonDescription & poly, Side side) {
137+
auto plot_poly = [this, &toImU32](const PolygonDescription & poly, Side side)
138+
{
171139
auto * draw_list = ImPlot::GetPlotDrawList();
172140
const auto & style = poly.style();
173141
// FIXME Handle style
@@ -179,15 +147,9 @@ void Plot::do_plot()
179147
for(size_t i = 0; i < poly.points().size(); ++i)
180148
{
181149
points_[i] = ImPlot::PlotToPixels(poly.points()[i][0], poly.points()[i][1]);
182-
if(ImPlot::FitThisFrame())
183-
{
184-
ImPlot::FitPoint({poly.points()[i][0], poly.points()[i][1]});
185-
}
186-
}
187-
if(fillColor.a != 0.0)
188-
{
189-
draw_list->AddConvexPolyFilled(points_.data(), points_.size(), toImU32(fillColor));
150+
if(ImPlot::FitThisFrame()) { ImPlot::FitPoint({poly.points()[i][0], poly.points()[i][1]}); }
190151
}
152+
if(fillColor.a != 0.0) { draw_list->AddConvexPolyFilled(points_.data(), points_.size(), toImU32(fillColor)); }
191153
draw_list->AddPolyline(points_.data(), points_.size(), toImU32(outlineColor), closed, 2.0f);
192154
};
193155
for(const auto & pp : polygons_)
@@ -204,10 +166,7 @@ void Plot::do_plot()
204166
const auto & group = pp.second;
205167
if(ImPlot::BeginItem(group.label.c_str()))
206168
{
207-
for(const auto & p : group.polygons)
208-
{
209-
plot_poly(p, group.side);
210-
}
169+
for(const auto & p : group.polygons) { plot_poly(p, group.side); }
211170
ImPlot::EndItem();
212171
}
213172
}

Diff for: Plot.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ struct Plot
2222

2323
Plot(const std::string & title);
2424

25-
inline const std::string & title() const noexcept
26-
{
27-
return title_;
28-
}
25+
inline const std::string & title() const noexcept { return title_; }
2926

3027
inline void start_plot() noexcept
3128
{

Diff for: Widget.h

+13-15
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,26 @@
1717
// #include <fmt/core.h>
1818
// #include <vector>
1919

20+
#include <Eigen/Dense>
2021
#include <fmt/core.h>
2122
#include <fmt/ranges.h>
23+
#include <string>
2224
#include <string_view>
2325
#include <vector>
24-
#include <string>
25-
#include <Eigen/Dense>
2626

27-
template <>
28-
struct fmt::formatter<Eigen::VectorXd> : fmt::formatter<std::string> {
29-
template <typename FormatContext>
30-
auto format(const Eigen::VectorXd& vec, FormatContext& ctx) {
31-
std::string result = "[";
32-
for (int i = 0; i < vec.size(); ++i) {
33-
result += fmt::format("{}{}", vec[i], (i < vec.size() - 1 ? ", " : ""));
34-
}
35-
result += "]";
36-
return formatter<std::string>::format(result, ctx);
37-
}
27+
template<>
28+
struct fmt::formatter<Eigen::VectorXd> : fmt::formatter<std::string>
29+
{
30+
template<typename FormatContext>
31+
auto format(const Eigen::VectorXd & vec, FormatContext & ctx)
32+
{
33+
std::string result = "[";
34+
for(int i = 0; i < vec.size(); ++i) { result += fmt::format("{}{}", vec[i], (i < vec.size() - 1 ? ", " : "")); }
35+
result += "]";
36+
return formatter<std::string>::format(result, ctx);
37+
}
3838
};
3939

40-
41-
4240
namespace mc_rtc::imgui
4341
{
4442

0 commit comments

Comments
 (0)