Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Fix clipping of controls #2505

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/Eto.Mac/Forms/Controls/DrawableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ public override void DrawRect(CGRect dirtyRect)
var drawable = Drawable;
if (drawable == null)
return;
// restrict drawing to the bounds of the drawable
// macOS can give us dirty rects outside this range
var bounds = Bounds.ToEto();
var dirty = dirtyRect.ToEto();
dirty.Restrict(bounds);

if (!IsFlipped)
dirtyRect.Y = Frame.Height - dirtyRect.Y - dirtyRect.Height;
if (dirtyRect.X % 1.0f > 0f)
dirtyRect.Width += 1;
if (dirtyRect.Y % 1.0f > 0f)
dirtyRect.Height += 1;
dirty.Y = bounds.Height - dirty.Y - dirty.Height;
if (dirty.X % 1.0f > 0f)
dirty.Width += 1;
if (dirty.Y % 1.0f > 0f)
dirty.Height += 1;
ApplicationHandler.QueueResizing = true;
drawable.DrawRegion(Rectangle.Ceiling(dirtyRect.ToEto()));
drawable.DrawRegion(Rectangle.Ceiling(dirty));
ApplicationHandler.QueueResizing = false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Eto.Mac/Forms/Controls/ExpanderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void UpdateExpandedState()
{
ctx.Duration = 0;
((NSView)content.Animator).Frame = startFrame;
content.SetClipsToBounds(true);
}, () => NSAnimationContext.RunAnimation(ctx =>
{
ctx.Duration = AnimationDuration;
Expand All @@ -147,6 +148,7 @@ void UpdateExpandedState()
suspendContentSizing--;
content.Hidden = !Expanded;
Callback.OnExpandedChanged(Widget, EventArgs.Empty);
content.SetClipsToBounds(false);
InvalidateMeasure();
}
)
Expand Down
4 changes: 4 additions & 0 deletions src/Eto.Mac/Forms/Controls/MacEventView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public MacEventView()
BorderWidth = 0;
BorderType = NSBorderType.NoBorder;
ContentViewMargins = CGSize.Empty;

// disable clipping to bounds so buttons/etc aren't clipped, 10.9+
this.SetClipsToBounds(false);
(ContentView as NSView)?.SetClipsToBounds(false);
}

public MacEventView(IntPtr handle)
Expand Down
2 changes: 2 additions & 0 deletions src/Eto.Mac/Forms/Controls/NumericStepperHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public EtoNumericStepperView(NumericStepperHandler handler)

AddSubview(TextField);
AddSubview(Stepper);

this.SetClipsToBounds(false);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/Eto.Mac/MacExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ public static CGSize ContentSizeForFrame(this NSScrollView scrollView, CGSize si
return Messaging.CGSize_objc_msgSend_CGSize_IntPtr_IntPtr_UInt64_UInt64_Int64(scrollView.ClassHandle, selContentSizeForFrameSize_HorizontalScrollerClass_VerticalScrollerClass_BorderType_ControlSize_ScrollerStyle_Handle, size, hbarPtr, vbarPtr, (ulong)scrollView.BorderType, (ulong)scrollView.VerticalScroller.ControlSize, (long)scrollView.VerticalScroller.ScrollerStyle);
}


static readonly IntPtr selSetClipsToBounds = Selector.GetHandle("setClipsToBounds:");
static readonly bool supportsClipsToBounds = ObjCExtensions.InstancesRespondToSelector<NSView>(selSetClipsToBounds);

public static void SetClipsToBounds(this NSView view, bool clipsToBounds)
{
if (!supportsClipsToBounds)
return;
Messaging.void_objc_msgSend_bool(view.Handle, selSetClipsToBounds, clipsToBounds);
}
}
}