public async Task AutoSizeInitializesCorrectly(EditorAutoSizeOption option) { var editor = new Editor { AutoSize = option, Text = "Test" }; IView layout = new VerticalStackLayout() { Children = { editor } }; await CreateHandlerAndAddToWindow <LayoutHandler>(layout, (_) => { layout.Arrange(new Graphics.Rect(Graphics.Point.Zero, layout.Measure(1000, 1000))); var initialHeight = editor.Height; editor.Text += Environment.NewLine + " Some new text" + Environment.NewLine; layout.Arrange(new Graphics.Rect(Graphics.Point.Zero, layout.Measure(1000, 1000))); if (option == EditorAutoSizeOption.Disabled) { Assert.Equal(initialHeight, editor.Height); } else { Assert.True(initialHeight < editor.Height); } return(Task.CompletedTask); }); }
public async Task AutoSizeInitializesCorrectly(EditorAutoSizeOption option) { var editor = new Editor { AutoSize = option, Text = "Test" }; IView layout = new VerticalStackLayout() { Children = { editor } }; await InvokeOnMainThreadAsync(() => { _ = CreateHandler <LayoutHandler>(layout); layout.Arrange(new Graphics.Rectangle(Graphics.Point.Zero, layout.Measure(1000, 1000))); var initialHeight = editor.Height; editor.Text += Environment.NewLine + " Some new text" + Environment.NewLine; layout.Arrange(new Graphics.Rectangle(Graphics.Point.Zero, layout.Measure(1000, 1000))); if (option == EditorAutoSizeOption.Disabled) { Assert.Equal(initialHeight, editor.Height); } else { Assert.True(initialHeight < editor.Height); } }); }
protected override void Init() { StackLayout container = new StackLayout() { BackgroundColor = Color.Purple }; StackLayout layout = new StackLayout() { BackgroundColor = Color.Pink, HeightRequest = 200 }; var editor = new Editor() { BackgroundColor = Color.Green, MinimumHeightRequest = 10, AutoSize = EditorAutoSizeOption.TextChanges, AutomationId = editorHeightShrinkWithPressureId }; var editorHeightGrow = new Editor() { BackgroundColor = Color.Green, MinimumHeightRequest = 200, AutoSize = EditorAutoSizeOption.TextChanges, AutomationId = editorHeightGrowId }; layout.Children.Add(editor); layout.Children.Add(editorHeightGrow); StackLayout layoutHorizontal = new StackLayout() { BackgroundColor = Color.Yellow, Orientation = StackOrientation.Horizontal }; var editorWidthGrow1 = new Editor() { BackgroundColor = Color.Green, MinimumWidthRequest = 10, AutoSize = EditorAutoSizeOption.TextChanges, AutomationId = editorWidthGrow1Id }; var editorWidthGrow2 = new Editor() { BackgroundColor = Color.Green, MinimumWidthRequest = 200, AutoSize = EditorAutoSizeOption.TextChanges, AutomationId = editorWidthGrow2Id, ClassId = editorWidthGrow2Id }; layoutHorizontal.Children.Add(editorWidthGrow1); layoutHorizontal.Children.Add(editorWidthGrow2); container.Children.Add(layout); container.Children.Add(layoutHorizontal); List <Editor> editors = new List <Editor>() { editor, editorHeightGrow, editorWidthGrow1, editorWidthGrow2 }; Button buttonChangeFont = new Button() { Text = btnChangeFontToLarger }; Button buttonChangeText = new Button() { Text = btnChangeToHasText }; Button buttonChangeSizeOption = new Button() { Text = btnChangeSizeOption }; double fontSizeInitial = editor.FontSize; buttonChangeFont.Clicked += (x, y) => { editors.ForEach(e => { if (e.FontSize == fontSizeInitial) { e.FontSize = 40; Device.BeginInvokeOnMainThread(() => buttonChangeFont.Text = btnChangeFontToDefault); } else { e.FontSize = fontSizeInitial; Device.BeginInvokeOnMainThread(() => buttonChangeFont.Text = btnChangeFontToLarger); } }); }; buttonChangeText.Clicked += (_, __) => { editors.ForEach(e => { if (String.IsNullOrWhiteSpace(e.Text)) { e.Text = String.Join(" ", Enumerable.Range(0, 100).Select(x => "f").ToArray()); Device.BeginInvokeOnMainThread(() => buttonChangeText.Text = btnChangeToNoText); } else { e.Text = String.Empty; Device.BeginInvokeOnMainThread(() => buttonChangeText.Text = btnChangeToHasText); } }); }; buttonChangeSizeOption.Clicked += (_, __) => { editors.ForEach(e => { EditorAutoSizeOption option = EditorAutoSizeOption.TextChanges; if (e.AutoSize == option) { option = EditorAutoSizeOption.Disabled; } e.AutoSize = option; }); }; StackLayout commands = new StackLayout(); commands.Children.Add(buttonChangeFont); commands.Children.Add(buttonChangeText); commands.Children.Add(buttonChangeSizeOption); Label sizeOption = new Label(); sizeOption.SetBinding(Label.TextProperty, new Binding(nameof(Editor.AutoSize), source: editor)); container.Children.Add(sizeOption); var valueConverter = new InvariantConverter(); editors.ForEach(e => { StackLayout commandLayout = new StackLayout() { Orientation = StackOrientation.Horizontal }; commands.Children.Add(commandLayout); Label automationLabelId = new Label(); automationLabelId.SetBinding(Label.TextProperty, new Binding(nameof(Editor.AutomationId), source: e)); Label width = new Label(); width.SetBinding(Label.TextProperty, new Binding(nameof(Editor.Width), source: e, converter: valueConverter)); width.AutomationId = e.AutomationId + "_width"; Label height = new Label(); height.SetBinding(Label.TextProperty, new Binding(nameof(Editor.Height), source: e, converter: valueConverter)); height.AutomationId = e.AutomationId + "_height"; commandLayout.Children.Add(automationLabelId); commandLayout.Children.Add(width); commandLayout.Children.Add(height); }); StackLayout content = new StackLayout(); content.Children.Add(new ScrollView() { Content = container }); content.Children.Add(commands); Content = content; }
SizeRequest CalculateDesiredSizes(FormsTextBox control, global::Windows.Foundation.Size constraint, EditorAutoSizeOption sizeOption) { if (sizeOption == EditorAutoSizeOption.TextChanges) { Size result = GetCopyOfSize(control, constraint); control.Measure(constraint); return(new SizeRequest(result)); } else { control.Measure(constraint); Size result = new Size(Math.Ceiling(control.DesiredSize.Width), Math.Ceiling(control.DesiredSize.Height)); return(new SizeRequest(result)); } }
public static Editor AutoSize(this Editor editor, EditorAutoSizeOption autoSize) { editor.AutoSize = autoSize; return(editor); }
public static T AutoSize <T>(this T editor, EditorAutoSizeOption autoSize) where T : IRxEditor { editor.AutoSize = autoSize; return(editor); }