Skip to content

Commit

Permalink
StandardNodule : Respect visibility metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Nov 20, 2024
1 parent 4681390 commit 512ff3e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
6 changes: 5 additions & 1 deletion include/GafferUI/StandardNodeGadget.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace GafferUI
class PlugAdder;
class NoduleLayout;
class ConnectionCreator;
class StandardNodule;

/// The standard means of representing a Node in a GraphGadget.
/// Nodes are represented as rectangular boxes with the name displayed
Expand Down Expand Up @@ -164,7 +165,10 @@ class GAFFERUI_API StandardNodeGadget : public NodeGadget
bool updateShape();
void updateFocusGadgetVisibility();
void updateTextDimming();
void applyNoduleLabelVisibilityMetadat();

friend class StandardNodule;
// Set the visibility for all nodules based on the metadata registered for this node.
void applyNoduleLabelVisibilityMetadata();

IE_CORE_FORWARDDECLARE( ErrorGadget );
ErrorGadget *errorGadget( bool createIfMissing = true );
Expand Down
4 changes: 4 additions & 0 deletions include/GafferUI/StandardNodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ class GAFFERUI_API StandardNodule : public Nodule
bool dragEnd( GadgetPtr gadget, const DragDropEvent &event );
bool drop( GadgetPtr gadget, const DragDropEvent &event );

/// \deprecated Use overloaded method without `visible` when setting `visible = true`
/// or `StandardNodeGadget::applyNoduleLabelVisibilityMetadata()` to restore
/// metadata-aware visibility.
void setCompatibleLabelsVisible( const DragDropEvent &event, bool visible );
void setCompatibleLabelsVisible( const DragDropEvent &event );

private :

Expand Down
58 changes: 53 additions & 5 deletions src/GafferUI/StandardNodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ bool StandardNodule::dragEnter( GadgetPtr gadget, const DragDropEvent &event )
Nodule *prevDestination = IECore::runTimeCast<Nodule>( event.destinationGadget.get() );
if( !prevDestination || prevDestination->plug()->node() != plug()->node() )
{
setCompatibleLabelsVisible( event, true );
setCompatibleLabelsVisible( event );
}

dirty( DirtyType::Render );
Expand Down Expand Up @@ -397,19 +397,40 @@ bool StandardNodule::dragLeave( GadgetPtr gadget, const DragDropEvent &event )
{
if( newDestination->plug()->node() != plug()->node() )
{
setCompatibleLabelsVisible( event, false );
if( auto nodeGadget = ancestor<StandardNodeGadget>() )
{
nodeGadget->applyNoduleLabelVisibilityMetadata();
}
else
{
setCompatibleLabelsVisible( event, false );
}
}
}
else if( NodeGadget *newDestination = IECore::runTimeCast<NodeGadget>( event.destinationGadget.get() ) )
{
if( newDestination->node() != plug()->node() )
{
setCompatibleLabelsVisible( event, false );
if( auto nodeGadget = ancestor<StandardNodeGadget>() )
{
nodeGadget->applyNoduleLabelVisibilityMetadata();
}
else
{
setCompatibleLabelsVisible( event, false );
}
}
}
else
{
setCompatibleLabelsVisible( event, false );
if( auto nodeGadget = ancestor<StandardNodeGadget>() )
{
nodeGadget->applyNoduleLabelVisibilityMetadata();
}
else
{
setCompatibleLabelsVisible( event, false );
}
}
dirty( DirtyType::Render );
}
Expand All @@ -434,7 +455,14 @@ bool StandardNodule::dragEnd( GadgetPtr gadget, const DragDropEvent &event )
bool StandardNodule::drop( GadgetPtr gadget, const DragDropEvent &event )
{
setHighlighted( false );
setCompatibleLabelsVisible( event, false );
if( auto nodeGadget = ancestor<StandardNodeGadget>() )
{
nodeGadget->applyNoduleLabelVisibilityMetadata();
}
else
{
setCompatibleLabelsVisible( event, false );
}

if( ConnectionCreator *creator = IECore::runTimeCast<ConnectionCreator>( event.sourceGadget.get() ) )
{
Expand Down Expand Up @@ -474,6 +502,26 @@ void StandardNodule::setCompatibleLabelsVisible( const DragDropEvent &event, boo
}
}

void StandardNodule::setCompatibleLabelsVisible( const DragDropEvent &event )
{
NodeGadget *nodeGadget = ancestor<NodeGadget>();
if( !nodeGadget )
{
return;
}

ConnectionCreator *creator = IECore::runTimeCast<ConnectionCreator>( event.sourceGadget.get() );
if( !creator )
{
return;
}

for( StandardNodule::RecursiveIterator it( nodeGadget ); !it.done(); ++it )
{
(*it)->setLabelVisible( creator->canCreateConnection( it->get()->plug() ) ? true : false );
}
}

void StandardNodule::plugMetadataChanged( const Gaffer::Plug *plug, IECore::InternedString key )
{
if( plug != this->plug() )
Expand Down

0 comments on commit 512ff3e

Please sign in to comment.