Resolved an issue where node width expanded infinitely during window dragging across multi‑display screens with different scaling factors.This problem was caused by inaccurate width calculation of placeholder elements.The width calculation for nodes now uses an adaptive approach.
This commit is contained in:
parent
fa4e79dc86
commit
f9f10209ca
@ -190,6 +190,9 @@ public:
|
|||||||
// 接口测试节点
|
// 接口测试节点
|
||||||
class Connector_Test_Node : public Abs_Node
|
class Connector_Test_Node : public Abs_Node
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
float node_width = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 显式禁用默认构造
|
// 显式禁用默认构造
|
||||||
Connector_Test_Node() = delete;
|
Connector_Test_Node() = delete;
|
||||||
@ -209,6 +212,9 @@ public:
|
|||||||
// DLT信息输入类,起始点
|
// DLT信息输入类,起始点
|
||||||
class MSG_Input_Node : public Abs_Node
|
class MSG_Input_Node : public Abs_Node
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
float node_width = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 显式禁用默认构造
|
// 显式禁用默认构造
|
||||||
MSG_Input_Node() = delete;
|
MSG_Input_Node() = delete;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "Nodes_And_Connectors.hpp"
|
#include "Nodes_And_Connectors.hpp"
|
||||||
|
#include "Json_Utilities.hpp"
|
||||||
#include "imgui_internal.h"
|
#include "imgui_internal.h"
|
||||||
|
|
||||||
// 客制化圆形带X按钮
|
// 客制化圆形带X按钮
|
||||||
@ -334,7 +335,7 @@ Connector_Test_Node::Connector_Test_Node(Independent_ID_Generator *Node_ID_Gener
|
|||||||
|
|
||||||
// CSV 相关接口
|
// CSV 相关接口
|
||||||
this->Connector_List.push_back(std::make_shared<CSV_Column_Input_Connector>(Connector_ID_Generator)); // [2] -> Column
|
this->Connector_List.push_back(std::make_shared<CSV_Column_Input_Connector>(Connector_ID_Generator)); // [2] -> Column
|
||||||
this->Connector_List.push_back(std::make_shared<CSV_Column_Output_Connector>(Connector_ID_Generator)); // [3] -> Column
|
this->Connector_List.push_back(std::make_shared<CSV_Column_Output_Connector>(Connector_ID_Generator)); // [3] Column ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,14 +353,21 @@ void Connector_Test_Node::Show(void)
|
|||||||
this->initial_position = ImVec2(0, 0);
|
this->initial_position = ImVec2(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 全宽适配
|
||||||
|
bool all_width_fit = true;
|
||||||
|
|
||||||
// 绘制节点
|
// 绘制节点
|
||||||
ImNodes::BeginNode(this->id);
|
ImNodes::BeginNode(this->id);
|
||||||
{
|
{
|
||||||
|
// 获取节点当前长宽维度
|
||||||
|
ImVec2 dimension = ImNodes::GetNodeDimensions(this->id);
|
||||||
|
|
||||||
// 标题部分
|
// 标题部分
|
||||||
ImNodes::BeginNodeTitleBar();
|
ImNodes::BeginNodeTitleBar();
|
||||||
{
|
{
|
||||||
ImGui::Text(u8"接口测试用节点");
|
const char *title_str = u8"接口测试用节点";
|
||||||
|
|
||||||
|
ImGui::Text(title_str);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
{
|
{
|
||||||
ImGui::TextDisabled(u8"(?)");
|
ImGui::TextDisabled(u8"(?)");
|
||||||
@ -379,49 +387,71 @@ void Connector_Test_Node::Show(void)
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
// 节点宽度调整
|
// 节点宽度调整
|
||||||
ImGui::Dummy(ImVec2(120.0f, 0.0f));
|
auto button_diameter = ImGui::GetTextLineHeight();
|
||||||
|
auto text_width = ImGui::CalcTextSize(title_str).x + ImGui::CalcTextSize(u8"(?)").x;
|
||||||
|
auto Tittle_Str_Width = text_width + ImNodes::GetStyle().NodePadding.x * 2 + ImGui::GetStyle().ItemSpacing.x * 2;
|
||||||
|
|
||||||
|
// 宽度判定
|
||||||
|
if (dimension.x < Tittle_Str_Width + button_diameter + ImGui::GetStyle().ItemSpacing.x)
|
||||||
|
all_width_fit = false;
|
||||||
|
|
||||||
|
ImGui::Dummy(ImVec2(this->node_width - Tittle_Str_Width - button_diameter - ImGui::GetStyle().ItemSpacing.x, 0.0f));
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
// 绘制关闭按钮
|
// 绘制关闭按钮
|
||||||
if (CircleButtonWithX("#X", ImGui::GetTextLineHeight() / 2))
|
if (CircleButtonWithX("#X", ImGui::GetTextLineHeight() / 2))
|
||||||
this->close_flag = true;
|
this->close_flag = true;
|
||||||
}
|
}
|
||||||
ImNodes::EndNodeTitleBar();
|
ImNodes::EndNodeTitleBar();
|
||||||
|
|
||||||
// 绘制DLT相关接口组
|
// 节点主体绘制
|
||||||
{
|
{
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, ImGui::GetStyle().ItemSpacing.y));
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, ImGui::GetStyle().ItemSpacing.y));
|
||||||
|
|
||||||
this->Connector_List[0]->Show();
|
// 绘制DLT相关接口组
|
||||||
ImGui::SameLine();
|
{
|
||||||
ImGui::Text("-> DLT-In");
|
// 宽度判定
|
||||||
ImGui::SameLine();
|
auto text_width = ImGui::CalcTextSize("-> DLT-In").x + ImGui::CalcTextSize("DLT-Out ->").x;
|
||||||
ImGui::Dummy(ImVec2(ImNodes::GetNodeDimensions(this->id).x - ImGui::CalcTextSize("-> DLT-In").x - ImGui::CalcTextSize("DLT-Out ->").x - (ImNodes::GetStyle().NodePadding.x + ImGui::GetStyle().ItemSpacing.x) * 2, 0.0f));
|
if (dimension.x < text_width + ImNodes::GetStyle().NodePadding.x * 2)
|
||||||
ImGui::SameLine();
|
all_width_fit = false;
|
||||||
ImGui::Text("DLT-Out ->");
|
|
||||||
ImGui::SameLine();
|
this->Connector_List[0]->Show();
|
||||||
this->Connector_List[1]->Show();
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("-> DLT-In");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Dummy(ImVec2(this->node_width - text_width - ImNodes::GetStyle().NodePadding.x * 2, 0.0f));
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("DLT-Out ->");
|
||||||
|
ImGui::SameLine();
|
||||||
|
this->Connector_List[1]->Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绘制CSV列相关接口组
|
||||||
|
{
|
||||||
|
// 宽度判定
|
||||||
|
auto text_width = ImGui::CalcTextSize("-> CSV-Column-In").x + ImGui::CalcTextSize("CSV-Column-Out ->").x;
|
||||||
|
if (dimension.x < text_width + ImNodes::GetStyle().NodePadding.x * 2 + ImGui::CalcTextSize("A").x)
|
||||||
|
all_width_fit = false;
|
||||||
|
if (this->node_width == 0)
|
||||||
|
this->node_width = text_width + ImNodes::GetStyle().NodePadding.x * 2 + ImGui::CalcTextSize("A").x;
|
||||||
|
|
||||||
|
this->Connector_List[2]->Show();
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("-> CSV-Column-In");
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Dummy(ImVec2(this->node_width - text_width - ImNodes::GetStyle().NodePadding.x * 2, 0.0f));
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("CSV-Column-Out ->");
|
||||||
|
ImGui::SameLine();
|
||||||
|
this->Connector_List[3]->Show();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制CSV列相关接口组
|
// 使用递进的方式自适应宽度
|
||||||
{
|
if (all_width_fit == false)
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, ImGui::GetStyle().ItemSpacing.y));
|
this->node_width += 1.0f;
|
||||||
|
|
||||||
this->Connector_List[2]->Show();
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Text("-> CSV-Column-In");
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Dummy(ImVec2(ImNodes::GetNodeDimensions(this->id).x - ImGui::CalcTextSize("-> CSV-Column-In").x - ImGui::CalcTextSize("CSV-Column-Out ->").x - (ImNodes::GetStyle().NodePadding.x + ImGui::GetStyle().ItemSpacing.x) * 2, 0.0f));
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Text("CSV-Column-Out ->");
|
|
||||||
ImGui::SameLine();
|
|
||||||
this->Connector_List[3]->Show();
|
|
||||||
|
|
||||||
ImGui::PopStyleVar();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ImNodes::EndNode();
|
ImNodes::EndNode();
|
||||||
}
|
}
|
||||||
@ -446,17 +476,12 @@ MSG_Input_Node::MSG_Input_Node(Independent_ID_Generator *Node_ID_Generator,
|
|||||||
{
|
{
|
||||||
// 消息输出节点
|
// 消息输出节点
|
||||||
this->Connector_List.push_back(std::make_shared<MSG_OutPut_Connector>(Connector_ID_Generator));
|
this->Connector_List.push_back(std::make_shared<MSG_OutPut_Connector>(Connector_ID_Generator));
|
||||||
this->Connector_List.push_back(std::make_shared<MSG_InPut_Connector>(Connector_ID_Generator));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制节点
|
// 绘制节点
|
||||||
void MSG_Input_Node::Show(void)
|
void MSG_Input_Node::Show(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
// auto ImNodesStyle = ImNodes::GetStyle();
|
|
||||||
// auto ImGuiStyle = ImGui::GetStyle();
|
|
||||||
|
|
||||||
if (this->close_flag == true)
|
if (this->close_flag == true)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -467,6 +492,9 @@ void MSG_Input_Node::Show(void)
|
|||||||
this->initial_position = ImVec2(0, 0);
|
this->initial_position = ImVec2(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 全宽适配
|
||||||
|
bool all_width_fit = true;
|
||||||
|
|
||||||
// 绘制节点
|
// 绘制节点
|
||||||
ImNodes::BeginNode(this->id);
|
ImNodes::BeginNode(this->id);
|
||||||
{
|
{
|
||||||
@ -474,7 +502,9 @@ void MSG_Input_Node::Show(void)
|
|||||||
// 标题部分
|
// 标题部分
|
||||||
ImNodes::BeginNodeTitleBar();
|
ImNodes::BeginNodeTitleBar();
|
||||||
{
|
{
|
||||||
ImGui::Text(u8"DLT-信息输入节点");
|
const char *title_str = u8"DLT-信息输入节点";
|
||||||
|
|
||||||
|
ImGui::Text(title_str);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
{
|
{
|
||||||
ImGui::TextDisabled(u8"(?)");
|
ImGui::TextDisabled(u8"(?)");
|
||||||
@ -492,43 +522,53 @@ void MSG_Input_Node::Show(void)
|
|||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
// ImGui::Dummy(ImVec2(node_width - ImGui::CalcTextSize(u8"DLT-信息输入节点").x - ImGui::GetTextLineHeight(), 0.0f));
|
|
||||||
|
|
||||||
// 节点宽度调整
|
// 节点宽度调整
|
||||||
ImGui::Dummy(ImVec2(20.0f, 0.0f));
|
ImVec2 dimension = ImNodes::GetNodeDimensions(this->id);
|
||||||
|
auto button_diameter = ImGui::GetTextLineHeight();
|
||||||
|
auto text_width = ImGui::CalcTextSize(title_str).x + ImGui::CalcTextSize(u8"(?)").x;
|
||||||
|
auto Tittle_Str_Width = text_width + ImNodes::GetStyle().NodePadding.x * 2 + ImGui::GetStyle().ItemSpacing.x * 2;
|
||||||
|
|
||||||
|
if (this->node_width == 0)
|
||||||
|
this->node_width = Tittle_Str_Width + button_diameter + ImGui::GetStyle().ItemSpacing.x;
|
||||||
|
|
||||||
|
if (dimension.x < Tittle_Str_Width + button_diameter + ImGui::GetStyle().ItemSpacing.x)
|
||||||
|
all_width_fit = false;
|
||||||
|
|
||||||
|
ImGui::Dummy(ImVec2(this->node_width - Tittle_Str_Width - button_diameter - ImGui::GetStyle().ItemSpacing.x, 0.0f));
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
// 绘制关闭按钮
|
// 绘制关闭按钮
|
||||||
if (CircleButtonWithX("#X", ImGui::GetTextLineHeight() / 2))
|
if (CircleButtonWithX("#X", button_diameter / 2))
|
||||||
this->close_flag = true;
|
this->close_flag = true;
|
||||||
}
|
}
|
||||||
ImNodes::EndNodeTitleBar();
|
ImNodes::EndNodeTitleBar();
|
||||||
|
|
||||||
// 节点主体部分
|
// 节点主体部分
|
||||||
{
|
{
|
||||||
}
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, ImGui::GetStyle().ItemSpacing.y));
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, ImGui::GetStyle().ItemSpacing.y));
|
// 靠右占位
|
||||||
|
ImVec2 dimension = ImNodes::GetNodeDimensions(this->id);
|
||||||
|
auto text_width = ImGui::CalcTextSize(u8"DLT-Out ->").x;
|
||||||
|
|
||||||
ImVec2 dimension = ImNodes::GetNodeDimensions(this->id);
|
if (dimension.x < text_width + ImNodes::GetStyle().NodePadding.x * 2)
|
||||||
ImVec2 text_size = ImGui::CalcTextSize(u8"OUT ->");
|
all_width_fit = false;
|
||||||
if (dimension.x > text_size.x)
|
|
||||||
{
|
ImGui::Dummy(ImVec2(this->node_width - text_width - ImNodes::GetStyle().NodePadding.x * 2, 0.0f));
|
||||||
ImGui::Dummy(ImVec2(dimension.x - text_size.x - (ImNodes::GetStyle().NodePadding.x + ImGui::GetStyle().ItemSpacing.x) * 2, 0.0f));
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
}
|
|
||||||
ImGui::Text(u8"OUT ->");
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
/**
|
// 绘制DLT输出接口
|
||||||
* @todo 自定义接口绘制
|
ImGui::Text(u8"DLT-Out ->");
|
||||||
*/
|
ImGui::SameLine();
|
||||||
for (auto Connector : this->Connector_List)
|
this->Connector_List[0]->Show();
|
||||||
{
|
|
||||||
Connector->Show();
|
ImGui::PopStyleVar();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PopStyleVar();
|
// 使用递进的方式自适应宽度
|
||||||
|
if (all_width_fit == false)
|
||||||
|
this->node_width += 1.0f;
|
||||||
}
|
}
|
||||||
ImNodes::EndNode();
|
ImNodes::EndNode();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user