예제 #1
0
        protected NativeFontRegistry()
        {
            var font = NSFont.SystemFontOfSize(NSFont.SystemFontSize);

            _systemFontName = font.FontName;
            font.Dispose();
        }
예제 #2
0
        public void SetGroupItem(bool isGroupItem, NSTableView tableView, float?groupSize = null, float?normalSize = null)
        {
            if (isGroupItem)
            {
                this.Font = NSFont.BoldSystemFontOfSize(groupSize ?? NSFont.SystemFontSize);
            }
            else if (Highlighted)
            {
                Font = NSFont.BoldSystemFontOfSize(normalSize ?? NSFont.SystemFontSize);
            }
            else
            {
                Font = NSFont.SystemFontOfSize(normalSize ?? NSFont.SystemFontSize);
            }

            if (Highlighted)
            {
                TextColor = NSColor.Highlight;
            }
            else if (!tableView.Window.IsKeyWindow)
            {
                TextColor = NSColor.DisabledControlText;
            }
            else if (isGroupItem)
            {
                TextColor = GroupColor;
            }
            else
            {
                TextColor = NSColor.ControlText;
            }
        }
예제 #3
0
        public static NSAttributedString AttributedTitle(string title, NSColor color, String fontName, float fontSize, NSTextAlignment textAlignment)
        {
            NSMutableParagraphStyle ps = new NSMutableParagraphStyle();

            ps.Alignment   = textAlignment;
            ps.LineSpacing = 0.0f;
            NSColor fontColor = color;
            NSFont  font      = NSFont.FromFontName(fontName, fontSize);

            if (font == null)
            {
                font = NSFont.SystemFontOfSize(fontSize);
            }
            NSString titleObj = new NSString(title);

            NSStringAttributes attributes = new NSStringAttributes();

            attributes.Font            = font;
            attributes.ForegroundColor = fontColor;
            attributes.ParagraphStyle  = ps;
            attributes.ToolTip         = titleObj;
            NSAttributedString buttonString = new NSAttributedString(title, attributes);

            return(buttonString);
        }
 private static void RenderSolutionNameIcon(string name)
 {
     if (!string.IsNullOrWhiteSpace(name))
     {
         const float margin         = 4;
         NSString    text           = (NSString)name;
         var         paragraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();
         paragraphStyle.Alignment = NSTextAlignment.Center;
         var attributes = new NSStringAttributes()
         {
             Font            = NSFont.SystemFontOfSize(19, NSFontWeight.Regular),
             ForegroundColor = NSColor.White,
             ParagraphStyle  = paragraphStyle
         };
         var textRect         = new CGSize(_defaultImage.Size.Width - margin * 2, _defaultImage.Size.Height - 2 * margin);
         var rect             = text.BoundingRectWithSize(textRect, NSStringDrawingOptions.UsesLineFragmentOrigin, attributes.Dictionary);
         var centerAdjustment = _defaultImage.Size.Width - rect.Width - 2 * margin;
         rect.Offset(margin + centerAdjustment / 2, margin);
         var brandedImage = NSImage.ImageWithSize(_defaultImage.Size, false, (dstRect) =>
         {
             _defaultImage.Draw(dstRect);
             DrawBackgroundInRect(rect);
             text.DrawInRect(rect, attributes);
             return(true);
         });
         NSApplication.SharedApplication.ApplicationIconImage = brandedImage;
     }
     else
     {
         NSApplication.SharedApplication.ApplicationIconImage = _defaultImage;
     }
 }
예제 #5
0
        protected override IView OnConvertToView(FigmaNode currentNode, ViewNode parentNode, ViewRenderService rendererService)
        {
            var button = new NSButton();

            var frame = (FigmaFrame)currentNode;

            frame.TryGetNativeControlType(out var controlType);
            frame.TryGetNativeControlVariant(out var controlVariant);

            FigmaText text = frame.children
                             .OfType <FigmaText>()
                             .FirstOrDefault(s => s.name == ComponentString.SYMBOL);

            button.BezelStyle = NSBezelStyle.RegularSquare;
            button.Bordered   = false;
            button.Font       = NSFont.SystemFontOfSize(text.style.fontSize, ViewHelper.GetNSFontWeight(text));
            button.Title      = text.characters;

            foreach (var styleMap in text.styles)
            {
                if (rendererService.NodeProvider.TryGetStyle(styleMap.Value, out FigmaStyle style))
                {
                    if (styleMap.Key == "fill")
                    {
                        button.ContentTintColor = ColorService.GetNSColor(style.name);
                    }
                }
            }

            if (frame.TrySearchA11Label(out var tooltip))
            {
                button.ToolTip = tooltip; // TODO: code generation
            }
            return(new View(button));
        }
예제 #6
0
        void CreateTitleBar(string title)
        {
            titleBar.BoxType     = NSBoxType.NSBoxCustom;
            titleBar.WantsLayer  = true;
            titleBar.BorderWidth = 0;

            titleBarGradient           = new CAGradientLayer();
            titleBarGradient.Locations = new NSNumber[] { 0.0, 1.0 };
            titleBar.Layer             = titleBarGradient;

            titleField.StringValue     = title;
            titleField.Font            = NSFont.SystemFontOfSize(NSFont.SystemFontSize);
            titleField.Alignment       = NSTextAlignment.Center;
            titleField.DrawsBackground = false;
            titleField.Editable        = false;
            titleField.Bezeled         = false;
            titleField.Selectable      = false;

            separator.BoxType     = NSBoxType.NSBoxCustom;
            separator.BorderWidth = 1;

            AddSubview(titleBar);
            AddSubview(titleField);
            AddSubview(separator);
        }
예제 #7
0
 static void UpdateButtonFields(ObservableButton b, bool enabled, string text, IObserver <Points> width)
 {
     b.Enabled = enabled;
     b.Title   = text;
     b.Font    = NSFont.SystemFontOfSize(0.0f);
     width.OnNext((double)b.FittingSize.Width);
 }
예제 #8
0
        public BrushTabViewController(IHostResourceProvider hostResources)
            : base(hostResources)
        {
            TabBorderColor     = NamedResources.TabBorderColor;
            TabBackgroundColor = NamedResources.PadBackgroundColor;

            PreferredContentSize = new CGSize(450, 280);
            TransitionOptions    = NSViewControllerTransitionOptions.None;
            ContentPadding       = new NSEdgeInsets(8, 8, 8, 8);

            this.filterResource = new NSSearchField {
                ControlSize       = NSControlSize.Mini,
                Font              = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Mini)),
                PlaceholderString = Properties.Resources.SearchResourcesTitle,
            };

            this.filterResource.Changed += (sender, e) => {
                ViewModel.ResourceSelector.FilterText = this.filterResource.Cell.Title;
                this.resource.ReloadData();
            };

            this.filterResource.Hidden = true;

            TabStack.AddView(this.filterResource, NSStackViewGravity.Leading);
        }
예제 #9
0
        public void SystemFontClicked(NSObject sender)
        {
            var size = NSFont.SystemFontSize;

            SelectedFont = NSFont.SystemFontOfSize(size);
            panel.SetPanelFont(SelectedFont, false);
        }
예제 #10
0
        public override void DrawRect(CGRect dirtyRect)
        {
            NSColorList colors = NSColorList.ColorListNamed("System");
            CGRect      rect   = Bounds;

            rect.Height = 12;
            var style = (NSMutableParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();

            style.Alignment = NSTextAlignment.Right;
            var attrs = new NSStringAttributes {
                Font            = NSFont.SystemFontOfSize(8),
                ForegroundColor = NSColor.LabelColor,
                ParagraphStyle  = style
            };

            foreach (NSString key in colors.AllKeys())
            {
                if (DrawColors)
                {
                    NSColor color = colors.ColorWithKey(key);
                    color.Set();
                    NSGraphics.RectFill(rect);
                }

                if (DrawTitles)
                {
                    key.DrawString(rect, attrs.Dictionary);
                }

                rect.Y += 12;
            }
        }
예제 #11
0
        private static NSFont _ToUIFont(string family, float size, FontAttributes attributes)
        {
            bool isBold   = (uint)(attributes & FontAttributes.Bold) > 0U;
            bool isItalic = (uint)(attributes & FontAttributes.Italic) > 0U;

            if (family != null)
            {
                try
                {
                    var uiFont1 = NSFont.FromFontName(family, (nfloat)size);
                    if (uiFont1 != null)
                    {
                        return(uiFont1);
                    }
                }
                catch
                {
                }
            }
            if (isBold & isItalic)
            {
                var uiFont = NSFont.SystemFontOfSize((nfloat)size);
                return(NSFont.BoldSystemFontOfSize((nfloat)size));
            }
            if (isBold)
            {
                return(NSFont.BoldSystemFontOfSize((nfloat)size));
            }

            //if (isItalic)
            //	return NSFont.ItalicSystemFontOfSize ((nfloat)size);

            return(NSFont.SystemFontOfSize((nfloat)size));
        }
예제 #12
0
        public NativeCanvas(Func <CGColorSpace> getColorspace) : base(CreateNewState, CreateStateCopy)
        {
            _getColorspace = getColorspace;

            if (_systemFontName == null)
            {
#if MONOMAC || __MACOS__
                var systemFont = NSFont.SystemFontOfSize(12f);
                _systemFontName = systemFont.FontName;
                systemFont.Dispose();

                var boldSystemFont = NSFont.BoldSystemFontOfSize(12f);
                _boldSystemFontName = boldSystemFont.FontName;
                boldSystemFont.Dispose();
#else
                var systemFont = UIFont.SystemFontOfSize(12f);
                _systemFontName = systemFont.Name;
                systemFont.Dispose();

                var boldSystemFont = UIFont.BoldSystemFontOfSize(12f);
                _boldSystemFontName = boldSystemFont.Name;
                boldSystemFont.Dispose();
#endif
            }

            _defaultFontName = "Helvetica";
            _fontName        = _defaultFontName;
        }
예제 #13
0
        void ShowExpiredLabelView(bool isShow)
        {
            if (isShow)
            {
                AddTriangleView(NSColor.Red, true);
            }

            if (updateInfoLabel == null)
            {
                var updateButtonFrame = new CGRect(-10, -48, PUBLICATION_DOWN_WIDTH, PUBLICATION_DOWN_ORGX);
                updateInfoLabel = new NSTextField(updateButtonFrame);
                updateInfoLabel.Cell.Bordered        = false;
                updateInfoLabel.Cell.DrawsBackground = false;
                updateInfoLabel.Cell.Editable        = false;
                updateInfoLabel.Cell.TextColor       = NSColor.White;
                updateInfoLabel.Cell.Alignment       = NSTextAlignment.Left;
                updateInfoLabel.Cell.Font            = NSFont.SystemFontOfSize(15.0f);
                updateInfoLabel.StringValue          = "Expired";

                nfloat rotation = updateInfoLabel.FrameCenterRotation;
                updateInfoLabel.FrameCenterRotation = rotation - 45.0f;

                if (customTriView != null)
                {
                    customTriView.WantsLayer = true;
                    customTriView.AddSubview(updateInfoLabel);
                }
            }

            updateInfoLabel.Hidden = !isShow;
        }
예제 #14
0
        public void ChangeFont(NSFontManager sender)
        {
            var font = sender.ConvertFont(NSFont.SystemFontOfSize(NSFont.SystemFontSize));

            Handler.Font = font != null ? new Font(new FontHandler(font)) : null;
            Handler.Callback.OnFontChanged(Handler.Widget, EventArgs.Empty);
        }
예제 #15
0
        public Task <NSImage> LoadImageAsync(
            ImageSource imagesource,
            CancellationToken cancelationToken = default(CancellationToken),
            float scale = 1f)
        {
            NSImage image      = null;
            var     fontsource = imagesource as FontImageSource;

            if (fontsource != null)
            {
                var font = NSFont.FromFontName(fontsource.FontFamily ?? string.Empty, (float)fontsource.Size) ??
                           NSFont.SystemFontOfSize((float)fontsource.Size);
                var iconcolor = fontsource.Color.IsDefault ? _defaultColor : fontsource.Color;
                var attString = new NSAttributedString(fontsource.Glyph, font: font, foregroundColor: iconcolor.ToNSColor());
                var imagesize = ((NSString)fontsource.Glyph).StringSize(attString.GetAttributes(0, out _));

                using (var context = new CGBitmapContext(IntPtr.Zero, (nint)imagesize.Width, (nint)imagesize.Height, 8, (nint)imagesize.Width * 4, NSColorSpace.GenericRGBColorSpace.ColorSpace, CGImageAlphaInfo.PremultipliedFirst))
                {
                    using (var ctline = new CTLine(attString))
                    {
                        ctline.Draw(context);
                    }

                    using (var cgImage = context.ToImage())
                    {
                        image = new NSImage(cgImage, imagesize);
                    }
                }
            }

            return(Task.FromResult(image));
        }
예제 #16
0
            public NavigationCell(CGRect frame)
            {
                var     uiLabel = new NSTextField(CGRect.Empty);
                NSColor clear   = NSColor.Clear;

                uiLabel.BackgroundColor = clear;

                uiLabel.Alignment = NSTextAlignment.Left;
                uiLabel.Font      = NSFont.SystemFontOfSize(14);
                this.nameLabel    = uiLabel;
                this.image        = new NSButton(CGRect.Empty);

                this.SetupLayer();

                this.image.Activated += (sender, e) =>
                {
                    if (this.Selected == null)
                    {
                        return;
                    }
                    this.Selected();
                };

                //this.image.ContentMode = UIViewContentMode.ScaleAspectFit;
                //this.image.Center = this.ContentView.Center;

                View.AddSubview(image);
                View.AddSubview(nameLabel);
            }
예제 #17
0
        public FixedFlatButton(string title, NSView logo = null)
        {
            Alignment  = NSTextAlignment.Center;
            WantsLayer = true;
            BezelStyle = NSBezelStyle.ShadowlessSquare;
            ShowsBorderOnlyWhileMouseInside = true;
            Layer.CornerRadius = 3;
            BackgroundColor    = NSColor.Clear;
            BorderColor        = NSColor.White;
            BorderWidth        = 1.0f;
            Title = "";

            if (logo != null)
            {
                this.logo = logo;
                AddSubview(logo);
            }

            label             = ViewsHelper.CreateLabel(title);
            label.StringValue = title;
            label.Alignment   = NSTextAlignment.Center;
            label.TextColor   = NSColor.White;
            label.Font        = NSFont.SystemFontOfSize(15);
            label.SetFrameSize(label.IntrinsicContentSize);
            AddSubview(label);

            //WidthAnchor.ConstraintEqualToConstant(FixedButtonWidth).Active = true;
            //HeightAnchor.ConstraintEqualToConstant(FixedButtonHeight).Active = true;
            RecalculateSizes();
        }
        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();
                }
            };
        }
예제 #19
0
        public bool Run(IWindowFrameBackend parent)
        {
            fontPanel.Delegate = new FontPanelDelegate();

            if (parent != null)
            {
                var macParent = parent as NSWindow ?? context.Toolkit.GetNativeWindow(parent) as NSWindow ?? NSApplication.SharedApplication.KeyWindow;
                if (macParent != null && fontPanel.EffectiveAppearance.Name != macParent.EffectiveAppearance.Name)
                {
                    fontPanel.Appearance = macParent.EffectiveAppearance;
                }
            }

            if (SelectedFont != null)
            {
                NSFontManager.SharedFontManager.SetSelectedFont(((FontData)Toolkit.GetBackend(SelectedFont)).Font, false);
            }

            NSApplication.SharedApplication.RunModalForWindow(fontPanel);

            var font = NSFontPanel.SharedFontPanel.PanelConvertFont(NSFont.SystemFontOfSize(0));

            SelectedFont = Font.FromName(FontData.FromFont(font).ToString());

            return(true);
        }
예제 #20
0
        public static NSFont GetNSFont(NativeControlVariant controlVariant, FigmaText text)
        {
            var fontWeight = GetNSFontWeight(text);

            if (controlVariant == NativeControlVariant.Regular)
            {
                // The system default Medium is slightly different, so let Cocoa handle that
                if (fontWeight == NSFontWeight.Medium)
                {
                    return(NSFont.SystemFontOfSize(NSFont.SystemFontSize));
                }
            }

            if (controlVariant == NativeControlVariant.Small)
            {
                // The system default Medium is slightly different, so let Cocoa handle that
                if (fontWeight == NSFontWeight.Medium)
                {
                    return(NSFont.SystemFontOfSize(NSFont.SmallSystemFontSize));
                }
                else
                {
                    return(NSFont.SystemFontOfSize(NSFont.SmallSystemFontSize, fontWeight));
                }
            }

            return(NSFont.SystemFontOfSize(GetNSFontSize(controlVariant), fontWeight));
        }
예제 #21
0
        static NSFont _ToNativeFont(string family, float size, FontAttributes attributes)
        {
            NSFont           defaultFont = NSFont.SystemFontOfSize(size);
            NSFont           font        = null;
            NSFontDescriptor descriptor  = null;
            var bold   = (attributes & FontAttributes.Bold) != 0;
            var italic = (attributes & FontAttributes.Italic) != 0;

            if (family != null && family != DefaultFontName)
            {
                try
                {
                    descriptor = new NSFontDescriptor().FontDescriptorWithFamily(family);
                    font       = NSFont.FromDescription(descriptor, size);

                    if (font == null)
                    {
                        var cleansedFont = CleanseFontName(family);
                        font = NSFont.FromFontName(cleansedFont, size);
                    }
                }
                catch
                {
                    Debug.WriteLine("Could not load font named: {0}", family);
                }
            }

            //if we didn't found a Font or Descriptor for the FontFamily use the default one
            if (font == null)
            {
                font       = defaultFont;
                descriptor = defaultFont.FontDescriptor;
            }

            if (descriptor == null)
            {
                descriptor = defaultFont.FontDescriptor;
            }


            if (bold || italic)
            {
                var traits = (NSFontSymbolicTraits)0;
                if (bold)
                {
                    traits |= NSFontSymbolicTraits.BoldTrait;
                }
                if (italic)
                {
                    traits |= NSFontSymbolicTraits.ItalicTrait;
                }

                var fontDescriptorWithTraits = descriptor.FontDescriptorWithSymbolicTraits(traits);

                font = NSFont.FromDescription(fontDescriptorWithTraits, size);
            }

            return(font.ScreenFontWithRenderingMode(NSFontRenderingMode.AntialiasedIntegerAdvancements));
        }
예제 #22
0
        protected override void OnViewModelChanged(PropertyViewModel oldModel)
        {
            base.OnViewModelChanged(oldModel);

            if (ViewModel == null)
            {
                return;
            }

            RightEdgeConstraint.Active = !ViewModel.HasInputModes;
            if (ViewModel.HasInputModes)
            {
                if (this.inputModePopup == null)
                {
                    this.inputModePopup = new FocusablePopUpButton {
                        Menu        = new NSMenu(),
                        ControlSize = NSControlSize.Small,
                        Font        = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                        TranslatesAutoresizingMaskIntoConstraints = false
                    };

                    this.inputModePopup.Activated += (o, e) => {
                        var popupButton = o as NSPopUpButton;
                        ViewModel.InputMode = this.viewModelInputModes.FirstOrDefault(im => im.Identifier == popupButton.Title);
                    };

                    AddSubview(this.inputModePopup);

                    this.editorInputModeConstraint = NSLayoutConstraint.Create(Entry, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.inputModePopup, NSLayoutAttribute.Left, 1, -4);

                    AddConstraints(new[] {
                        this.editorInputModeConstraint,
                        NSLayoutConstraint.Create(this.inputModePopup, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
                        NSLayoutConstraint.Create(this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
                        NSLayoutConstraint.Create(this.inputModePopup, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, DefaultButtonWidth),
                        NSLayoutConstraint.Create(this.inputModePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, Entry, NSLayoutAttribute.Height, 1, 0),
                    });

                    this.lastKeyView = this.inputModePopup;
                }

                this.inputModePopup.Menu.RemoveAllItems();
                this.viewModelInputModes = ViewModel.InputModes;
                foreach (InputMode item in this.viewModelInputModes)
                {
                    this.inputModePopup.Menu.AddItem(new NSMenuItem(item.Identifier));
                }
            }

            // If we are reusing the control we'll have to hid the inputMode if this doesn't have InputMode.
            if (this.inputModePopup != null)
            {
                this.inputModePopup.Hidden            = !ViewModel.HasInputModes;
                this.editorInputModeConstraint.Active = ViewModel.HasInputModes;
                UpdateAccessibilityValues();
            }

            SetEnabled();
        }
예제 #23
0
        public override float GetPreferredSize(object value, System.Drawing.SizeF cellSize, NSCell cell)
        {
            var font  = cell.Font ?? NSFont.SystemFontOfSize(NSFont.SystemFontSize);
            var str   = new NSString(Convert.ToString(value));
            var attrs = NSDictionary.FromObjectAndKey(font, NSAttributedString.FontAttributeName);

            return(str.StringSize(attrs).Width + 4);             // for border
        }
예제 #24
0
        public DialogResult ShowDialog(Window parent)
        {
            NSWindow parentWindow;

            if (parent != null)
            {
                if (parent.ControlObject is NSWindow)
                {
                    parentWindow = (NSWindow)parent.ControlObject;
                }
                else if (parent.ControlObject is NSView)
                {
                    parentWindow = ((NSView)parent.ControlObject).Window;
                }
                else
                {
                    parentWindow = NSApplication.SharedApplication.KeyWindow;
                }
            }
            else
            {
                parentWindow = NSApplication.SharedApplication.KeyWindow;
            }

            FontDialogHelper.Instance = new FontDialogHelper {
                Handler = this
            };

            Manager.Target = null;
            Manager.Action = null;
            if (Font != null)
            {
                var fontHandler = this.Font.Handler as FontHandler;
                Manager.SetSelectedFont(fontHandler.Control, false);
            }
            else
            {
                Manager.SetSelectedFont(NSFont.SystemFontOfSize(NSFont.SystemFontSize), false);
            }

            Control.Delegate = FontDialogHelper.Instance;
            Manager.Target   = FontDialogHelper.Instance;
            Manager.Action   = new Selector("changeFont:");

            if (parentWindow != null)
            {
                if (parentWindow == NSApplication.SharedApplication.ModalWindow)
                {
                    NSNotificationCenter.DefaultCenter.AddObserver(FontDialogHelper.Instance, new Selector("modalClosed:"), new NSString("NSWindowWillCloseNotification"), parentWindow);
                }
            }

            Manager.OrderFrontFontPanel(parentWindow);
            //if (isModal) Control.MakeKeyWindow();
            Control.MakeKeyAndOrderFront(parentWindow);

            return(DialogResult.None);            // signal that we are returning right away!
        }
예제 #25
0
 static NSAttributedString GetPopoverString(string text)
 {
     return(new NSAttributedString(text, new NSStringAttributes {
         ParagraphStyle = new NSMutableParagraphStyle {
             Alignment = NSTextAlignment.Center,
         },
         Font = NSFont.SystemFontOfSize(NSFont.SystemFontSize - 1),
     }));
 }
예제 #26
0
        public void NSFormatter_ShouldGetAttributedString()
        {
            var str = formatter.GetAttributedString(NSNumber.FromFloat(3.21f), new NSStringAttributes()
            {
                Font = NSFont.SystemFontOfSize(8)
            });

            Assert.AreEqual(str.Value, "$3.21");
        }
예제 #27
0
 void Initialize()
 {
     ControlSize     = NSControlSize.Regular;
     Font            = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(ControlSize));
     Bezeled         = false;
     DrawsBackground = false;
     Editable        = false;
     Selectable      = false;
 }
예제 #28
0
        public static NSFont GetNSFont(NativeControlVariant controlVariant)
        {
            if (controlVariant == NativeControlVariant.Small)
            {
                return(NSFont.SystemFontOfSize(NSFont.SmallSystemFontSize));
            }

            return(NSFont.SystemFontOfSize(NSFont.SystemFontSize));
        }
예제 #29
0
        /// <summary>
        /// Convert to a UIFont object
        /// </summary>
        /// <returns>The user interface font.</returns>
        /// <param name="Font">Font.</param>
        public static NSFont ToUIFont(this DSFont Font)
        {
            if (String.IsNullOrWhiteSpace(Font.FontFamily))
            {
                return((Font.FontWeight == FontWeight.Normal) ? NSFont.SystemFontOfSize(Font.FontSize) : NSFont.BoldSystemFontOfSize(Font.FontSize));
            }


            return(NSFont.FromFontName(Font.FontFamily, Font.FontSize));
        }
        internal NSTableCellView GetFTAnalyzerGridCell(NSTableView tableView, NSTableColumn tableColumn, nint row)
        {
            var index = Array.IndexOf(_fieldNames, tableColumn.Identifier);

            if (index < 0 || index > _properties.Length)
            {
                return(null);
            }
            var             property  = _properties[index];
            NSTextAlignment alignment = NSTextAlignment.Left;
            var             width     = tableColumn.Width;

            ColumnDetail[] x = property.GetCustomAttributes(typeof(ColumnDetail), false) as ColumnDetail[];
            if (x?.Length == 1)
            {
                alignment = x[0].Alignment;
                width     = x[0].ColumnWidth;
            }
            if (!(tableView.MakeView(CellIdentifier, this) is NSTableCellView cellView))
            {
                var textField = new NSTextField
                {
                    BackgroundColor     = NSColor.Clear,
                    LineBreakMode       = NSLineBreakMode.TruncatingTail,
                    Bordered            = false,
                    Selectable          = false,
                    Editable            = false,
                    Alignment           = alignment,
                    AutoresizingMask    = NSViewResizingMask.MinYMargin | NSViewResizingMask.WidthSizable,
                    AutoresizesSubviews = true,
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    AllowsDefaultTighteningForTruncation      = true,
                };
                if (tableView.AutosaveName == "PrintView")
                {
                    textField.Font = NSFont.SystemFontOfSize(8);
                }
                cellView = new NSTableCellView
                {
                    Identifier          = CellIdentifier,
                    TextField           = textField,
                    AutoresizesSubviews = true,
                    AutoresizingMask    = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable
                };
                cellView.AddSubview(textField);
                var views = new NSMutableDictionary
                {
                    { new NSString("textField"), textField }
                };
                cellView.AddConstraints(NSLayoutConstraint.FromVisualFormat($"H:|[textField({width}@750)]|", NSLayoutFormatOptions.AlignAllTop, null, views));
                cellView.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|[textField]|", NSLayoutFormatOptions.AlignAllTop, null, views));
                NSLayoutConstraint.ActivateConstraints(cellView.Constraints);
            }
            return(cellView);
        }