Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit fa75209

Browse files
author
Eric Maupin
committed
[mac] Redo layout on solid brush editor
This better matches the layout and allowss the lefthand side to scale down whereas it was previously a fixed size that didn't work well inline.
1 parent 209bd74 commit fa75209

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ 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);
237+
var frame = Bounds.Inset (Padding, Padding);
238238
var labelFrame = new CGRect (frame.X, frame.Height - DefaultControlHeight, 20, DefaultControlHeight);
239239
var editorFrame = new CGRect (labelFrame.Right, labelFrame.Y, frame.Width - labelFrame.Right, DefaultControlHeight);
240240
var yOffset = DefaultControlHeight + DefaultGradientHeight + 3;
@@ -253,10 +253,10 @@ public override void Layout ()
253253
editorFrame = editorFrame.Translate (0, -yOffset);
254254
}
255255

256-
this.hexLabel.Frame = new CGRect (frame.X, padding, 20, DefaultControlHeight);
256+
this.hexLabel.Frame = new CGRect (frame.X, Padding, 20, DefaultControlHeight);
257257
this.hexEditor.Frame = new CGRect (
258258
labelFrame.Right,
259-
padding,
259+
Padding,
260260
frame.Width - labelFrame.Right - 16,
261261
DefaultControlHeight);
262262
}

Xamarin.PropertyEditing.Mac/Controls/Custom/ColorEditorView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public virtual void OnPropertyChanged (object sender, PropertyChangedEventArgs e
4747

4848
internal abstract class ColorEditorView : NotifyingView<SolidBrushViewModel>
4949
{
50-
protected const float padding = 3;
50+
protected const float Padding = 3;
5151

5252
public ColorEditorView (IntPtr handle) : base (handle)
5353
{

Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
22
using System.ComponentModel;
33
using System.Linq;
4-
using System.Runtime.CompilerServices;
4+
55
using AppKit;
66
using CoreAnimation;
77
using CoreGraphics;
8-
using CoreImage;
9-
using Foundation;
8+
109
using Xamarin.PropertyEditing.Drawing;
1110
using Xamarin.PropertyEditing.ViewModels;
1211

@@ -79,12 +78,14 @@ private void Initialize (IHostResourceProvider hostResources)
7978

8079
private readonly CALayer background = new CALayer {
8180
CornerRadius = 3,
82-
BorderWidth = 1
81+
BorderWidth = 1,
82+
BorderColor = new CGColor (.5f, .5f, .5f, .5f),
8383
};
8484

8585
private readonly CALayer componentBackground = new CALayer {
8686
CornerRadius = 3,
87-
BorderWidth = 1
87+
BorderWidth = 1,
88+
BorderColor = new CGColor (.5f, .5f, .5f, .5f)
8889
};
8990

9091
private EditorInteraction interaction;
@@ -176,36 +177,36 @@ public override void Layout ()
176177
if (Frame.IsEmpty || Frame.IsInfinite () || double.IsNaN (Frame.X) || double.IsInfinity (Frame.X))
177178
return;
178179

179-
var secondarySpan = 20;
180-
var primarySpan = Frame.Height - 2 * padding - secondarySpan;
181-
var firstBase = padding;
182-
var secondBase = padding + secondarySpan;
183-
var firstStop = firstBase + primarySpan;
184-
185-
this.background.BorderColor = new CGColor (.5f, .5f, .5f, .5f);
186180
this.background.BackgroundColor = NSColor.ControlBackground.CGColor;
187-
this.background.Frame = new CGRect (0, 0, Frame.Height, Frame.Height);
188-
189-
this.componentBackground.BorderColor = new CGColor (.5f, .5f, .5f, .5f);
190181
this.componentBackground.BackgroundColor = NSColor.ControlBackground.CGColor;
191-
this.componentBackground.Frame = new CGRect (0, 0, Frame.Height, Frame.Height);
182+
this.hueLayer.GripColor = NSColor.Text.CGColor;
192183

193-
var x = firstStop + secondarySpan + 4 * padding;
194-
var backgroundFrame = new CGRect (x, 0, Math.Max(Frame.Width - x, 180), Frame.Height);
195-
this.componentBackground.Frame = backgroundFrame;
184+
const float spacing = 8, hueWidth = 20, historyHeight = 20;
185+
const float leftMinWidth = hueWidth + (Padding * 2) + 50;
186+
const float rightMinWidth = 125;
187+
const float rightRatio = 0.85f;
196188

197-
this.hueLayer.Frame = new CGRect (firstStop, secondBase, secondarySpan, primarySpan);
198-
this.hueLayer.GripColor = NSColor.Text.CGColor;
189+
nfloat hspace = Frame.Width - spacing;
190+
float leftWidth = Math.Max ((float)(hspace / 2) * (1 + (1 - rightRatio)), leftMinWidth);
191+
float rightWidth = Math.Max ((float)(hspace - leftWidth), rightMinWidth);
192+
nfloat vspace = Frame.Height - (Padding * 2);
193+
194+
this.background.Frame = new CGRect (0, 0, leftWidth, Frame.Height);
195+
196+
var shadeFrame = new CGRect (Padding, Padding + historyHeight + Padding, leftWidth - (Padding * 3) - hueWidth, vspace - historyHeight - Padding);
197+
this.shadeLayer.Frame = shadeFrame;
198+
this.historyLayer.Frame = new CGRect (Padding, Padding, shadeFrame.Width, historyHeight);
199+
this.hueLayer.Frame = new CGRect (this.shadeLayer.Frame.Right + Padding, this.historyLayer.Frame.Bottom + Padding, hueWidth, shadeFrame.Height);
200+
201+
var backgroundFrame = new CGRect (this.hueLayer.Frame.Right + spacing, 0, rightWidth, Frame.Height);
202+
this.componentBackground.Frame = backgroundFrame;
203+
var inset = backgroundFrame.Inset (4 * Padding, 2 * Padding);
204+
this.componentTabs.View.Frame = inset;
199205

200-
this.shadeLayer.Frame = new CGRect (firstBase, secondBase, primarySpan, primarySpan);
201-
this.historyLayer.Frame = new CGRect (firstBase, firstBase, primarySpan, secondarySpan);
202206
var inter = interaction ?? new EditorInteraction (ViewModel, null);
203207
foreach (var editor in Layer.Sublayers.OfType<ColorEditorLayer> ()) {
204208
editor.UpdateFromModel (inter);
205209
}
206-
207-
var inset = backgroundFrame.Inset (4 * padding, 2 * padding);
208-
this.componentTabs.View.Frame = inset;
209210
}
210211
}
211212
}

0 commit comments

Comments
 (0)