public BrushEditorControl(IHostResourceProvider hostResources) : base(hostResources) { TranslatesAutoresizingMaskIntoConstraints = false; this.previewLayer = new CommonBrushLayer(hostResources) { Frame = new CGRect(0, 0, 30, 10) }; this.popover = new AutoClosePopOver(hostResources, hostResources.GetVibrantAppearance(EffectiveAppearance)) { ContentViewController = this.brushTabViewController = new BrushTabViewController(hostResources) { PreferredContentSize = new CGSize(550, 363) } }; this.popUpButton = new ColorPopUpButton { ControlSize = NSControlSize.Small, Font = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)), TranslatesAutoresizingMaskIntoConstraints = false, ProxyResponder = new ProxyResponder(this, ProxyRowType.SingleView) }; this.popupButtonList = new NSMenu(); this.popUpButton.Menu = this.popupButtonList; AddSubview(this.popUpButton); this.AddConstraints(new[] { NSLayoutConstraint.Create(this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), NSLayoutConstraint.Create(this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16), NSLayoutConstraint.Create(this.popUpButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0), }); AppearanceChanged(); }
public static Task <ITypeInfo> RequestAt(this TypeRequestedEventArgs self, IHostResourceProvider hostResources, NSView source, AsyncValue <IReadOnlyDictionary <IAssemblyInfo, ILookup <string, ITypeInfo> > > assignableTypes) { var tcs = new TaskCompletionSource <ITypeInfo> (); var vm = new TypeSelectorViewModel(assignableTypes); var selector = new TypeSelectorControl { ViewModel = vm, Appearance = source.EffectiveAppearance }; vm.PropertyChanged += (vms, ve) => { if (ve.PropertyName == nameof(TypeSelectorViewModel.SelectedType)) { tcs.TrySetResult(vm.SelectedType); } }; var popover = new AutoClosePopOver(hostResources, hostResources.GetVibrantAppearance(source.EffectiveAppearance)) { Delegate = new PopoverDelegate <ITypeInfo> (tcs), ContentViewController = new NSViewController { View = selector, PreferredContentSize = new CoreGraphics.CGSize(360, 335) }, }; tcs.Task.ContinueWith(t => { // Focus back to the button that popped us up source.Superview?.Window?.MakeFirstResponder(source); popover.PerformClose(popover); popover.Dispose(); }, TaskScheduler.FromCurrentSynchronizationContext()); popover.Show(source.Frame, source.Superview, NSRectEdge.MinYEdge); return(tcs.Task); }