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 Rich/TextArea to show text when initially shown. #2631

Merged
Merged
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
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
Loading