From 4818b79fde4bfa6d398967bda0b5590fe8c805f4 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Fri, 8 Mar 2024 12:58:51 -0800 Subject: [PATCH] Mac: Fix Rich/TextArea to show text when initially shown. Fixes #2617 --- src/Eto.Mac/Forms/Controls/TextAreaHandler.cs | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/Eto.Mac/Forms/Controls/TextAreaHandler.cs b/src/Eto.Mac/Forms/Controls/TextAreaHandler.cs index b55a896981..330ada5fd0 100644 --- a/src/Eto.Mac/Forms/Controls/TextAreaHandler.cs +++ b/src/Eto.Mac/Forms/Controls/TextAreaHandler.cs @@ -22,8 +22,6 @@ public interface ITextAreaHandler Range lastSelection { get; set; } int? lastCaretIndex { get; set; } - - void PerformLayout(); } public class EtoTextAreaDelegate : NSTextViewDelegate @@ -81,7 +79,7 @@ public EtoTextView(ITextAreaHandler handler) { Delegate = new EtoTextAreaDelegate { Handler = handler }; AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable; - HorizontallyResizable = true; + HorizontallyResizable = false; VerticallyResizable = true; Editable = true; RichText = false; @@ -92,15 +90,6 @@ public EtoTextView(ITextAreaHandler handler) MaxSize = new CGSize(float.MaxValue, float.MaxValue); TextContainer.WidthTracksTextView = true; } - - public override void Layout() - { - if (MacView.NewLayout) - base.Layout(); - (Handler as ITextAreaHandler)?.PerformLayout(); - if (!MacView.NewLayout) - base.Layout(); - } } public class TextAreaHandler : MacView, TextArea.IHandler, ITextAreaHandler @@ -294,19 +283,28 @@ public Font Font public bool Wrap { - get - { - return Control.TextContainer.WidthTracksTextView; - } + get => Control.TextContainer.WidthTracksTextView; set { + if (value == Wrap) + return; + if (value) { + Control.HorizontallyResizable = false; Control.TextContainer.WidthTracksTextView = true; - Control.NeedsLayout = true; + if (Widget.Loaded) + { + // shrink the control and text container to the current width of the visible rectangle + var width = Scroll.DocumentVisibleRect.Size.Width; + Control.SetFrameSize(new CGSize(width, Control.Frame.Height)); + Control.TextContainer.Size = new CGSize(width, float.MaxValue); + Control.NeedsLayout = true; + } } else { + Control.HorizontallyResizable = true; Control.TextContainer.WidthTracksTextView = false; Control.TextContainer.ContainerSize = new CGSize(float.MaxValue, float.MaxValue); } @@ -414,15 +412,6 @@ TextArea ITextAreaHandler.Widget get { return Widget; } } - public void PerformLayout() - { - if (Wrap) - { - // set width of content to the size of the control when wrapping - Control.TextContainer.ContainerSize = new CGSize(Scroll.DocumentVisibleRect.Size.Width, float.MaxValue); - } - } - public TextReplacements TextReplacements { get