Skip to content

Commit

Permalink
some wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-cukic committed Apr 9, 2024
1 parent 5c6c3f7 commit 7a651d0
Show file tree
Hide file tree
Showing 10 changed files with 459 additions and 374 deletions.
2 changes: 1 addition & 1 deletion src/ui/app_header/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_library(
app_header INTERFACE
"fair_header.h"
"fair_header.hpp"
PopupMenu.hpp
)
target_include_directories(app_header INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
103 changes: 53 additions & 50 deletions src/ui/dashboardpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "flowgraph/datasink.hpp"
#include "imguiutils.hpp"

#include "utils/ImguiWrap.hpp"
#include "utils/TouchHandler.hpp"

namespace DigitizerUi {
Expand Down Expand Up @@ -347,64 +348,66 @@ void DashboardPage::draw(App *app, Dashboard *dashboard, Mode mode) noexcept {
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),
false, ImGuiWindowFlags_NoScrollbar);
{
IMW::Child plotsChild("##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)) {
m_editPane.block = nullptr;
}
if (ImGui::IsWindowHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
m_editPane.block = nullptr;
}

// Plots
ImGui::BeginGroup();
drawPlots(app, mode, dashboard);
ImGui::EndGroup(); // Plots
// Plots
{
IMW::Group group;
drawPlots(app, mode, dashboard);
}

ImGui::SetCursorPos(ImVec2(0, ImGui::GetWindowHeight() - legend_box.y));
ImGui::SetCursorPos(ImVec2(0, ImGui::GetWindowHeight() - legend_box.y));

// Legend
ImGui::BeginGroup();
// Button strip
if (mode == Mode::Layout) {
if (plotButton(app, "\uF201", "create new chart")) // chart-line
newPlot(dashboard);
ImGui::SameLine();
if (plotButton(app, "\uF7A5", "change to the horizontal layout"))
plot_layout.SetArrangement(GridArrangement::Horizontal);
ImGui::SameLine();
if (plotButton(app, "\uF7A4", "change to the vertical layout"))
plot_layout.SetArrangement(GridArrangement::Vertical);
ImGui::SameLine();
if (plotButton(app, "\uF58D", "change to the grid layout"))
plot_layout.SetArrangement(GridArrangement::Tiles);
ImGui::SameLine();
if (plotButton(app, "\uF248", "change to the free layout"))
plot_layout.SetArrangement(GridArrangement::Free);
ImGui::SameLine();
}
// Legend
{
IMW::Group group;
// Button strip
if (mode == Mode::Layout) {
if (plotButton(app, "\uF201", "create new chart")) // chart-line
newPlot(dashboard);
ImGui::SameLine();
if (plotButton(app, "\uF7A5", "change to the horizontal layout"))
plot_layout.SetArrangement(GridArrangement::Horizontal);
ImGui::SameLine();
if (plotButton(app, "\uF7A4", "change to the vertical layout"))
plot_layout.SetArrangement(GridArrangement::Vertical);
ImGui::SameLine();
if (plotButton(app, "\uF58D", "change to the grid layout"))
plot_layout.SetArrangement(GridArrangement::Tiles);
ImGui::SameLine();
if (plotButton(app, "\uF248", "change to the free layout"))
plot_layout.SetArrangement(GridArrangement::Free);
ImGui::SameLine();
}

drawLegend(app, dashboard, mode);
drawLegend(app, dashboard, mode);

// Post button strip
if (mode == Mode::Layout) {
ImGui::SameLine();
if (plotButton(app, "\uf067", "add signal")) { // plus
// add new signal
}
}
// Post button strip
if (mode == Mode::Layout) {
ImGui::SameLine();
if (plotButton(app, "\uf067", "add signal")) { // plus
// add new signal
}
}

if (app->prototypeMode) {
ImGui::SameLine();
// Retrieve FPS and milliseconds per iteration
const float fps = ImGui::GetIO().Framerate;
const auto str = fmt::format("FPS:{:5.0f}({:2}ms)", fps, app->execTime.count());
const auto estSize = ImGui::CalcTextSize(str.c_str());
alignForWidth(estSize.x, 1.0);
ImGui::Text("%s", str.c_str());
if (app->prototypeMode) {
ImGui::SameLine();
// Retrieve FPS and milliseconds per iteration
const float fps = ImGui::GetIO().Framerate;
const auto str = fmt::format("FPS:{:5.0f}({:2}ms)", fps, app->execTime.count());
const auto estSize = ImGui::CalcTextSize(str.c_str());
alignForWidth(estSize.x, 1.0);
ImGui::Text("%s", str.c_str());
}
}
legend_box.y = std::floor(ImGui::GetItemRectSize().y * 1.5f);
}
ImGui::EndGroup(); // Legend
legend_box.y = std::floor(ImGui::GetItemRectSize().y * 1.5f);

ImGui::EndChild();

if (horizontalSplit) {
const float w = size.x * ratio;
Expand Down
66 changes: 33 additions & 33 deletions src/ui/flowgraphitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "flowgraph.hpp"
#include "imguiutils.hpp"

#include "utils/ImguiWrap.hpp"

namespace DigitizerUi {

// Function to perform topological sort on the graph
Expand Down Expand Up @@ -625,41 +627,42 @@ void FlowGraphItem::draw(FlowGraph *fg, const ImVec2 &size) {
ImGui::SetNextWindowPos({ origCursorPos.x, origCursorPos.y + size.y * (1 - ratio) - 39 }, ImGuiCond_Always); // on vertical, we need some extra space for the splitter
}
ImGui::SetNextWindowSize({ size.x * (ratio && horizontalSplit ? 1 - ratio : 1), 37 });
ImGui::Begin("Button Overlay", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoBackground);
// These Buttons are rendered on top of the Editor, to make them properly readable, take out the opacity
ImVec4 buttonColor = ImGui::GetStyleColorVec4(ImGuiCol_Button);
buttonColor.w = 1.0f;
ImGui::PushStyleColor(ImGuiCol_Button, buttonColor);

ImGui::SetCursorPosX(15);
if (ImGui::Button("Add signal")) {
ImGui::OpenPopup("addSignalPopup");
}
{
IMW::Window overlay("Button Overlay", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoBackground);
// These Buttons are rendered on top of the Editor, to make them properly readable, take out the opacity
ImVec4 buttonColor = ImGui::GetStyleColorVec4(ImGuiCol_Button);
buttonColor.w = 1.0f;
ImGui::PushStyleColor(ImGuiCol_Button, buttonColor);

ImGui::SameLine();
ImGui::SetCursorPosX(15);
if (ImGui::Button("Add signal")) {
ImGui::OpenPopup("addSignalPopup");
}

float newSinkButtonPos = ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize("New Sink").x - 15;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + newSinkButtonPos / 2 - ImGui::CalcTextSize("Re-Layout Graph").x);
if (ImGui::Button("Re-Layout Graph")) {
m_layoutGraph = true;
}
ImGui::SameLine();

ImGui::SameLine();
float newSinkButtonPos = ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize("New Sink").x - 15;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + newSinkButtonPos / 2 - ImGui::CalcTextSize("Re-Layout Graph").x);
if (ImGui::Button("Re-Layout Graph")) {
m_layoutGraph = true;
}

ImGui::SetCursorPosX(newSinkButtonPos);
if (ImGui::Button("New sink") && newSinkCallback) {
m_nodesToArrange.push_back(newSinkCallback(fg));
m_nodesToArrange.push_back(newSinkSourceCallback(fg));
}
ImGui::PopStyleColor();
ImGui::SameLine();

if (openNewBlockDialog) {
ImGui::OpenPopup("New block");
}
drawNewBlockDialog(fg);
drawAddSourceDialog(fg);
ImGui::SetCursorPosX(newSinkButtonPos);
if (ImGui::Button("New sink") && newSinkCallback) {
m_nodesToArrange.push_back(newSinkCallback(fg));
m_nodesToArrange.push_back(newSinkSourceCallback(fg));
}
ImGui::PopStyleColor();

ImGui::End(); // overlay
if (openNewBlockDialog) {
ImGui::OpenPopup("New block");
}
drawNewBlockDialog(fg);
drawAddSourceDialog(fg);
}

if (horizontalSplit) {
const float w = size.x * ratio;
Expand Down Expand Up @@ -694,7 +697,7 @@ void FlowGraphItem::drawAddSourceDialog(FlowGraph *fg) {
ImGui::SetNextWindowSize({ 800, 600 }, ImGuiCond_Once);
if (ImGui::BeginPopupModal("addSignalPopup", nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
static BlockType *sel = nullptr;
if (ImGui::BeginChild(1, { 0, ImGui::GetContentRegionAvail().y - 50 })) {
if (auto child = IMW::ChildWithId(1, ImVec2{ 0, ImGui::GetContentRegionAvail().y - 50 }, 0, 0)) {
struct Cat {
std::string name;
std::vector<BlockType *> types;
Expand Down Expand Up @@ -736,7 +739,7 @@ void FlowGraphItem::drawAddSourceDialog(FlowGraph *fg) {
}
ImGui::Separator();
ImGui::SetNextWindowSize(ImGui::GetContentRegionAvail(), ImGuiCond_Once);
ImGui::BeginChild("Signals");
IMW::Child signals("Signals", ImVec2(0, 0), 0, 0);

signalList.addRemoteSignalCallback = [fg](const opencmw::service::dns::Entry &entry) {
const auto uri = opencmw::URI<>::UriFactory().scheme(entry.protocol).hostName(entry.hostname).port(static_cast<uint16_t>(entry.port)).path(entry.service_name).addQueryParameter("channelNameFilter", entry.signal_name).build();
Expand All @@ -750,8 +753,6 @@ void FlowGraphItem::drawAddSourceDialog(FlowGraph *fg) {
if (ImGui::Button("Refresh")) {
signalList.update();
}

ImGui::EndChild();
}

if (isRemote) {
Expand Down Expand Up @@ -788,7 +789,6 @@ void FlowGraphItem::drawAddSourceDialog(FlowGraph *fg) {
}
}
}
ImGui::EndChild();

if (ImGuiUtils::drawDialogButtons(sel) == ImGuiUtils::DialogButton::Ok) {
fg->addSourceBlock(sel->createBlock({}));
Expand Down
50 changes: 25 additions & 25 deletions src/ui/imguiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "flowgraph.hpp"
#include "flowgraph/datasink.hpp"
#include "imguiutils.hpp"
#include "utils/ImguiWrap.hpp"

namespace ImGuiUtils {

Expand Down Expand Up @@ -260,7 +261,7 @@ class InputKeypad {
} guard;

ReturnState returnState = ReturnState::None;
if (ImGui::BeginChild("drawKeypad Input", ImVec2{}, true)) {
if (auto keypadInput = IMW::Child("drawKeypad Input", ImVec2{}, true)) {
const ImVec2 windowSize = ImGui::GetContentRegionAvail(); // now inside this child;

// setup number and function keypad -- global style settings
Expand All @@ -270,7 +271,6 @@ class InputKeypad {
ImGui::PopFont();
ImGui::PopStyleVar();

ImGui::EndChild();
returnState = processKeypadLogic(activatedKey);
}

Expand Down Expand Up @@ -992,22 +992,23 @@ float splitter(ImVec2 space, bool vertical, float size, float defaultRatio, bool
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + s - w - size / 2.f);
}

ImGui::BeginChild("##c");
ImGui::Button("##sep", vertical ? ImVec2{ size, space.y } : ImVec2{ space.x, size });
{
IMW::Child child("##c", ImVec2(0, 0), 0, 0);
ImGui::Button("##sep", vertical ? ImVec2{ size, space.y } : ImVec2{ space.x, size });

const auto cursor = vertical ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS;
if (ImGui::IsItemHovered()) {
ImGui::SetMouseCursor(cursor);
}
const auto cursor = vertical ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS;
if (ImGui::IsItemHovered()) {
ImGui::SetMouseCursor(cursor);
}

if (ImGui::IsItemActive()) {
ImGui::SetMouseCursor(cursor);
const auto delta = ImGui::GetMouseDragDelta();
splitter_state.ratio = startRatio - (vertical ? delta.x : delta.y) / s;
} else {
splitter_state.start_ratio = splitter_state.ratio;
if (ImGui::IsItemActive()) {
ImGui::SetMouseCursor(cursor);
const auto delta = ImGui::GetMouseDragDelta();
splitter_state.ratio = startRatio - (vertical ? delta.x : delta.y) / s;
} else {
splitter_state.start_ratio = splitter_state.ratio;
}
}
ImGui::EndChild();
return splitter_state.ratio;
}

Expand All @@ -1023,7 +1024,7 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im

ImGui::SetNextWindowPos(pos, ImGuiCond_Always);
ImGui::SetNextWindowSize(frameSize);
ImGui::Begin("BlockControlsPanel", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);
IMW::Window blockControlsPanel("BlockControlsPanel", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);

auto &app = App::instance();
ImGui::PushFont(app.fontIconsSolid);
Expand Down Expand Up @@ -1244,15 +1245,16 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
}
}

ImGui::BeginChild("Settings", verticalLayout ? ImVec2(size.x, ImGui::GetContentRegionAvail().y - lineHeight - itemSpacing.y) : ImVec2(ImGui::GetContentRegionAvail().x - lineHeight - itemSpacing.x, size.y), true,
ImGuiWindowFlags_HorizontalScrollbar);
ImGui::TextUnformatted(ctx.block->name.c_str());
ImGuiUtils::blockParametersControls(ctx.block, verticalLayout);
{
IMW::Child settings("Settings", verticalLayout ? ImVec2(size.x, ImGui::GetContentRegionAvail().y - lineHeight - itemSpacing.y) : ImVec2(ImGui::GetContentRegionAvail().x - lineHeight - itemSpacing.x, size.y), true,
ImGuiWindowFlags_HorizontalScrollbar);
ImGui::TextUnformatted(ctx.block->name.c_str());
ImGuiUtils::blockParametersControls(ctx.block, verticalLayout);

if (ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
resetTime();
if (ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
resetTime();
}
}
ImGui::EndChild();

ImGui::SetCursorPos(minpos);

Expand Down Expand Up @@ -1298,8 +1300,6 @@ void drawBlockControlsPanel(BlockControlsPanel &ctx, const ImVec2 &pos, const Im
ImGui::EndGroup();
}
ImGui::PopFont();

ImGui::End();
}

namespace {
Expand Down
Loading

0 comments on commit 7a651d0

Please sign in to comment.