public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier) { switch (Array.IndexOf(DefaultIdentifiers, identifier)) { case 0: { var item = NSColorPickerTouchBarItem.CreateColorPicker(identifier, NSImage.ImageNamed(NSImageName.TouchBarColorPickerFill)); item.ColorList = NSColorList.ColorListNamed("Apple"); item.ShowsAlpha = false; item.Activated += (_, __) => { var color = item.Color.UsingColorSpace(NSColorSpace.CalibratedRGB); this.ColorSelected.Invoke(item, color); }; return(item); } case 1: { var item = new NSCustomTouchBarItem(identifier); item.View = NSButton.CreateButton(NSImage.ImageNamed(NSImageName.TouchBarRecordStopTemplate), () => this.TurnOffRequested.Invoke(this, null)); return(item); } default: return(null); } }
public TypeSelectorWindow(TypeSelectorViewModel viewModel) : base(new CGRect(0, 0, 300, 300), NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable, NSBackingStore.Buffered, true) { Title = Properties.Resources.SelectObjectTitle; this.selector = new TypeSelectorControl { ViewModel = viewModel, TranslatesAutoresizingMaskIntoConstraints = false }; ContentView.AddSubview(this.selector); this.ok = NSButton.CreateButton(Properties.Resources.OK, OnOked); this.ok.TranslatesAutoresizingMaskIntoConstraints = false; ContentView.AddSubview(this.ok); this.cancel = NSButton.CreateButton(Properties.Resources.Cancel, OnCanceled); this.cancel.TranslatesAutoresizingMaskIntoConstraints = false; ContentView.AddSubview(this.cancel); ContentView.AddConstraints(new[] { NSLayoutConstraint.Create(this.selector, NSLayoutAttribute.Width, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Width, 1, -20), NSLayoutConstraint.Create(this.selector, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1, 0), NSLayoutConstraint.Create(this.selector, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.CenterX, 1, 0), NSLayoutConstraint.Create(this.selector, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.ok, NSLayoutAttribute.Top, 1, -10), NSLayoutConstraint.Create(this.ok, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Bottom, 1, -10), NSLayoutConstraint.Create(this.ok, NSLayoutAttribute.Right, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Right, 1, -10), NSLayoutConstraint.Create(this.cancel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.ok, NSLayoutAttribute.Left, 1, -10), NSLayoutConstraint.Create(this.cancel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Bottom, 1, -10), }); }
public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier) { var item = new NSCustomTouchBarItem(identifier); switch (Array.IndexOf(DefaultIdentifiers, identifier)) { case 0: item.View = new NSImageView { Image = GetImage(), ImageScaling = NSImageScale.ProportionallyDown }; break; case 1: item.View = NSButton.CreateButton(NSImage.ImageNamed(NSImageName.TouchBarPlayTemplate), () => NSWorkspace.SharedWorkspace.OpenUrl(url)); break; case 2: // trim title var start = result.IndexOf('「'); var end = result.IndexOf('」'); var summary = result.Substring(0, start) + " " + result.Substring(end + 1); item.View = NSTextField.CreateLabel(summary); break; default: break; } return(item); }
public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier) { NSCustomTouchBarItem item = new NSCustomTouchBarItem(identifier); switch (identifier) { case "md.build": { var buildButton = NSButton.CreateButton(BuildPlayImage(), () => throw new NotImplementedException()); buildButton.Activated += Build_Activated; item.View = buildButton; return(item); } case "md.debug": { if (!IsRunning && !DebuggingService.IsRunning && !DebuggingService.IsPaused) { return(null); } var test = new[] { BuildDebugImage() }.Concat(_debugImages).ToArray(); var nsControl = NSSegmentedControl.FromImages(test, NSSegmentSwitchTracking.SelectAny, () => throw new NotImplementedException()); for (var i = 1; i < test.Length; i++) { nsControl.SetEnabled(DebuggingService.IsPaused, i); } nsControl.Activated += Debug_Activated; item.View = nsControl; return(item); } } return(null); }
public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier) { NSCustomTouchBarItem item = new NSCustomTouchBarItem(identifier); item.CustomizationLabel = "Bar " + ParseId(identifier); switch (ParseId(identifier)) { case 0: { item.View = NSButton.CreateButton("Custom 1", () => Console.WriteLine("Custom First")); return(item); } case 1: { item.View = NSButton.CreateButton("Custom 2", () => Console.WriteLine("Custom Second")); return(item); } case 2: { item.View = NSButton.CreateButton("Custom 3", () => Console.WriteLine("Custom Third")); return(item); } case 3: { item.View = NSButton.CreateButton("Custom 4", () => Console.WriteLine("Custom Fourth")); return(item); } } return(null); }
public override void ViewDidLoad() { base.ViewDidLoad(); var stackView = new NSStackView { Orientation = NSUserInterfaceLayoutOrientation.Vertical, Frame = View.Frame, }; var editBenchCount = AddArrangedLabelAndField(stackView, "Benchmark count:", "5"); var editStrings = AddArrangedLabelAndField(stackView, "NSString allocations:", "10000"); var editViews = AddArrangedLabelAndField(stackView, "NSView allocations", "0"); stackView.AddArrangedSubview(NSButton.CreateButton("Test", () => { int benchCount = int.Parse(editBenchCount.StringValue); int nsstringCount = int.Parse(editStrings.StringValue); int nsviewCount = int.Parse(editViews.StringValue); var bench = new AllocatorBenchmark(benchCount, nsstringCount, nsviewCount); bench.Run(); })); View.AddSubview(stackView); // Do any additional setup after loading the view. }
NSTouchBarItem makeStartHugulpButton(string identifier) { var item = new NSCustomTouchBarItem(identifier); var button = NSButton.CreateButton("Start hugulp Watcher", () => appDelegate.startHugulpWatcher()); item.View = button; return(item); }
NSTouchBarItem makeAddNewPostButton(string identifier) { var item = new NSCustomTouchBarItem(identifier); var button = NSButton.CreateButton("New Post", () => appDelegate.addNewBlogPost()); button.Image = NSImage.ImageNamed(NSImageName.TouchBarAddTemplate); button.ImagePosition = NSCellImagePosition.ImageLeft; item.View = button; return(item); }
NSTouchBarItem makeServerButton(string identifier) { _serverItem = new NSCustomTouchBarItem(identifier); var button = NSButton.CreateButton("Start Server", () => AppDelegate.startStopServer()); button.Image = NSImage.ImageNamed(NSImageName.StatusUnavailable); button.ImagePosition = NSCellImagePosition.ImageLeft; _serverItem.View = button; return(_serverItem); }
NSTouchBarItem makeOpenFolderButton(string identifier) { var item = new NSCustomTouchBarItem(identifier); var button = NSButton.CreateButton("Open Hugo Folder", () => appDelegate.openHugoFolder()); button.Image = NSImage.ImageNamed(NSImageName.TouchBarFolderTemplate); button.ImagePosition = NSCellImagePosition.ImageLeft; item.View = button; return(item); }
public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier) { var item = new NSCustomTouchBarItem(identifier); switch (Array.IndexOf(DefaultIdentifiers, identifier)) { case 0: item.View = new NSImageView { Image = GetImage(), ImageScaling = NSImageScale.ProportionallyDown }; break; case 1: if (url == null) { item.View = new NSImageView { Image = NSImage.ImageNamed(NSImageName.Caution) }; } else { item.View = NSButton.CreateButton(NSImage.ImageNamed(NSImageName.TouchBarPlayTemplate), () => NSWorkspace.SharedWorkspace.OpenUrl(url)); } break; case 2: var view = new NSScrollView { HasVerticalScroller = false, HasHorizontalScroller = true, BorderType = NSBorderType.NoBorder }; item.View = view; // trim title var label = NSTextField.CreateLabel(result); var size = label.AttributedStringValue.Size; label.SetBoundsOrigin(new CGPoint(0, (BarHeight - size.Height) / 2)); label.SetFrameSize(new CGSize(size.Width + 8, BarHeight)); view.DocumentView = label; break; default: break; } return(item); }
public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier) { if (IsPopupID(identifier)) { switch (ParseNestedId(identifier)) { case 0: return(ColorPickerDelegate.CreateColorPicker(identifier, "Apple")); case 1: return(new NSCustomTouchBarItem(identifier) { View = NSButton.CreateButton("NSPopup Button", () => Console.WriteLine("Popup Button")) }); } } else { switch (ParseId(identifier)) { case 0: { NSPopoverTouchBarItem item = new NSPopoverTouchBarItem(identifier); item.PopoverTouchBar = new NSTouchBar() { Delegate = this, DefaultItemIdentifiers = new string [] { CreateNestedID(0) } }; item.CollapsedRepresentationLabel = "Popup Color"; return(item); } case 1: { NSPopoverTouchBarItem item = new NSPopoverTouchBarItem(identifier); item.PopoverTouchBar = new NSTouchBar() { Delegate = this, DefaultItemIdentifiers = new string [] { CreateNestedID(1) } }; item.CollapsedRepresentationLabel = "Popup Text"; return(item); } } } return(null); }
public MainWindow(CGRect contentRect, NSWindowStyle aStyle, NSBackingStore bufferingType, bool deferCreation) : base(contentRect, aStyle, bufferingType, deferCreation) { // Define the User Interface of the Window here Title = "Window From Code"; // Create the content view for the window and make it fill the window ContentView = new NSView(Frame); // Add UI Elements to window ClickMeButton = NSButton.CreateButton("Click Me!", ButtonClicked); ClickMeButton.TranslatesAutoresizingMaskIntoConstraints = false; ContentView.AddSubview(ClickMeButton); ClickMeLabel = NSTextField.CreateLabel("Button has not been clicked yet."); ClickMeLabel.TranslatesAutoresizingMaskIntoConstraints = false; ContentView.AddSubview(ClickMeLabel); // Add constraints to window ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "V:|-[button]-[label]", NSLayoutFormatOptions.AlignAllLeading, "button", ClickMeButton, "label", ClickMeLabel)); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "H:|-[button]", NSLayoutFormatOptions.AlignAllFirstBaseline, "button", ClickMeButton)); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "H:|-[label]", NSLayoutFormatOptions.AlignAllFirstBaseline, "label", ClickMeLabel)); var constraints = NSLayoutConstraint.FromVisualFormat( "H:[label]-|", NSLayoutFormatOptions.AlignAllFirstBaseline, "label", ClickMeLabel); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "H:[button]-(>=std)-|", NSLayoutFormatOptions.AlignAllFirstBaseline, "button", ClickMeButton, "std", constraints[0].Constant)); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "H:[label]-(>=std)-|", NSLayoutFormatOptions.AlignAllFirstBaseline, "label", ClickMeLabel, "std", constraints[0].Constant)); constraints = NSLayoutConstraint.FromVisualFormat( "V:[label]-|", NSLayoutFormatOptions.AlignAllLeft, "label", ClickMeLabel); ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat( "V:[label]-(>=std)-|", NSLayoutFormatOptions.AlignAllFirstBaseline, "label", ClickMeLabel, "std", constraints[0].Constant)); }
public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier) { NSCustomTouchBarItem item = new NSCustomTouchBarItem(identifier); switch (ParseId(identifier)) { case 0: { item.View = NSButton.CreateButton("1️⃣ Button", () => Console.WriteLine("Button")); return(item); } case 1: { item.View = NSSegmentedControl.FromLabels(new string [] { "Label1", "Label2" }, NSSegmentSwitchTracking.SelectAny, () => Console.WriteLine("Seg Label")); return(item); } case 2: { item.View = new NSImageView() { Image = NSImage.ImageNamed(NSImageName.TouchBarGetInfoTemplate), }; return(item); } case 3: { item.View = NSSegmentedControl.FromImages( new NSImage [] { NSImage.ImageNamed(NSImageName.TouchBarVolumeDownTemplate), NSImage.ImageNamed(NSImageName.TouchBarVolumeUpTemplate) }, NSSegmentSwitchTracking.SelectAny, () => Console.WriteLine("Seg Images")); return(item); } case 4: { item.View = NSSlider.FromValue(5, 0, 10, () => Console.WriteLine("Slider")); return(item); } } return(null); }
public CollectionEditorWindow(IHostResourceProvider hostResources, CollectionPropertyViewModel viewModel) : base(new CGRect(0, 0, 500, 400), NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable, NSBackingStore.Buffered, true) { Delegate = new ModalDialogDelegate(); Title = String.Format(Properties.Resources.CollectionEditorTitle, viewModel.Property.Name); this.collectionEditor = new CollectionEditorControl(hostResources) { ViewModel = viewModel, TranslatesAutoresizingMaskIntoConstraints = false }; ContentView.AddSubview(this.collectionEditor); this.ok = NSButton.CreateButton(Properties.Resources.OK, OnOked); this.ok.TranslatesAutoresizingMaskIntoConstraints = false; //this.ok.KeyEquivalent = "\r"; // FIXME: The type selector popup doesn't eat this key, so it ends up closing both. ContentView.AddSubview(this.ok); this.cancel = NSButton.CreateButton(Properties.Resources.Cancel, OnCanceled); this.cancel.TranslatesAutoresizingMaskIntoConstraints = false; ContentView.AddSubview(this.cancel); ContentView.AddConstraints(new[] { NSLayoutConstraint.Create(this.collectionEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Width, 1, -40), NSLayoutConstraint.Create(this.collectionEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1, 20), NSLayoutConstraint.Create(this.collectionEditor, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.CenterX, 1, 0), NSLayoutConstraint.Create(this.collectionEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.ok, NSLayoutAttribute.Top, 1, -20), NSLayoutConstraint.Create(this.ok, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Bottom, 1, -20), NSLayoutConstraint.Create(this.ok, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.collectionEditor, NSLayoutAttribute.Right, 1, 0), NSLayoutConstraint.Create(this.ok, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this.cancel, NSLayoutAttribute.Width, 1, 0), NSLayoutConstraint.Create(this.cancel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.ok, NSLayoutAttribute.Left, 1, -10), NSLayoutConstraint.Create(this.cancel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.ok, NSLayoutAttribute.Bottom, 1, 0), NSLayoutConstraint.Create(this.cancel, NSLayoutAttribute.Width, NSLayoutRelation.GreaterThanOrEqual, 1, 80) }); }