Skip to content

Commit

Permalink
Merge pull request #2631 from cwensley/curtis/mac-fix-textarea-visibi…
Browse files Browse the repository at this point in the history
…lity

Mac: Fix Rich/TextArea to show text when initially shown.
  • Loading branch information
cwensley authored Mar 8, 2024
2 parents 2753ba5 + 4818b79 commit 868ffe8
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions src/Eto.Mac/Forms/Controls/TextAreaHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public interface ITextAreaHandler

Range<int> lastSelection { get; set; }
int? lastCaretIndex { get; set; }

void PerformLayout();
}

public class EtoTextAreaDelegate : NSTextViewDelegate
Expand Down Expand Up @@ -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;
Expand All @@ -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<TControl, TCallback> : MacView<NSTextView, TControl, TCallback>, TextArea.IHandler, ITextAreaHandler
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 868ffe8

Please sign in to comment.