protected virtual nfloat GetRowWidth(ICellHandler cell, int row, CGSize cellSize) { var item = DataViewHandler.GetItem(row); var val = GetObjectValue(item); return(cell.GetPreferredSize(val, cellSize, row, item)); }
public override void SetContentSize(CGSize contentSize) { if (MinimumSize != Size.Empty) { contentSize.Width = (nfloat)Math.Max(contentSize.Width, MinimumSize.Width); contentSize.Height = (nfloat)Math.Max(contentSize.Height, MinimumSize.Height); } if (Widget.Loaded) { var diffy = ClientSize.Height - (int)contentSize.Height; var diffx = ClientSize.Width - (int)contentSize.Width; var frame = Control.Frame; if (diffx < 0 || !setInitialSize) { frame.Width -= diffx; } if (diffy < 0 || !setInitialSize) { frame.Y += diffy; frame.Height -= diffy; } Control.SetFrame(frame, false, false); } else { Control.SetContentSize(contentSize); } }
public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell) { cell.ObjectValue = value as NSObject; var size = cell.CellSizeForBounds(new CGRect(0, 0, nfloat.MaxValue, cellSize.Height)).Width; return(size); }
public static NSImage ToNS(this Image image, int?size = null) { if (image == null) { return(null); } var source = image.Handler as IImageSource; if (source == null) { return(null); } var nsimage = source.GetImage(); if (size != null) { var rep = nsimage.BestRepresentation(new CGRect(0, 0, size.Value, size.Value), null, null); if (rep.PixelsWide > size.Value || rep.PixelsHigh > size.Value) { var max = Math.Max(nsimage.Size.Width, nsimage.Size.Height); var newsize = new CGSize((int)(size.Value * nsimage.Size.Width / max), (int)(size.Value * nsimage.Size.Height / max)); nsimage = nsimage.Resize(newsize); } else { nsimage = new NSImage(); nsimage.AddRepresentation(rep); } } return(nsimage); }
// not bound public static CGRect BoundingRect(this NSAttributedString str, CGSize size, NSStringDrawingOptions options) { CGRect rect; RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options); return(rect); }
public override void SetFrameSize(CGSize newSize) { base.SetFrameSize(newSize); if (setBezel) { Handler.SetBezel(); } }
public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell) { var font = cell.Font ?? NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize); var str = new NSString(Convert.ToString(value)); var attrs = NSDictionary.FromObjectAndKey(font, NSStringAttributeKey.Font); return((float)str.StringSize(attrs).Width + 8); // for border }
public nfloat GetPreferredSize(object value, CGSize cellSize, int row, object dataItem) { if (copy == null) { copy = Control.Copy() as NSCell; } ColumnHandler.DataViewHandler.OnCellFormatting(ColumnHandler.Widget, dataItem, row, copy); return(GetPreferredSize(value, cellSize, copy)); }
public override void SetFrameSize(CGSize newSize) { if (((SliderHandler)Handler).Orientation == Orientation.Horizontal && newSize.Width < newSize.Height) { // prevent slider from flipping to vertical orientation when resized newSize.Height = newSize.Width; } base.SetFrameSize(newSize); }
public override void SetFrameSize(CGSize newSize) { base.SetFrameSize(newSize); if (!autoSized) { autoSized = Handler.AutoSizeColumns(); } }
public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem) { var img = value as Image; if (img != null) { return(cellSize.Height / img.Size.Height * img.Size.Width); } return(16); }
public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell) { var img = value as Image; if (img != null) { return((float)(cellSize.Height / (float)img.Size.Height * (float)img.Size.Width)); } return(16); }
public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem) { var args = new MacCellFormatArgs(ColumnHandler.Widget, dataItem, row, field); ColumnHandler.DataViewHandler.Callback.OnCellFormatting(ColumnHandler.DataViewHandler.Widget, args); field.Font = args.Font.ToNS() ?? NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize); field.ObjectValue = value as NSObject; return(field.Cell.CellSizeForBounds(new CGRect(0, 0, nfloat.MaxValue, cellSize.Height)).Width); }
public override void SetFrameSize(CGSize newSize) { base.SetFrameSize(newSize); var views = Subviews; var text = views[0]; var splitter = views[1]; var offset = (newSize.Height - text.Frame.Height) / 2; text.SetFrameOrigin(new CGPoint(0, offset)); text.SetFrameSize(new CGSize((float)(newSize.Width - splitter.Frame.Width), (float)text.Frame.Height)); offset = (newSize.Height - splitter.Frame.Height) / 2; splitter.SetFrameOrigin(new CGPoint(newSize.Width - splitter.Frame.Width, offset)); }
public static NSImage Resize(this NSImage image, CGSize newsize, ImageInterpolation interpolation = ImageInterpolation.Default) { var newimage = new NSImage(newsize); var newrep = new NSBitmapImageRep(IntPtr.Zero, (nint)newsize.Width, (nint)newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * (nint)newsize.Width, 32); newimage.AddRepresentation(newrep); var graphics = NSGraphicsContext.FromBitmap(newrep); NSGraphicsContext.GlobalSaveGraphicsState(); NSGraphicsContext.CurrentContext = graphics; graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG(); image.DrawInRect(new CGRect(CGPoint.Empty, newimage.Size), new CGRect(CGPoint.Empty, image.Size), NSCompositingOperation.SourceOver, 1f); NSGraphicsContext.GlobalRestoreGraphicsState(); return newimage; }
static void SetFrameSizeAction(IntPtr sender, IntPtr sel, CGSize size) { var obj = Runtime.GetNSObject(sender); Messaging.void_objc_msgSendSuper_SizeF(obj.SuperHandle, sel, size); var handler = GetHandler(obj) as IMacViewHandler; if (handler != null) { handler.OnSizeChanged(EventArgs.Empty); handler.Callback.OnSizeChanged(handler.Widget, EventArgs.Empty); } }
void SetPattern() { sectionSize = new CGSize((EndPoint.X - StartPoint.X) + 1, (EndPoint.Y - StartPoint.Y) + 1); if (Wrap == GradientWrapMode.Reflect) { tileSize = new CGSize(sectionSize.Width * 4, sectionSize.Height * 4); } else { tileSize = new CGSize(sectionSize.Width * 2, sectionSize.Height * 2); } var rect = new CGRect(StartPoint, tileSize); var t = CGAffineTransform.Multiply(transform, viewTransform); pattern = new CGPattern(rect, t, rect.Width, rect.Height, CGPatternTiling.NoDistortion, true, DrawPattern); }
public static NSImage Resize(this NSImage image, CGSize newsize, ImageInterpolation interpolation = ImageInterpolation.Default) { var newimage = new NSImage(newsize); var newrep = new NSBitmapImageRep(IntPtr.Zero, (nint)newsize.Width, (nint)newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * (nint)newsize.Width, 32); newimage.AddRepresentation(newrep); var graphics = NSGraphicsContext.FromBitmap(newrep); NSGraphicsContext.GlobalSaveGraphicsState(); NSGraphicsContext.CurrentContext = graphics; graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG(); image.DrawInRect(new CGRect(CGPoint.Empty, newimage.Size), new CGRect(CGPoint.Empty, image.Size), NSCompositingOperation.SourceOver, 1f); NSGraphicsContext.GlobalRestoreGraphicsState(); return(newimage); }
public override void SetContentSize(CGSize contentSize) { if (MinimumSize != Size.Empty) { contentSize.Width = (nfloat)Math.Max(contentSize.Width, MinimumSize.Width); contentSize.Height = (nfloat)Math.Max(contentSize.Height, MinimumSize.Height); } if (ExpandContentWidth) { contentSize.Width = (nfloat)Math.Max(ClientSize.Width, contentSize.Width); } if (ExpandContentHeight) { contentSize.Height = (nfloat)Math.Max(ClientSize.Height, contentSize.Height); } InternalSetFrameSize(contentSize); }
public override void SetContentSize(CGSize contentSize) { base.SetContentSize(contentSize); if (MinimumSize != Size.Empty) { contentSize.Width = (nfloat)Math.Max(contentSize.Width, MinimumSize.Width); contentSize.Height = (nfloat)Math.Max(contentSize.Height, MinimumSize.Height); } if (Widget.Content != null) { var child = Widget.Content.Handler as IMacContainer; if (child != null) { child.SetContentSize(contentSize); } } }
public EtoTextView(ITextAreaHandler handler) { Delegate = new EtoTextAreaDelegate { Handler = handler }; AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable; HorizontallyResizable = true; VerticallyResizable = true; Editable = true; RichText = false; AllowsDocumentBackgroundColorChange = false; Selectable = true; AllowsUndo = true; MinSize = CGSize.Empty; MaxSize = new CGSize(float.MaxValue, float.MaxValue); TextContainer.WidthTracksTextView = true; }
public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell) { var val = value as MacImageData; if (val == null) { return(0); } var font = cell.Font ?? NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize); var str = val.Text; var attrs = NSDictionary.FromObjectAndKey(font, NSAttributedString.FontAttributeName); var size = str.StringSize(attrs).Width + 4 + 16 + MacImageListItemCell.ImagePadding * 2; // for border + image return((float)size); }
public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem) { var args = new MacCellFormatArgs(ColumnHandler.Widget, dataItem, row, field); ColumnHandler.DataViewHandler.Callback.OnCellFormatting(ColumnHandler.DataViewHandler.Widget, args); field.Font = defaultFont; if (args.FontSet) { field.Font = args.Font.ToNS(); } if (field.Title != menu.Title) { field.Menu = menu.Copy() as NSMenu; } field.ObjectValue = value as NSObject; return(field.Cell.CellSizeForBounds(new CGRect(0, 0, nfloat.MaxValue, cellSize.Height)).Width); }
void InternalSetFrameSize(CGSize size) { var view = ContentControl; if (!view.IsFlipped) { var ctl = Content.GetContainerView(); if (ctl != null) { var clientHeight = Control.DocumentVisibleRect.Size.Height; ctl.Frame = new CGRect(new CGPoint(0, (nfloat)Math.Max(0, clientHeight - size.Height)), size); size.Height = (nfloat)Math.Max(clientHeight, size.Height); } } if (size != view.Frame.Size) { view.SetFrameSize(size); } }
public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem) { var args = new CellEventArgs(row, dataItem, CellStates.None); var identifier = Callback.OnGetIdentifier(Widget, args) ?? string.Empty; Control widthCell; if (!widthCells.TryGetValue(identifier, out widthCell)) { widthCell = Callback.OnCreateCell(Widget, args); if (widthCell == null) { return(Callback.OnGetPreferredWidth(Widget, args)); } widthCell.ToNative(true); widthCells.Add(identifier, widthCell); } Callback.OnConfigureCell(Widget, args, widthCell); var result = widthCell.GetPreferredSize(SizeF.MaxValue).Width; widthCell.DataContext = null; return(result); //return Callback.OnGetPreferredWidth(Widget, new CellEventArgs(row, dataItem, CellStates.None)); }
public static SizeF ToEto(this CGSize point) { return(new SizeF((float)point.Width, (float)point.Height)); }
public static extern void void_objc_msgSendSuper_SizeF(IntPtr receiver, IntPtr selector, CGSize arg1);
public override void LayoutChildren() { if (!Widget.Loaded || views == null || NeedsQueue()) return; var heights = new float[views.GetLength(0)]; var widths = new float[views.GetLength(1)]; var controlFrame = ContentControl.Frame; float totalxpadding = Padding.Horizontal + Spacing.Width * (widths.Length - 1); float totalypadding = Padding.Vertical + Spacing.Height * (heights.Length - 1); var totalx = (float)controlFrame.Width - totalxpadding; var totaly = (float)controlFrame.Height - totalypadding; var requiredx = totalxpadding; var requiredy = totalypadding; var numx = 0; var numy = 0; for (int y = 0; y < heights.Length; y++) { heights[y] = 0; if (yscaling[y] || lastyscale == y) numy++; } for (int x = 0; x < widths.Length; x++) { widths[x] = 0; if (xscaling[x] || lastxscale == x) numx++; } var availableSize = Size.Max(Size.Empty, Control.Frame.Size.ToEtoSize() - new Size((int)requiredx, (int)requiredy)); for (int y = 0; y < heights.Length; y++) for (int x = 0; x < widths.Length; x++) { var view = views[y, x]; if (view != null && view.Visible) { var size = view.GetPreferredSize(availableSize); if (!xscaling[x] && lastxscale != x && widths[x] < size.Width) { requiredx += size.Width - widths[x]; widths[x] = size.Width; } if (!yscaling[y] && lastyscale != y && heights[y] < size.Height) { requiredy += size.Height - heights[y]; heights[y] = size.Height; } } } if (controlFrame.Width < requiredx) { totalx = requiredx - totalxpadding; } if (controlFrame.Height < requiredy) { totaly = requiredy - totalypadding; } for (int y = 0; y < heights.Length; y++) if (!yscaling[y] && lastyscale != y) totaly -= heights[y]; for (int x = 0; x < widths.Length; x++) if (!xscaling[x] && lastxscale != x) totalx -= widths[x]; var chunkx = (numx > 0) ? (float)Math.Truncate(Math.Max(totalx, 0) / numx) : totalx; var chunky = (numy > 0) ? (float)Math.Truncate(Math.Max(totaly, 0) / numy) : totaly; #if OSX bool flipped = Control.IsFlipped; #elif IOS bool flipped = !Control.Layer.GeometryFlipped; #endif float starty = Padding.Top; for (int x = 0; x < widths.Length; x++) { if (xscaling[x] || lastxscale == x) { widths[x] = Math.Min(chunkx, totalx); totalx -= chunkx; } } for (int y = 0; y < heights.Length; y++) { if (yscaling[y] || lastyscale == y) { heights[y] = Math.Min(chunky, totaly); totaly -= chunky; } float startx = Padding.Left; for (int x = 0; x < widths.Length; x++) { var view = views[y, x]; if (view != null && view.Visible) { var nsview = view.GetContainerView(); var frame = nsview.Frame; var oldframe = frame; frame.Width = widths[x]; frame.Height = heights[y]; frame.X = Math.Max(0, startx); frame.Y = flipped ? starty : controlFrame.Height - starty - frame.Height; if (frame != oldframe) nsview.Frame = frame; else if (oldframe.Right > oldFrameSize.Width || oldframe.Bottom > oldFrameSize.Height || frame.Right > oldFrameSize.Width || frame.Bottom > oldFrameSize.Height) nsview.SetNeedsDisplay(); //Console.WriteLine("*** x:{2} y:{3} view: {0} size: {1} totalx:{4} totaly:{5}", view, view.Size, x, y, totalx, totaly); } startx += widths[x] + Spacing.Width; } starty += heights[y] + Spacing.Height; } oldFrameSize = controlFrame.Size; }
// not bound public static CGRect BoundingRect(this NSAttributedString str, CGSize size, NSStringDrawingOptions options) { CGRect rect; Messaging.RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options); return rect; }
public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell) { return(25); }
public static NSImage ToNS(this Image image, int? size = null) { if (image == null) return null; var source = image.Handler as IImageSource; if (source == null) return null; var nsimage = source.GetImage(); if (size != null) { var rep = nsimage.BestRepresentation(new CGRect(0, 0, size.Value, size.Value), null, null); if (rep.PixelsWide > size.Value || rep.PixelsHigh > size.Value) { var max = Math.Max(nsimage.Size.Width, nsimage.Size.Height); var newsize = new CGSize((int)(size.Value * nsimage.Size.Width / max), (int)(size.Value * nsimage.Size.Height / max)); nsimage = nsimage.Resize(newsize); } else { nsimage = new NSImage(); nsimage.AddRepresentation(rep); } } return nsimage; }
public abstract nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell);
static extern void RectangleF_objc_msgSend_stret_SizeF_int(out CGRect retval, IntPtr receiver, IntPtr selector, CGSize arg1, nint arg2);
public override void SetContentSize(CGSize contentSize) { Control.SetFrameFromContentFrame(new CGRect(0, 0, contentSize.Width, contentSize.Height)); }
public static System.Drawing.SizeF ToSD(this CGSize size) { return(new System.Drawing.SizeF((float)size.Width, (float)size.Height)); }
public static Size ToEtoSize(this CGSize size) { return(new Size((int)size.Width, (int)size.Height)); }