Skip to content

Commit d25e043

Browse files
committed
Move node editor context menus to main imgui context to avoid scaling
1 parent 6792ff9 commit d25e043

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

tools/NodeEditor/FastNoiseNodeEditor.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ void FastNoiseNodeEditor::Node::GeneratePreview( bool nodeTreeChanged, bool benc
199199
genRGB->SetSource( scale );
200200
scale->SetSource( generator );
201201
scale->SetScaling( editor.mNodeScale );
202-
203-
FastNoise::SmartNode<FastNoise::ConvertRGBA8> l(nullptr);
204202

205203
auto startTime = std::chrono::high_resolution_clock::now();
206204

@@ -335,7 +333,7 @@ bool FastNoiseNodeEditor::MetadataMenuItem::CanDraw( std::function<bool( const F
335333

336334
const FastNoise::Metadata* FastNoiseNodeEditor::MetadataMenuItem::DrawUI( std::function<bool( const FastNoise::Metadata* )> isValid, bool drawGroups ) const
337335
{
338-
std::string format = FastNoise::Metadata::FormatMetadataNodeName( metadata, true );
336+
std::string format = FastNoise::Metadata::FormatMetadataNodeName( metadata, drawGroups );
339337

340338
if( ImGui::MenuItem( format.c_str() ) )
341339
{
@@ -589,6 +587,7 @@ void FastNoiseNodeEditor::SetupSettingsHandlers()
589587

590588
FastNoiseNodeEditor::FastNoiseNodeEditor( NodeEditorApp& nodeEditorApp ) :
591589
mNodeEditorApp( nodeEditorApp ),
590+
mMainContext( ImGui::GetCurrentContext() ),
592591
mOverheadNode( *this, new FastNoise::NodeData( &FastNoise::Metadata::Get<FastNoise::Constant>() ), false )
593592
{
594593
if( !mNodeEditorApp.IsDetachedNodeGraph() )
@@ -830,9 +829,10 @@ void FastNoiseNodeEditor::Draw( const Matrix4& transformation, const Matrix4& pr
830829
OpenStandaloneNodeGraph();
831830
}
832831

832+
ImGui::SetCurrentContext( mMainContext );
833833
DoHelp();
834-
835834
DoContextMenu();
835+
ImGui::SetCurrentContext( ImNodes::GetNodeEditorImGuiContext() );
836836

837837
DoNodes();
838838

@@ -1049,9 +1049,17 @@ void FastNoiseNodeEditor::DoNodes()
10491049

10501050
ImNodes::EndNodeTitleBar();
10511051

1052+
if( ImGui::IsMouseReleased( ImGuiMouseButton_Right ) && ImGui::IsItemHovered( ImGuiHoveredFlags_AllowWhenBlockedByPopup ) )
1053+
{
1054+
ImGui::SetCurrentContext( mMainContext );
1055+
ImGui::OpenPopup( "node_title" );
1056+
}
1057+
1058+
ImGui::SetCurrentContext( mMainContext );
10521059
// Right click node title to change node type
10531060
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 4, 4 ) );
1054-
if( ImGui::BeginPopupContextItem() )
1061+
1062+
if( ImGui::BeginPopup( "node_title" ) )
10551063
{
10561064
if( ImGui::MenuItem( "Copy Encoded Node Tree" ) )
10571065
{
@@ -1074,7 +1082,7 @@ void FastNoiseNodeEditor::DoNodes()
10741082
MatchingMembers( newMetadata->memberNodeLookups, nodeMetadata->memberNodeLookups ) &&
10751083
MatchingMembers( newMetadata->memberHybrids, nodeMetadata->memberHybrids ) )
10761084
{
1077-
nodeMetadata = newMetadata;
1085+
nodeMetadata = newMetadata;
10781086
}
10791087
else
10801088
{
@@ -1104,7 +1112,7 @@ void FastNoiseNodeEditor::DoNodes()
11041112
links.pop();
11051113
}
11061114

1107-
*node.second.data = std::move( newData );
1115+
*node.second.data = std::move( newData );
11081116
}
11091117

11101118
node.second.GeneratePreview();
@@ -1114,6 +1122,8 @@ void FastNoiseNodeEditor::DoNodes()
11141122
}
11151123
ImGui::PopStyleVar();
11161124

1125+
ImGui::SetCurrentContext( ImNodes::GetNodeEditorImGuiContext() );
1126+
11171127
ImGui::PushItemWidth( 90.0f );
11181128

11191129
ImNodes::PushAttributeFlag( ImNodesAttributeFlags_EnableLinkCreationOnSnap );
@@ -1286,7 +1296,7 @@ void FastNoiseNodeEditor::DoHelp()
12861296
ImGui::Text( " Help" );
12871297
if( ImGui::IsItemHovered() )
12881298
{
1289-
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 4.f, 4.f ) );
1299+
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 6.f, 6.f ) );
12901300
ImGui::BeginTooltip();
12911301
constexpr float alignPx = 110;
12921302

tools/NodeEditor/FastNoiseNodeEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ namespace Magnum
126126
void UpdateSelected();
127127

128128
NodeEditorApp& mNodeEditorApp;
129+
ImGuiContext* mMainContext;
129130

130131
std::unordered_map<FastNoise::NodeData*, Node> mNodes;
131132
FastNoise::NodeData* mDroppedLinkNode = nullptr;

0 commit comments

Comments
 (0)