@@ -11,10 +11,8 @@ namespace Xamarin.PropertyEditing.Mac
1111{
1212 internal class ColorComponentEditor : ColorEditorView
1313 {
14- private const int DefaultPropertyButtonSize = 10 ;
15- private const int DefaultActioButtonSize = 16 ;
16- private const int DefaultControlHeight = 22 ;
17- private const int DefaultGradientHeight = 4 ;
14+ private const int DefaultControlHeight = 18 ;
15+ private const int DefaultGradientHeight = 3 ;
1816
1917 private ChannelEditorType EditorType { get ; }
2018
@@ -122,6 +120,8 @@ private void Initialize (IHostResourceProvider hostResources)
122120
123121 this . hexEditor = new NSTextField {
124122 Alignment = NSTextAlignment . Right ,
123+ ControlSize = NSControlSize . Small ,
124+ Font = NSFont . SystemFontOfSize ( NSFont . SystemFontSizeForControlSize ( NSControlSize . Small ) )
125125 } ;
126126 AddSubview ( this . hexEditor ) ;
127127
@@ -234,29 +234,42 @@ public override void Layout ()
234234 if ( Frame . IsEmpty || Frame . IsInfinite ( ) || double . IsNaN ( Frame . X ) || double . IsInfinity ( Frame . X ) )
235235 return ;
236236
237- var frame = Bounds . Inset ( Padding , Padding ) ;
238- var labelFrame = new CGRect ( frame . X , frame . Height - DefaultControlHeight , 20 , DefaultControlHeight ) ;
237+ nfloat maxLabelWidth = this . hexLabel . Cell . CellSizeForBounds ( Frame ) . Width ;
238+ for ( int i = 0 ; i < Editors . Length ; i ++ ) {
239+ CGSize size = Editors [ i ] . Label . Cell . CellSizeForBounds ( Frame ) ;
240+ if ( size . Width > maxLabelWidth )
241+ maxLabelWidth = size . Width ;
242+ }
243+
244+ maxLabelWidth = ( nfloat ) Math . Ceiling ( maxLabelWidth ) ;
245+
246+ var frame = Bounds ;
247+ var labelFrame = new CGRect ( frame . X , frame . Height - DefaultControlHeight , maxLabelWidth , DefaultControlHeight ) ;
239248 var editorFrame = new CGRect ( labelFrame . Right , labelFrame . Y , frame . Width - labelFrame . Right , DefaultControlHeight ) ;
240249 var yOffset = DefaultControlHeight + DefaultGradientHeight + 3 ;
241250
242- foreach ( var channelGroup in Editors ) {
251+ for ( int i = 0 ; i < Editors . Length ; i ++ ) {
252+ var channelGroup = Editors [ i ] ;
253+
243254 channelGroup . Label . Frame = labelFrame ;
244255 channelGroup . Editor . Frame = editorFrame ;
256+ channelGroup . Editor . Layout ( ) ;
257+
245258 channelGroup . Gradient . Frame = new CGRect (
246259 editorFrame . X + .5f ,
247260 editorFrame . Y - DefaultGradientHeight + 1 ,
248- editorFrame . Width - 15 , DefaultGradientHeight ) ;
261+ channelGroup . Editor . Subviews [ 0 ] . Frame . Width - 1f , DefaultGradientHeight ) ;
249262
250263 channelGroup . Gradient . BorderColor = NSColor . DisabledControlText . CGColor ;
251264 channelGroup . Gradient . ContentsScale = Window ? . Screen ? . BackingScaleFactor ?? NSScreen . MainScreen . BackingScaleFactor ;
252265 labelFrame = labelFrame . Translate ( 0 , - yOffset ) ;
253266 editorFrame = editorFrame . Translate ( 0 , - yOffset ) ;
254267 }
255268
256- this . hexLabel . Frame = new CGRect ( frame . X , Padding , 20 , DefaultControlHeight ) ;
269+ this . hexLabel . Frame = new CGRect ( frame . X , 0 , maxLabelWidth , DefaultControlHeight ) ;
257270 this . hexEditor . Frame = new CGRect (
258271 labelFrame . Right ,
259- Padding ,
272+ 0 ,
260273 frame . Width - labelFrame . Right - 16 ,
261274 DefaultControlHeight ) ;
262275 }
0 commit comments