Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Jul 6, 2023
1 parent 900302f commit b27ec78
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 58 deletions.
17 changes: 8 additions & 9 deletions src/ui/dashboardpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,19 @@ void DashboardPage::drawPlot(DigitizerUi::Dashboard::Plot &plot) noexcept {
}

void DashboardPage::draw(App *app, Dashboard *dashboard, Mode mode) noexcept {
const float left = ImGui::GetCursorPosX();
const float top = ImGui::GetCursorPosY();
const ImVec2 size = ImGui::GetContentRegionAvail();
const float left = ImGui::GetCursorPosX();
const float top = ImGui::GetCursorPosY();
const ImVec2 size = ImGui::GetContentRegionAvail();

const bool horizontalSplit = size.x > size.y;
constexpr float splitterWidth = 6;
const bool horizontalSplit = size.x > size.y;
constexpr float splitterWidth = 6;
constexpr float halfSplitterWidth = splitterWidth / 2.f;
const float ratio = m_editPane.block ? ImGuiUtils::splitter(size, horizontalSplit, splitterWidth, 0.2f) : 0.f;
const float ratio = m_editPane.block ? ImGuiUtils::splitter(size, horizontalSplit, splitterWidth, 0.2f) : 0.f;

ImGui::SetCursorPosX(left);
ImGui::SetCursorPosY(top);

ImGui::BeginChild("##plots", horizontalSplit ? ImVec2(size.x * (1.f - ratio) - halfSplitterWidth, size.y) :
ImVec2(size.x, size.y * (1.f - ratio) - halfSplitterWidth),
ImGui::BeginChild("##plots", horizontalSplit ? ImVec2(size.x * (1.f - ratio) - halfSplitterWidth, size.y) : ImVec2(size.x, size.y * (1.f - ratio) - halfSplitterWidth),
false, ImGuiWindowFlags_NoScrollbar);

if (ImGui::IsWindowHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
Expand Down Expand Up @@ -404,7 +403,7 @@ void DashboardPage::draw(App *app, Dashboard *dashboard, Mode mode) noexcept {
ImGuiUtils::drawBlockControlsPanel(m_editPane, { left + size.x - w + halfSplitterWidth, top }, { w - halfSplitterWidth, size.y }, true);
} else {
const float h = size.y * ratio;
ImGuiUtils::drawBlockControlsPanel(m_editPane, { left, top + size.y - h + halfSplitterWidth }, { size.x, h - halfSplitterWidth}, false);
ImGuiUtils::drawBlockControlsPanel(m_editPane, { left, top + size.y - h + halfSplitterWidth }, { size.x, h - halfSplitterWidth }, false);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/ui/dashboardpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#define DASHBOARDPAGE_H

#include "grid_layout.h"
#include "imguiutils.h"
#include <imgui.h>
#include <stack>
#include <string>
#include <vector>
#include "imguiutils.h"

namespace DigitizerUi {

Expand Down Expand Up @@ -50,13 +50,13 @@ class DashboardPage {

public:
void draw(App *app, Dashboard *Dashboard, Mode mode = Mode::View) noexcept;
void newPlot(Dashboard *dashboard);
void newPlot(Dashboard *dashboard);

private:
void drawPlots(App *app, DigitizerUi::DashboardPage::Mode mode, Dashboard *dashboard);
void drawGrid(float w, float h);
void drawLegend(App *app, Dashboard *dashboard, const Mode &mode) noexcept;
static void drawPlot(DigitizerUi::Dashboard::Plot &plot) noexcept;
void drawPlots(App *app, DigitizerUi::DashboardPage::Mode mode, Dashboard *dashboard);
void drawGrid(float w, float h);
void drawLegend(App *app, Dashboard *dashboard, const Mode &mode) noexcept;
static void drawPlot(DigitizerUi::Dashboard::Plot &plot) noexcept;

ImGuiUtils::BlockControlsPanel m_editPane;
};
Expand Down
27 changes: 13 additions & 14 deletions src/ui/flowgraphitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ void FlowGraphItem::addBlock(const Block &b, std::optional<ImVec2> nodePos, Alig
ImGui::SetCursorPos(curPos);

// auto y = curPos.y;
const auto &inputs = b.inputs();
auto *inputWidths = static_cast<float *>(alloca(sizeof(float) * inputs.size()));
const auto &inputs = b.inputs();
auto *inputWidths = static_cast<float *>(alloca(sizeof(float) * inputs.size()));

auto curScreenPos = ImGui::GetCursorScreenPos();
ImVec2 pos = { curScreenPos.x - padding.x, curScreenPos.y };
auto curScreenPos = ImGui::GetCursorScreenPos();
ImVec2 pos = { curScreenPos.x - padding.x, curScreenPos.y };
for (std::size_t i = 0; i < inputs.size(); ++i) {
inputWidths[i] = ImGui::CalcTextSize(b.type->inputs[i].name.c_str()).x + textMargin * 2;
if (!filteredOut) {
Expand Down Expand Up @@ -392,20 +392,19 @@ void FlowGraphItem::draw(FlowGraph *fg, const ImVec2 &size) {
c.config.UserPointer = &c;
ax::NodeEditor::SetCurrentEditor(c.editor);

const float left = ImGui::GetCursorPosX();
const float top = ImGui::GetCursorPosY();
const float left = ImGui::GetCursorPosX();
const float top = ImGui::GetCursorPosY();

const bool horizontalSplit = size.x > size.y;
constexpr float splitterWidth = 6;
const bool horizontalSplit = size.x > size.y;
constexpr float splitterWidth = 6;
constexpr float halfSplitterWidth = splitterWidth / 2.f;
const float ratio = m_editPane.block ? ImGuiUtils::splitter(size, horizontalSplit, splitterWidth, 0.2f) : 0.f;
const float ratio = m_editPane.block ? ImGuiUtils::splitter(size, horizontalSplit, splitterWidth, 0.2f) : 0.f;

ImGui::SetCursorPosX(left);
ImGui::SetCursorPosY(top);

ImGui::BeginChild("##canvas", horizontalSplit ? ImVec2(size.x * (1.f - ratio) - halfSplitterWidth, size.y) :
ImVec2(size.x, size.y * (1.f - ratio) - halfSplitterWidth),
false, ImGuiWindowFlags_NoScrollbar);
ImGui::BeginChild("##canvas", horizontalSplit ? ImVec2(size.x * (1.f - ratio) - halfSplitterWidth, size.y) : ImVec2(size.x, size.y * (1.f - ratio) - halfSplitterWidth),
false, ImGuiWindowFlags_NoScrollbar);

ax::NodeEditor::Begin("My Editor", ImGui::GetContentRegionAvail());

Expand Down Expand Up @@ -511,7 +510,7 @@ void FlowGraphItem::draw(FlowGraph *fg, const ImVec2 &size) {
if (!block) {
m_editPane.block = nullptr;
} else {
m_editPane.block = block;
m_editPane.block = block;
m_editPane.closeTime = std::chrono::system_clock::now() + App::instance().editPaneCloseDelay;
}
}
Expand Down Expand Up @@ -633,7 +632,7 @@ void FlowGraphItem::draw(FlowGraph *fg, const ImVec2 &size) {
ImGuiUtils::drawBlockControlsPanel(m_editPane, { left + size.x - w + halfSplitterWidth, top }, { w - halfSplitterWidth, size.y }, true);
} else {
const float h = size.y * ratio;
ImGuiUtils::drawBlockControlsPanel(m_editPane, { left, top + size.y - h + halfSplitterWidth }, { size.x, h - halfSplitterWidth}, false);
ImGuiUtils::drawBlockControlsPanel(m_editPane, { left, top + size.y - h + halfSplitterWidth }, { size.x, h - halfSplitterWidth }, false);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ui/flowgraphitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class FlowGraphItem {
ax::NodeEditor::Config config;
std::string settings;
};
std::unordered_map<FlowGraph *, Context> m_editors;
ImGuiUtils::BlockControlsPanel m_editPane;
std::unordered_map<FlowGraph *, Context> m_editors;
ImGuiUtils::BlockControlsPanel m_editPane;
};

} // namespace DigitizerUi
36 changes: 17 additions & 19 deletions src/ui/imguiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
ImGui::SetCursorPos(pos);

if (ImGui::BeginChildFrame(1, size, ImGuiWindowFlags_NoScrollbar)) {
size = ImGui::GetContentRegionAvail();
size = ImGui::GetContentRegionAvail();

// don't close the panel while the mouse is hovering it.
if (ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
Expand All @@ -113,13 +113,13 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
ImGui::ProgressBar(1.f - duration, { size.x, 3 });
ImGui::PopStyleColor();

auto minpos = ImGui::GetCursorPos();
size = ImGui::GetContentRegionAvail();
auto minpos = ImGui::GetCursorPos();
size = ImGui::GetContentRegionAvail();

int outputsCount = 0;
{
const char *prevString = verticalLayout ? "\uf062" : "\uf060";
for (const auto &out: ctx.block->outputs()) {
for (const auto &out : ctx.block->outputs()) {
outputsCount += out.connections.size();
}
if (outputsCount == 0) {
Expand All @@ -133,7 +133,7 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
ImGui::BeginGroup();
int id = 1;
for (auto &out : ctx.block->outputs()) {
for (const auto *conn: out.connections) {
for (const auto *conn : out.connections) {
ImGui::PushID(id++);

ImGui::PushFont(app.fontIconsSolid);
Expand All @@ -152,7 +152,6 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
}
ImGui::EndGroup();
}

}

if (!verticalLayout) {
Expand All @@ -162,20 +161,20 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
{
// Draw the two add block buttons
ImGui::BeginGroup();
const auto buttonSize = calcButtonSize(2);
const auto buttonSize = calcButtonSize(2);
{
ImGuiUtils::DisabledGuard dg(ctx.mode != BlockControlsPanel::Mode::None || outputsCount == 0);
ImGui::PushFont(app.fontIconsSolid);
if (ImGui::Button("\uf055", buttonSize)) {
if (outputsCount > 1) {
ImGui::OpenPopup("insertBlockPopup");
} else {
[&](){
[&]() {
int index = 0;
for (auto &out : ctx.block->outputs()) {
for (auto *conn: out.connections) {
ctx.insertFrom = conn->ports[0];
ctx.insertBefore = conn->ports[1];
for (auto *conn : out.connections) {
ctx.insertFrom = conn->ports[0];
ctx.insertBefore = conn->ports[1];
ctx.breakConnection = conn;
return;
}
Expand All @@ -191,12 +190,12 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
if (ImGui::BeginPopup("insertBlockPopup")) {
int index = 0;
for (auto &out : ctx.block->outputs()) {
for (auto *conn: out.connections) {
for (auto *conn : out.connections) {
auto text = fmt::format("Before block '{}'", conn->ports[1]->block->name);
if (ImGui::Selectable(text.c_str())) {
ctx.insertBefore = conn->ports[1];
ctx.mode = BlockControlsPanel::Mode::Insert;
ctx.insertFrom = conn->ports[0];
ctx.insertBefore = conn->ports[1];
ctx.mode = BlockControlsPanel::Mode::Insert;
ctx.insertFrom = conn->ports[0];
ctx.breakConnection = conn;
}
}
Expand All @@ -216,7 +215,7 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
if (ctx.block->outputs().size() > 1) {
ImGui::OpenPopup("addBlockPopup");
} else {
ctx.mode = BlockControlsPanel::Mode::AddAndBranch;
ctx.mode = BlockControlsPanel::Mode::AddAndBranch;
ctx.insertFrom = &ctx.block->outputs()[0];
}
}
Expand All @@ -225,10 +224,10 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im

if (ImGui::BeginPopup("addBlockPopup")) {
int index = 0;
for (const auto &out: ctx.block->type->outputs) {
for (const auto &out : ctx.block->type->outputs) {
if (ImGui::Selectable(out.name.c_str())) {
ctx.insertFrom = &ctx.block->outputs()[index];
ctx.mode = BlockControlsPanel::Mode::AddAndBranch;
ctx.mode = BlockControlsPanel::Mode::AddAndBranch;
}
++index;
}
Expand Down Expand Up @@ -281,7 +280,6 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im

app.dashboardPage.newPlot(app.dashboard.get());
app.dashboard->plots().back().sources.push_back(&*source);

}
ctx.block = block.get();

Expand Down
16 changes: 8 additions & 8 deletions src/ui/imguiutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ inline ImVec2 operator-(const ImVec2 a, const ImVec2 b) {
namespace DigitizerUi {
class Block;
class Dashboard;
}
} // namespace DigitizerUi

namespace ImGuiUtils {

Expand Down Expand Up @@ -222,22 +222,22 @@ DialogButton drawDialogButtons(bool okEnabled = true);
float splitter(ImVec2 space, bool vertical, float size, float defaultRatio = 0.5);

struct BlockControlsPanel {
DigitizerUi::Block *block = {};
DigitizerUi::Block *block = {};
enum class Mode {
None,
Insert,
AddAndBranch
};
Mode mode = Mode::None;
DigitizerUi::Block::Port *insertBefore = nullptr;
DigitizerUi::Block::Port *insertFrom = nullptr;
DigitizerUi::Connection *breakConnection = nullptr;
Mode mode = Mode::None;
DigitizerUi::Block::Port *insertBefore = nullptr;
DigitizerUi::Block::Port *insertFrom = nullptr;
DigitizerUi::Connection *breakConnection = nullptr;
std::chrono::time_point<std::chrono::system_clock> closeTime;
};
void drawBlockControlsPanel(BlockControlsPanel &context, const ImVec2 &pos, const ImVec2 &frameSize, bool verticalLayout);

void blockParametersControls(DigitizerUi::Block *b, bool verticalLayout, const ImVec2 &size = { 0.f, 0.f });
void setItemTooltip(const char *fmt, auto &&...args) {
void blockParametersControls(DigitizerUi::Block *b, bool verticalLayout, const ImVec2 &size = { 0.f, 0.f });
void setItemTooltip(const char *fmt, auto &&...args) {
if (ImGui::IsItemHovered()) {
if constexpr (sizeof...(args) == 0) {
ImGui::SetTooltip(fmt);
Expand Down

0 comments on commit b27ec78

Please sign in to comment.