Skip to content

Commit

Permalink
ColorChooser : Spacers between triplets
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Sep 24, 2024
1 parent ce2d8fd commit 6aa17ea
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions python/GafferUI/ColorChooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ def __init__( self, color=imath.Color3f( 1 ), **kw ) :
self.__sliders = {}
self.__numericWidgets = {}
self.__channelLabels = {}
self.__spacers = {}
self.__componentValueChangedConnections = []

with self.__column :
Expand All @@ -504,7 +505,8 @@ def __init__( self, color=imath.Color3f( 1 ), **kw ) :

# sliders and numeric widgets
c, staticComponent = self.__colorField.getColor()
for row, component in enumerate( "rgbahsvtmi" ) :
for component in "rgbahsvtmi" :
row = { "r" : 0, "g" : 1, "b" : 2, "a" : 4, "h" : 6, "s" : 7, "v" : 8, "t" : 10, "m" : 11, "i" : 12 }[component]
self.__channelLabels[component] = GafferUI.Label( component.capitalize(), parenting = { "index" : ( 0, row ), "alignment" : ( GafferUI.HorizontalAlignment.Center, GafferUI.VerticalAlignment.Center ) } )
self.__channelLabels[component]._qtWidget().setObjectName( "gafferColorComponentLabel" )
self.__channelLabels[component]._qtWidget().setFixedSize( 27, 22 )
Expand All @@ -531,6 +533,11 @@ def __init__( self, color=imath.Color3f( 1 ), **kw ) :
)
)

spacerHeight = 4
self.__spacers["a"] = GafferUI.Spacer( imath.V2i( 0, spacerHeight ), parenting = { "index" : ( 0, 3 ) } )
self.__spacers["hsv"] = GafferUI.Spacer( imath.V2i( 0, spacerHeight ), parenting = { "index" : ( 0, 5 ) } )
self.__spacers["tmi"] = GafferUI.Spacer( imath.V2i( 0, spacerHeight ), parenting = { "index" : ( 0, 9 ) } )

numericWidget = GafferUI.NumericWidget( 0.0, parenting = { "index" : ( 1, row ) } )

numericWidget.setFixedCharacterWidth( 6 )
Expand Down Expand Up @@ -894,13 +901,9 @@ def __updateUIFromColor( self ) :
self.__sliders["a"].setValue( c[3] )
self.__numericWidgets["a"].setValue( c[3] )

self.__sliders["a"].setVisible( True )
self.__numericWidgets["a"].setVisible( True )
self.__channelLabels["a"].setVisible( True )
self.__setComponentVisible( "a", True )
else :
self.__sliders["a"].setVisible( False )
self.__numericWidgets["a"].setVisible( False )
self.__channelLabels["a"].setVisible( False )
self.__setComponentVisible( "a", False )

for slider in [ v for k, v in self.__sliders.items() if k in "hsv" ] :
slider.setColor( self.__colorHSV )
Expand Down Expand Up @@ -1001,6 +1004,19 @@ def __labelLeave( self, widget, component ) :

self.__channelLabels[component]._repolish()

def __setComponentVisible( self, component, visible ) :

self.__channelLabels[component].setVisible( visible )
self.__numericWidgets[component].setVisible( visible )
self.__sliders[component].setVisible( visible )

if component == "a" :
self.__spacers["a"].setVisible( visible and any( self.__channelLabels[c].getVisible() for c in "rgb" ) )
elif component in "hsv" :
self.__spacers["hsv"].setVisible( visible and any( self.__channelLabels[c].getVisible() for c in "rgba" ) )
elif component in "tmi" :
self.__spacers["tmi"].setVisible( visible and any( self.__channelLabels[c].getVisible() for c in "rgbahsv" ) )

def __setVisibleComponentsInternal( self, components ) :

componentsSet = set( components )
Expand All @@ -1014,10 +1030,7 @@ def __setVisibleComponentsInternal( self, components ) :
return

for c in self.__sliders.keys() :
visible = c in componentsSet
self.__channelLabels[c].setVisible( visible )
self.__numericWidgets[c].setVisible( visible )
self.__sliders[c].setVisible( visible )
self.__setComponentVisible( c, c in componentsSet )

self.__visibleComponentsChangedSignal( self )

Expand Down

0 comments on commit 6aa17ea

Please sign in to comment.