From 2edd7a366a0050d5e27cbb69fccbc6be70157839 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Thu, 29 Jan 2026 22:22:47 -0700 Subject: [PATCH] Colors and rearrange --- gui/WarpGraphModel.cpp | 60 +++++++++++++++++++++++++++-------- gui/WarpGraphModel.h | 10 +++++- include/warppipe/warppipe.hpp | 1 + src/warppipe.cpp | 1 + 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/gui/WarpGraphModel.cpp b/gui/WarpGraphModel.cpp index e976502..8677220 100644 --- a/gui/WarpGraphModel.cpp +++ b/gui/WarpGraphModel.cpp @@ -134,10 +134,7 @@ QVariant WarpGraphModel::nodeData(QtNodes::NodeId nodeId, if (sizeIt != m_sizes.end()) { return sizeIt->second; } - int maxPorts = static_cast( - std::max(data.inputPorts.size(), data.outputPorts.size())); - int height = std::max(80, 50 + maxPorts * 28); - return QSize(200, height); + return estimateNodeSize(data); } case QtNodes::NodeRole::InPortCount: return static_cast(data.inputPorts.size()); @@ -354,9 +351,9 @@ void WarpGraphModel::refreshFromClient() { data.inputPorts = std::move(inputs); data.outputPorts = std::move(outputs); - m_nodes.emplace(qtId, std::move(data)); + auto [nodeIt, _] = m_nodes.emplace(qtId, std::move(data)); m_pwToQt.emplace(nodeInfo.id.value, qtId); - m_positions.emplace(qtId, nextPosition()); + m_positions.emplace(qtId, nextPosition(nodeIt->second)); Q_EMIT nodeCreated(qtId); } @@ -473,17 +470,50 @@ QtNodes::NodeId WarpGraphModel::qtNodeIdForPw(uint32_t pwNodeId) const { } QString WarpGraphModel::captionForNode(const warppipe::NodeInfo &info) { + if (!info.description.empty()) { + return QString::fromStdString(info.description); + } if (!info.application_name.empty() && info.application_name != info.name) { return QString::fromStdString(info.application_name); } return QString::fromStdString(info.name); } -QPointF WarpGraphModel::nextPosition() const { - int count = static_cast(m_nodes.size()); - double x = (count % 4) * 280.0; - double y = (count / 4) * 200.0; - return QPointF(x, y); +QSize WarpGraphModel::estimateNodeSize(const WarpNodeData &data) { + int maxPorts = static_cast( + std::max(data.inputPorts.size(), data.outputPorts.size())); + int height = std::max(80, 50 + maxPorts * 28); + + QString caption = captionForNode(data.info); + int captionWidth = caption.length() * 8 + 40; + + int maxInputLen = 0; + int maxOutputLen = 0; + for (const auto &p : data.inputPorts) + maxInputLen = std::max(maxInputLen, static_cast(p.name.length())); + for (const auto &p : data.outputPorts) + maxOutputLen = std::max(maxOutputLen, static_cast(p.name.length())); + int portWidth = (maxInputLen + maxOutputLen) * 7 + 60; + + int width = std::max(180, std::max(captionWidth, portWidth)); + return QSize(width, height); +} + +QPointF WarpGraphModel::nextPosition(const WarpNodeData &data) { + QSize size = estimateNodeSize(data); + double nodeW = size.width(); + double nodeH = size.height(); + + if (m_nextX + nodeW > kMaxRowWidth && m_nextX > 0) { + m_nextX = 0.0; + m_nextY += m_rowMaxHeight + kVerticalGap; + m_rowMaxHeight = 0.0; + } + + QPointF pos(m_nextX, m_nextY); + m_nextX += nodeW + kHorizontalGap; + m_rowMaxHeight = std::max(m_rowMaxHeight, nodeH); + return pos; } bool WarpGraphModel::isGhost(QtNodes::NodeId nodeId) const { @@ -516,13 +546,17 @@ QVariant WarpGraphModel::styleForNode(WarpNodeType type, bool ghost) { QColor base; switch (type) { case WarpNodeType::kHardwareSink: - case WarpNodeType::kHardwareSource: base = QColor(72, 94, 118); break; + case WarpNodeType::kHardwareSource: + base = QColor(94, 72, 118); + break; case WarpNodeType::kVirtualSink: - case WarpNodeType::kVirtualSource: base = QColor(62, 122, 104); break; + case WarpNodeType::kVirtualSource: + base = QColor(62, 104, 122); + break; case WarpNodeType::kApplication: base = QColor(138, 104, 72); break; diff --git a/gui/WarpGraphModel.h b/gui/WarpGraphModel.h index 4615f45..0578ffc 100644 --- a/gui/WarpGraphModel.h +++ b/gui/WarpGraphModel.h @@ -69,7 +69,8 @@ private: static QString captionForNode(const warppipe::NodeInfo &info); static WarpNodeType classifyNode(const warppipe::NodeInfo &info); static QVariant styleForNode(WarpNodeType type, bool ghost); - QPointF nextPosition() const; + QPointF nextPosition(const WarpNodeData &data); + static QSize estimateNodeSize(const WarpNodeData &data); warppipe::Client *m_client = nullptr; QtNodes::NodeId m_nextNodeId = 1; @@ -83,4 +84,11 @@ private: std::unordered_map m_positions; std::unordered_map m_sizes; std::unordered_set m_ghostNodes; + + static constexpr double kHorizontalGap = 40.0; + static constexpr double kVerticalGap = 30.0; + static constexpr double kMaxRowWidth = 1400.0; + double m_nextX = 0.0; + double m_nextY = 0.0; + double m_rowMaxHeight = 0.0; }; diff --git a/include/warppipe/warppipe.hpp b/include/warppipe/warppipe.hpp index b80b276..33c7adf 100644 --- a/include/warppipe/warppipe.hpp +++ b/include/warppipe/warppipe.hpp @@ -89,6 +89,7 @@ struct RuleId { struct NodeInfo { NodeId id; std::string name; + std::string description; std::string media_class; std::string application_name; std::string process_binary; diff --git a/src/warppipe.cpp b/src/warppipe.cpp index 3bd8999..e75f4eb 100644 --- a/src/warppipe.cpp +++ b/src/warppipe.cpp @@ -334,6 +334,7 @@ void Client::Impl::RegistryGlobal(void* data, NodeInfo info; info.id = NodeId{id}; info.name = LookupString(props, PW_KEY_NODE_NAME); + info.description = LookupString(props, PW_KEY_NODE_DESCRIPTION); info.media_class = LookupString(props, PW_KEY_MEDIA_CLASS); info.application_name = LookupString(props, PW_KEY_APP_NAME); info.process_binary = LookupString(props, PW_KEY_APP_PROCESS_BINARY);