void CreateTitleLabels()
        {
            nfloat labelWidth = _sheetFrame.Width - 2 * _xMargin;

            // Create the window title label.
            _yCurr -= _labelHeight;
            var titleLabelRect = new CGRect(_xMargin, _yCurr, labelWidth, _labelHeight);
            var titleLabel     = ControlsFactory.NewStandardLabel(titleLabelRect);

            titleLabel.Font        = NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize);
            titleLabel.StringValue = "Uncombine film";
            View.AddSubview(titleLabel);

            // Create the instruction label.
            _yCurr -= _labelHeight + _yLabelsDistance;
            var instructionLabelRect = new CGRect(_xMargin, _yCurr, labelWidth, _labelHeight);
            var instructionLabel     = ControlsFactory.NewStandardLabel(instructionLabelRect);

            instructionLabel.Font        = NSFont.LabelFontOfSize(NSFont.LabelFontSize);
            instructionLabel.StringValue = "Create multiple films, one per distinct screening title";
            View.AddSubview(instructionLabel);

            // Set sample view used to disable resizing.
            _sampleView = titleLabel;
        }
            public override NSView GetViewForItem(iCarousel carousel, nint index, NSView view)
            {
                NSTextField label     = null;
                NSImageView imageView = null;

                if (view == null)
                {
                    // create new view if no view is available for recycling
                    imageView                = new NSImageView(new CGRect(0, 0, 200.0f, 200.0f));
                    imageView.Image          = NSImage.ImageNamed("page");
                    imageView.ImageAlignment = NSImageAlignment.Center;

                    label = new NSTextField(imageView.Bounds);
                    label.BackgroundColor = NSColor.Clear;
                    label.Alignment       = NSTextAlignment.Center;
                    label.Font            = NSFont.LabelFontOfSize(50);
                    label.Bordered        = false;
                    label.Editable        = false;
                    label.Tag             = 1;
                    imageView.AddSubview(label);
                }
                else
                {
                    // get a reference to the label in the recycled view
                    imageView = (NSImageView)view;
                    label     = (NSTextField)view.ViewWithTag(1);
                }

                // set the values of the view
                label.StringValue = items[index].ToString();

                return(imageView);
            }
예제 #3
0
        protected override void OnElementChanged(ElementChangedEventArgs <Button> e)
        {
            base.OnElementChanged(e);

            Control.BezelStyle = NSBezelStyle.Rounded;
            Control.Font       = NSFont.LabelFontOfSize(12);
        }
예제 #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Do any additional setup after loading the view.
            myFont                         = NSFont.LabelFontOfSize(12);
            pathView                       = PathView as PathView;
            ButtonFont.Activated          += (sender, e) => ShowFontPanel();
            TextFieldString.Changed       += (sender, e) => UpdateText();
            ButtonFont.Activated          += (sender, e) => UpdateText();
            SliderLetterSpacing.Activated += (sender, e) => UpdateLetterSpacing();
            SetFont(myFont);
        }
예제 #5
0
        void CreateUI()
        {
            var style = _style;

            if (style != NSTableViewCellStyle.Empty)
            {
                AddSubview(TextLabel = new NSTextField
                {
                    Bordered   = false,
                    Selectable = false,
                    Editable   = false,
                    Font       = NSFont.LabelFontOfSize(NSFont.SystemFontSize)
                });

                TextLabel.Cell.BackgroundColor = s_defaultChildViewsBackground;

                if (style == NSTableViewCellStyle.Image || style == NSTableViewCellStyle.Subtitle ||
                    style == NSTableViewCellStyle.ImageSubtitle)
                {
                    AddSubview(DetailTextLabel = new NSTextField
                    {
                        Bordered   = false,
                        Selectable = false,
                        Editable   = false,
                        Font       = NSFont.LabelFontOfSize(NSFont.SmallSystemFontSize)
                    });
                    DetailTextLabel.Cell.BackgroundColor = s_defaultChildViewsBackground;
                }

                if (style == NSTableViewCellStyle.Image || style == NSTableViewCellStyle.ImageSubtitle)
                {
                    AddSubview(ImageView = new NSImageView());
                }

                if (style == NSTableViewCellStyle.Value1 || style == NSTableViewCellStyle.Value2)
                {
                    var accessoryView = new NSView {
                        WantsLayer = true
                    };
                    accessoryView.Layer.BackgroundColor = s_defaultChildViewsBackground.CGColor;
                    AddSubview(AccessoryView            = accessoryView);
                }
            }
            AddSubview(_contexActionsTrackingView = new TrackingClickNSView());
        }
예제 #6
0
        public static NSFont ToNSFont(this FigmaTypeStyle style)
        {
            string family = style.fontFamily;

            if (family == "SF UI Text")
            {
                family = ".SF NS Text";
            }
            else if (family == "SF Mono")
            {
                family = ".SF NS Display";
            }
            else
            {
                Console.WriteLine("FONT: {0} - {1}", family, style.fontPostScriptName);
            }

            var             font   = NSFont.FromFontName(family, style.fontSize);
            var             w      = ToAppKitFontWeight(style.fontWeight);
            NSFontTraitMask traits = default(NSFontTraitMask);

            if (style.fontPostScriptName != null && style.fontPostScriptName.EndsWith("-Bold"))
            {
                traits = NSFontTraitMask.Bold;
            }
            else
            {
            }
            //if (font != null)
            //{
            //    var w = NSFontManager.SharedFontManager.WeightOfFont(font);
            //    var traits = NSFontManager.SharedFontManager.TraitsOfFont(font);

            //}

            font = NSFontManager.SharedFontManager.FontWithFamily(family, traits, w, style.fontSize);
            //var font = NSFont.FromFontName(".SF NS Text", 12);

            if (font == null)
            {
                Console.WriteLine($"[ERROR] Font not found :{family}");
                font = NSFont.LabelFontOfSize(style.fontSize);
            }
            return(font);
        }
 private void SetSummaryFieldText(string text, bool alternativeFormat = false)
 {
     if (alternativeFormat && _summaryFieldFormatIsOriginal)
     {
         _summaryField.Selectable      = false;
         _summaryField.Font            = NSFont.LabelFontOfSize(24);
         _summaryField.TextColor       = NSColor.LightGray;
         _summaryFieldFormatIsOriginal = false;
     }
     else if (!alternativeFormat && !_summaryFieldFormatIsOriginal)
     {
         _summaryField.Selectable      = true;
         _summaryField.Font            = _originalSummaryFieldFont;
         _summaryField.TextColor       = _originalSummaryFieldColor;
         _summaryFieldFormatIsOriginal = true;
     }
     _summaryField.AttributedStringValue = FilmInfo.HtmlToAttributed(text);
     ;
 }
예제 #8
0
        public MainWindow(CGRect contentRect, NSWindowStyle aStyle, NSBackingStore bufferingType, bool deferCreation) : base(contentRect, aStyle, bufferingType, deferCreation)
        {
            var windowSize     = new CGSize(640, 480);
            var windowLocation = new CGPoint(NSScreen.MainScreen.Frame.Width / 2 - windowSize.Width / 2, NSScreen.MainScreen.Frame.Height / 2 - windowSize.Height / 2);

            var centerRect = new CGRect(windowLocation, windowSize);

            Title = "Programmatic window";

            ContentView = new NSView(centerRect);

            var title = new NSTextField {
                StringValue        = "Title your problem",
                Editable           = true,
                UsesSingleLineMode = true,
                PlaceholderString  = "Title your problem"
            };

            title.AccessibilityLabel = title.PlaceholderString;

            title.TranslatesAutoresizingMaskIntoConstraints = false;
            ContentView.AddSubview(title);

            // There are three ways to set auto layout constraints programmatically.  The first is by setting layout anchors
            // https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html#//apple_ref/doc/uid/TP40010853-CH16-SW5
            // Don't forget to set .Active = true on the constraint or it won't show up
            title.LeadingAnchor.ConstraintEqualToAnchor(ContentView.LeadingAnchor, PADDING).Active    = true;
            title.TrailingAnchor.ConstraintEqualToAnchor(ContentView.TrailingAnchor, -PADDING).Active = true;
            title.TopAnchor.ConstraintEqualToAnchor(ContentView.TopAnchor, PADDING).Active            = true;

            var scroll = new NSScrollView(new CGRect(0, 0, ContentView.Frame.Width - PADDING - PADDING, 100));

            scroll.BorderType            = NSBorderType.BezelBorder;
            scroll.HasHorizontalScroller = false;
            scroll.HasVerticalScroller   = true;
            var scrollSize = scroll.ContentSize;

            var description = new NSTextView(new CGRect(0, 0, scrollSize.Width, scrollSize.Height));

            description.MinSize               = new CGSize(0, scrollSize.Height);
            description.MaxSize               = new CGSize(float.MaxValue, float.MaxValue);
            description.Editable              = true;
            description.Font                  = title.Font;
            description.VerticallyResizable   = true;
            description.HorizontallyResizable = false;
            description.AutoresizingMask      = NSViewResizingMask.WidthSizable;

            description.TextContainer.Size = new CGSize(scrollSize.Width, float.MaxValue);
            description.TextContainer.WidthTracksTextView = true;

            scroll.DocumentView = description;

            scroll.TranslatesAutoresizingMaskIntoConstraints = false;
            ContentView.AddSubview(scroll);

            // The second option is to create NSLayoutConstraints
            // https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html#//apple_ref/doc/uid/TP40010853-CH16-SW8
            ContentView.AddConstraints(new [] {
                NSLayoutConstraint.Create(scroll, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Leading, 1, PADDING),
                NSLayoutConstraint.Create(scroll, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Trailing, 1, -PADDING)
            });

            // Alternatively, you can create the constraints as shown here and set .Active = true, same as with the anchor method above
            NSLayoutConstraint.Create(scroll, NSLayoutAttribute.Top, NSLayoutRelation.Equal, title, NSLayoutAttribute.Bottom, 1, PADDING).Active = true;

            title.Activated += (sender, e) => MakeFirstResponder(description);

            var labelFont = NSFont.LabelFontOfSize(10);

            var publicLabel = new NSTextField {
                StringValue     = "Your title and description will be public",
                Editable        = false,
                Bezeled         = false,
                DrawsBackground = false,
                Selectable      = false,
                Font            = labelFont,
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            ContentView.AddSubview(publicLabel);

            // You can also use different types of constraints for the same view
            ContentView.AddConstraints(new [] {
                NSLayoutConstraint.Create(publicLabel, NSLayoutAttribute.Leading, NSLayoutRelation.GreaterThanOrEqual, ContentView, NSLayoutAttribute.Leading, 1, 40),
                NSLayoutConstraint.Create(publicLabel, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Trailing, 1, -PADDING)
            });
            publicLabel.TopAnchor.ConstraintEqualToAnchor(scroll.BottomAnchor, 5).Active = true;

            var email = new NSTextField {
                Editable          = true,
                PlaceholderString = "Optional email address"
            };

            email.AccessibilityLabel = email.PlaceholderString;

            email.TranslatesAutoresizingMaskIntoConstraints = false;
            ContentView.AddSubview(email);
            ContentView.AddConstraints(new [] {
                NSLayoutConstraint.Create(email, NSLayoutAttribute.Top, NSLayoutRelation.Equal, publicLabel, NSLayoutAttribute.Bottom, 1, PADDING)
            });

            // The third option for setting layout constraints is to use Visual Format Language
            // https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html#//apple_ref/doc/uid/TP40010853-CH16-SW9
            string emailFormat      = "|-10-[email]-10-|";
            var    emailViews       = NSDictionary.FromObjectAndKey(email, (NSString)"email");
            var    emailConstraints = NSLayoutConstraint.FromVisualFormat(emailFormat, NSLayoutFormatOptions.None, null, emailViews);

            NSLayoutConstraint.ActivateConstraints(emailConstraints);

            var sendButton = new NSButton {
                Title = "OK"
            };

            sendButton.Activated += (sender, e) => {
                var alert = new NSAlert {
                    MessageText = "Button pressed"
                };
                alert.AddButton("Okay");
                alert.RunModal();
                Dispose();
            };

            sendButton.TranslatesAutoresizingMaskIntoConstraints = false;
            ContentView.AddSubview(sendButton);
            ContentView.AddConstraints(new [] {
                NSLayoutConstraint.Create(sendButton, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Trailing, 1, -PADDING),
                NSLayoutConstraint.Create(sendButton, NSLayoutAttribute.Leading, NSLayoutRelation.GreaterThanOrEqual, ContentView, NSLayoutAttribute.Leading, 1, 40)
            });

            //To do vertical constraints with visual format language, start the format string with V:"
            string sendButtonFormat      = "V:[email]-10-[sendButton]-10-|";
            var    sendButtonViews       = NSDictionary.FromObjectsAndKeys(new NSObject [] { email, sendButton }, new NSObject [] { (NSString)"email", (NSString)"sendButton" });
            var    sendButtonConstraints = NSLayoutConstraint.FromVisualFormat(sendButtonFormat, NSLayoutFormatOptions.None, null, sendButtonViews);

            NSLayoutConstraint.ActivateConstraints(sendButtonConstraints);

            email.Activated += (sender, e) => {
                if (sendButton.Enabled)
                {
                    MakeFirstResponder(sendButton);
                }
            };

            bool hasTitle       = false;
            bool hasDescription = false;

            title.Changed += (sender, e) => {
                var titleStr = title.StringValue;
                hasTitle           = !string.IsNullOrWhiteSpace(titleStr) && titleStr.Length > 5;
                sendButton.Enabled = hasTitle && hasDescription;
            };

            description.TextStorage.DidProcessEditing += (sender, e) => {
                hasDescription     = description.TextStorage.Length > 10;
                sendButton.Enabled = hasTitle && hasDescription;
            };
        }