private void Initialize(IHostResourceProvider hostResources) { WantsLayer = true; Editors = CreateEditors(hostResources, EditorType); this.hexLabel = new UnfocusableTextField { StringValue = "#:", Alignment = NSTextAlignment.Right, ToolTip = Properties.Resources.HexValue }; AddSubview(this.hexLabel); this.hexEditor = new NSTextField { Alignment = NSTextAlignment.Right, ControlSize = NSControlSize.Small, Font = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)) }; AddSubview(this.hexEditor); this.hexEditor.EditingEnded += (o, e) => { if (CommonColor.TryParseArgbHex(this.hexEditor.StringValue, out CommonColor c)) { ViewModel.Color = c; this.hexEditor.StringValue = c.ToString(); } }; }
public void ColorParseArgb() { CommonColor parsed; Assert.IsTrue(CommonColor.TryParseArgbHex("#123", out parsed)); Assert.AreEqual(new CommonColor(0x11, 0x22, 0x33), parsed); Assert.IsTrue(CommonColor.TryParseArgbHex("#123456", out parsed)); Assert.AreEqual(new CommonColor(0x12, 0x34, 0x56), parsed); Assert.IsTrue(CommonColor.TryParseArgbHex("#1234", out parsed)); Assert.AreEqual(new CommonColor(0x22, 0x33, 0x44, 0x11), parsed); Assert.IsTrue(CommonColor.TryParseArgbHex("#12345678", out parsed)); Assert.AreEqual(new CommonColor(0x34, 0x56, 0x78, 0x12), parsed); Assert.IsFalse(CommonColor.TryParseArgbHex("not a color", out parsed)); Assert.AreEqual(CommonColor.Black, parsed); }