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

TextFormatter.Lines should return a single string.Empty list even with Width or Height equal to zero. #3224

Closed
BDisp opened this issue Jan 31, 2024 · 7 comments

Comments

@BDisp
Copy link
Collaborator

BDisp commented Jan 31, 2024

I'll fix this in the #3181 because I already have a branch of it on another wip branch.

BDisp added a commit to BDisp/Terminal.Gui that referenced this issue Jan 31, 2024
…Empty list even with Width or Height equal to zero.
@BDisp
Copy link
Collaborator Author

BDisp commented Feb 2, 2024

Due this fix if a View initialize with AutoSize as false setting the Height doesn't ensures that a view is drawn unless the Dim properties or the Frame are defined. Is the case of the Generic scenario where it's initializing a Button with AutoSize = false and without define a dimension. Thus doesn't make any sense to define Height = 1 in the constructor because if the Width = 0 nothing is drawn anyway.
I'll will fix this in the #3181.

BDisp added a commit to BDisp/Terminal.Gui that referenced this issue Feb 2, 2024
@tig
Copy link
Collaborator

tig commented Feb 6, 2024

I'll fix this in the #3181 because I already have a branch of it on another wip branch.

Please don't.

I already have enough merge issues there AND I did a ton of TF fixes in #3202, which I am going to pull out into a separate PR.

@BDisp
Copy link
Collaborator Author

BDisp commented Feb 6, 2024

I want to use these changes in the #2489. It's almost ready. I'm only struggle when I use the Pos.Center on the view location and it's drawing outside the view padding.

@tig
Copy link
Collaborator

tig commented Feb 6, 2024

I want to use these changes in the #2489. It's almost ready. I'm only struggle when I use the Pos.Center on the view location and it's drawing outside the view padding.

You'll have to wait until I'm done merging #3181 and #3202. Sorry.

If you want, you can try to take the TextFormatter.cs from #3202 and create a new branch that uses it. However, this requires touching a ton of files because I changed TextFormatter significantly in #3202 (which I shouldn't have done, but I did). In particular I changed Lines to be GetLines () because it being a property getter was causing chaos in the debugger.

If you do this, DO NOT apply any code reformatting.

tig added a commit that referenced this issue Feb 11, 2024
…` functionality/unit tests (#3202)

* Removed resharper settings from editorconfig

* Remove constructors with frame parameters from Button class.

* Remove constructors with frame parameters from CheckBox class.

* Cleanup code.

* Remove constructors with frame parameters from ComboBox class.

* @BDisp
Remove constructors with frame parameters from FrameView class.

* Remove constructors with frame parameters from Label class.

* Remove constructors with frame parameters from ListView class.

* Remove constructors with frame parameters from ScrollBarView class.

* Remove constructors with frame parameters from ScrollView class.

* Remove namespace braces.

* Cleanup code.

* Cleanup code.

* Cleanup code.

* Remove constructors with frame parameters from TextField class.

* Remove constructors with frame parameters from TimeField class.

* Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty.

* Remove constructors with frame parameters from Toplevel class.

* Remove constructors with frame parameters from Window class.

* Fix merge errors.

* Revert "Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty."

This reverts commit cf9c24b.

* Revert unit test.

* Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame (#2980)

* Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame

* Trying fix this unit test that sometimes fail.

* Fixes #2983. View need a alternative DrawFrame for the v2.

* Use new DrawFrame method.

* Change _lines field to Lines property.

* Add TabWindow unit test.

* Add DrawIncompleteFrame method and unit tests.

* Add more unit tests to LineCanvas.

* Fix newline conflict errors.

* Revert "Change _lines field to Lines property."

This reverts commit ab6c5f3.

* Add DrawIncompleteFrame method and unit tests.

* Add more unit tests to LineCanvas.

* Fix newline conflict errors.

* Force render immediately instead of join.

* I will never rely on zero-location-based unit test again.

* Fix TestTreeViewColor unit test fail.

* Using location of 3 to avoid be divisible by 2 and so avoiding bugs.

* Revert "Using location of 3 to avoid be divisible by 2 and so avoiding bugs."

This reverts commit dd3df13.

* Revert "I will never rely on zero-location-based unit test again."

This reverts commit 62adf6f.

* Revert "Fix newline conflict errors."

This reverts commit 4acf726.

* Revert "Add more unit tests to LineCanvas."

This reverts commit 66bc6f5.

* Revert "Add DrawIncompleteFrame method and unit tests."

This reverts commit 680ba26.

* Resolving merge conflicts.

* Revert "Use new DrawFrame method."

This reverts commit 69a7f17.

* Revert "Fixes #2983. View need a alternative DrawFrame for the v2."

This reverts commit dade9fd.

* Reverting this changes to start a new one.

* Add horizontal and vertical support for combining glyphs.

* Fix text and auto size behavior.

* Add TabWidth property.

* Add unit test for WordWrap.

* Fixes #3017. View TextDirection returns incorrect size on a vertical direction instance with AutoSize as false.

* Using Frame to force read from the get method.

* Fix some issues with AutoSize and ForceValidatePosDim.

* Fixing broken unit tests.

* Restoring code I've broken.

* Removing forgotten code.

* Only LayoutStyle.Computed can change the Frame.

* DateField and TimeField depends on LayoutStyle.Computed.

* Fix unit tests related with LayoutStyle.

* Implements tabs, left and right arrows as View.

* Draws a minimum full border.

* Adds missing XML parameter.

* Adds assert tests for Frame.

* Removes duplicates InlineData.

* Adds more unit tests for minimum full border without Left and Right thickness.

* Trying to fix the TestTreeViewColor unit test fail.

* Prevents a user to set TextDirection to -1.

* Prevents any invalid TextDirection value.

* Removes (TextDirection)(-1).

* Removes unnecessary TextDirection initialization.

* Removes LayoutStyle.

* Fixing unit tests with border.

* Trying to fix TestTreeViewColor again.

* Revert "Trying to fix TestTreeViewColor again."

This reverts commit c2efa8e.

* Trying to fix TestTreeViewColor again.

* Fix merge errors.

* Fix merge errors.

* Restoring unit test.

* Restores the right XML comment.

* Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes.

* Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes.

* Only call OnResizeNeeded if it's LayoutStyle.Computed.

* Fix merge errors.

* Fix merge errors.

* Fix unit tests fail.

* Reformat.

* Again.

* Rename to OnDrawAdornments.

* Fix failing unit tests.

* Reduces indentation and cleanup code.

* Cleanup code.

* Fix bug done when cleanup.

* Replace FrameHandledMouseEvent to AdornmentHandledMouseEvent.

* Removes Tab constructor parameters.

---------

Co-authored-by: Tig <tig@users.noreply.github.com>

* Fix merge errors.

* Remove constructors with parameters from Button.

* Remove parenthesis on objects initializers from Button.

* Remove constructors with parameters from CheckBox.

* Remove parenthesis on objects initializers from CheckBox.

* Remove constructors with parameters from ComboBox.

* Remove constructors with parameters from FrameView.

* Remove parenthesis on objects initializers from FrameView.

* Initial commit

* Renamed Direction enum for clarity in refactoring unit tests

* Moved nav tests to NavigationTests

* Moved view tests around

* Cleaning up TextFormatter and View.AutoSize code

* Fixed latent TextFormatter bug with \n

* removed Application dependency on some autosize unit tests

* Fixed Label tests to deal with auotsize overriding height/width

* Fixed more label tests. WIP

* Fixed all places where AutoSize = happend after setting Dims

* Started adding new primitive View.Text tests

* Code comments

* WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match.

* WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match.

* Remove frame set from the View constructor and prevent SetRelativeLayout running if not yet initialized.

* Changes needed for unit tests pass on remove parameters constructors from the Label class.

* Remove constructors with parameters from Label.

* Remove parenthesis on objects initializers from Label.

* Prefix private fields with underscore.

* Renamed to MaxLength.

* Remove constructors with parameters from ListView.

* MakeWrapper not needed anymore.

* Remove parenthesis on objects initializers from ListView.

* WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match.

* Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat.

* Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat.

* Fixed messagebox

* Remove constructors with parameters from ScrollBarView and ScrollView.

* Remove parenthesis on objects initializers from ScrollBarView and ScrollView.

* Cleanup code.

* Fix merge errors.

* Add empty dotsettings for solution and projects.

* Set ReSharper language analysis level for projects to  C#12

* Make ReSharper consider itself the boss for style

* Add rule to enforce property backing fields above the property

* Disable auto-detection of naming rules so ReSharper doesn't change them by itself

* Don't let someone's VS settings override the indent settings

* Explicitly set tab width to 4 spaces and force spaces.

* Rules to keep various multi-line constructs aligned within themselves

* Curly brace rules (Using K&R style, per current project spec)

* Blank line rules

Mostly to add breaks in various situations, and also to enforce max of 1 blank line.

* Increase auto-wrap to 160 from default of 120

* Line break at end of all files, to make Unixy systems happy

* Keep attributes on their own lines except for methods and records that are themselves single-line

* Increase attribute auto-wrap to 60 from default of 38

* Wrap/chop rules for long method signatures and record declarations

Chop if either already multi-line or if over 8 parameters.
Chop AFTER the left paren and BEFORE the first parameter.

* Chop rules for generics

For generics with multi-line type parameters or multiple type parameter constraints, chop in a way that has consistent alignment.

* Always enforce enum members on their own lines

* One-line functions completely on one line

They're usually expression-bodied anyway, here, so this is almost irrelevant

* Keep control flow statements on their own lines

* Follow same chop rules for method invocation as method declaration

* Chop long or multi-line method chains or patterns

* Wrap rules for binary operators

Operator at beginning of new lines
Auto-chop if long or already multi-line

* Spaces between keywords and their opening parentheses

* Add file layout rules for organization of reorderable items like fields, properties, etc.

Ugly XML, so load it up in the UI to look at it
It's MOSTLY the ReSharper defaults, but with more aggressive sorting, generally by access modifier and name, within each grouping.

* Deconstructors use per-member types

* Use keywords for built-in types and increase severity of inspection for violations

Also apply to IntPtr and similar, which should now be nint and similar

* Apply syntax style on completion.

* Use var when evident for built-in and simple types, but not elsewhere

* Increase severity for some minor redundancy and clarity inspections

* Enforce braces always required for blocks, and treat as error

* Warn if a local function is not statement-bodied

* Increase various inspection severities

IF Condition => Severity:
Attributes not wrapped property => Suggestion
Constructors expression-bodied => Error
default doesn't have type when it isn't clear => suggestion
Namespaces not file-scoped => error
Methods not statement-bodied => hint
Null check pattern not the object property pattern => Error

* Adjust preference order of null check patterns to make object pattern highest

* XmlDoc rules to keep tags and contents aligned and wrapped

* Add a few custom profiles for code cleanup and make the full profile default

* Remove parts for languages not used in this solution

* copied in v2_develop changes

* Merged v2_develop

* Added Begin/Init unit tests. Removed Application dependencey from AutoSizeFalse tests

* TextFormatter.Lines -> GetLines ()

* Let ReSharper know we intend to localize things

* TextFormatter code cleanup

* copied in v2_develop changes

* Merged v2_develop

* Spaces aren't wanted here either.

* Fix merge errors.

* Fixes ContentBottomRightCorner related with #3211 (comment)

* Remove constructors with parameters from ContextMenu.

* Remove commented code.

* Remove constructors with parameters from OpenDialog.

* Remove constructors with parameters from SaveDialog.

* Remove constructors with parameters from TextField.

* Remove constructors with parameters from TimeField.

* Fix unit test.

* Remove unnecessary SetInitialProperties method.

* Remove unnecessary SetInitialProperties method.

* Remove parenthesis on objects initializers from Toplevel and Window.

* Remove constructors with parameters from RadioGroup.

* Remove constructors with parameters from TextView.

* Remove constructors with parameters from MenuBar.

* TEMPORARY: Turn everything that was set to error down to warning or lower

* Fixes #3219. MenuBar is opened by call OpenMenu even it's disabled.

* Remove constructors with parameters from Menu.

* Remove constructors with parameters from View.

* Change constructor to internal because is mainly useful for testing.

* ReSharper Cleanup Code.

* Added format only r# config

* Fixes #3224. TextFormatter.Lines should return a single string.Empty list even with Width or Height equal to zero.

* Remove constructors with parameters from Dialog.

* Remove constructors with parameters from TextValidateField.

* Fixes #3224 (comment)

* Fixes #3225. Press CursorDown on TabView doesn't move to the next view.

* Fixes #3229. TextFormatter should have a FillRemaining property.

* Testing formatting merge in bdisp

* Testing formatting merge

* Testing formatting merge bdisp

* Testing formatting merge 2

* xmldoc format

* R# Full Code Cleanup

* R# Full Code Cleanup2

* R# Full Code Cleanup2

* Merged! But broke tests

* Refixing...

* Refixed DrawTests

* Refixed ViewTests

* Refixed Text Tests

* Refixed more unit tests

* Refixed scenarios

* Refixed rest of scenarios

* Refixed ViewsTests

* Refixed rest of tests. All unit tests pass again!

* Fixed warnings

* Updated R# version. Added new code cleanup settings

* Applied latest code cleanup to solution

* Another code cleanup pass

* Tweaked r# settings. .editorconfig now matches.

* r# else on separate line

* r# - update

* r# - full solution

* test commit

* test commit

* test commit

* Removed extra profiles

* Full cleanup following cleaning up profiles

* Null checking pattern rules/inspections

* Tabs and extra whitespace are evil

* Attributes on their own lines

* Code layout rules to put fields first and to put backing fields with their properties

* Merged v2_develop

* Full cleanup following dodexahedron's PR

---------

Co-authored-by: BDisp <bd.bdisp@gmail.com>
Co-authored-by: Brandon Thetford <github@snapsinazfs.com>
@BDisp
Copy link
Collaborator Author

BDisp commented Feb 12, 2024

@tig this test is failing:

	[Fact]
	[SetupFakeDriver]
	public void Button_AutoSize_False_Does_Not_Draw ()
	{
		var btn = new Button {
			AutoSize = false,
			X = Pos.Center (),
			Y = Pos.Center (),
			Text = "Press me!"
		};
		Assert.Equal ("Press me!", btn.Text);
		btn.BeginInit ();
		btn.EndInit ();
		btn.Draw ();

		Assert.Equal ($"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}", btn.TextFormatter.Text);
		Assert.Equal ("{Width=0, Height=1}", btn.TextFormatter.Size.ToString ());
		TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
	}

The output is:

Expected:

 But Was:
          ⟦ Pr

This should be really empty because the dimension wasn't already set and IsInitialized is false. It has a width of 4 because the SetRelativeLayout, called by the constructor, is setting the Pos/Dim absolute values even without initialize the view. Do you really want to maintain the current behavior?

@tig
Copy link
Collaborator

tig commented Feb 12, 2024

@tig this test is failing:

	[Fact]
	[SetupFakeDriver]
	public void Button_AutoSize_False_Does_Not_Draw ()
	{
		var btn = new Button {
			AutoSize = false,
			X = Pos.Center (),
			Y = Pos.Center (),
			Text = "Press me!"
		};
		Assert.Equal ("Press me!", btn.Text);
		btn.BeginInit ();
		btn.EndInit ();
		btn.Draw ();

		Assert.Equal ($"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}", btn.TextFormatter.Text);
		Assert.Equal ("{Width=0, Height=1}", btn.TextFormatter.Size.ToString ());
		TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
	}

The output is:

Expected:

 But Was:
          ⟦ Pr

This should be really empty because the dimension wasn't already set and IsInitialized is false. It has a width of 4 because the SetRelativeLayout, called by the constructor, is setting the Pos/Dim absolute values even without initialize the view. Do you really want to maintain the current behavior?

First, you need to ask "What, really, is the purpose of this test? What precisely is it testing at a unit level? I deleted this test because I moved what it was testing to where those tests belonged (Layout and Text).

There is a bug here though. Let's decode it.

SetRelativeLayout is called because the constructor (actually the View constructor) sets Text, and the Text setter ends up calling SetRelativeLayout:

image

SetRelativeLayout gets called again when Button sets TextAlignment in its constructor:

image

And again when Height is set:

image

And AGAIN when AutoSize is set:

image

etc...

Finally, when `Text = "Press me!" happens:

image

Before BeginInit is called:

image

As you note this is clearly wrong, giving AutoSize == false.

The question is, what is right (for Button)?

  1. 0, 0
  2. 0, 1
  3. 4, 1 (current behavior)
  4. 13, 1 (4 + "Press me!")

I want to view this through the lens of Dim.Auto existing (and View.AutoSize being nuked). I think, by default, Button would be set like this:

Width = Dim.Auto ();
Height = 1;

If someone were to set Width to some other value, the button would be that Width.

All that said, I think the TEST is buggy: Setting AutoSize = false invalidates Height and Width. The test never sets Height and Width and thus they are indeterminate.

This is correct:

[Fact]
[SetupFakeDriver]
public void Button_AutoSize_False_Does_Not_Draw ()
{
    var btn = new Button
    {
        AutoSize = false,
        X = Pos.Center (),
        Y = Pos.Center (),
        Height = 1,
        Width = 0,
        Text = "Press me!"
    };
    Assert.Equal ("Press me!", btn.Text);
    btn.BeginInit ();
    btn.EndInit ();
    btn.Draw ();

    Assert.Equal ($"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}", btn.TextFormatter.Text);
    Assert.Equal ("{Width=0, Height=1}", btn.TextFormatter.Size.ToString ());
    TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
}

tig added a commit that referenced this issue Feb 12, 2024
…tting (#3241)

* Removed resharper settings from editorconfig

* Remove constructors with frame parameters from Button class.

* Remove constructors with frame parameters from CheckBox class.

* Cleanup code.

* Remove constructors with frame parameters from ComboBox class.

* @BDisp
Remove constructors with frame parameters from FrameView class.

* Remove constructors with frame parameters from Label class.

* Remove constructors with frame parameters from ListView class.

* Remove constructors with frame parameters from ScrollBarView class.

* Remove constructors with frame parameters from ScrollView class.

* Remove namespace braces.

* Cleanup code.

* Cleanup code.

* Cleanup code.

* Remove constructors with frame parameters from TextField class.

* Remove constructors with frame parameters from TimeField class.

* Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty.

* Remove constructors with frame parameters from Toplevel class.

* Remove constructors with frame parameters from Window class.

* Fix merge errors.

* Revert "Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty."

This reverts commit cf9c24b.

* Revert unit test.

* Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame (#2980)

* Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame

* Trying fix this unit test that sometimes fail.

* Fixes #2983. View need a alternative DrawFrame for the v2.

* Use new DrawFrame method.

* Change _lines field to Lines property.

* Add TabWindow unit test.

* Add DrawIncompleteFrame method and unit tests.

* Add more unit tests to LineCanvas.

* Fix newline conflict errors.

* Revert "Change _lines field to Lines property."

This reverts commit ab6c5f3.

* Add DrawIncompleteFrame method and unit tests.

* Add more unit tests to LineCanvas.

* Fix newline conflict errors.

* Force render immediately instead of join.

* I will never rely on zero-location-based unit test again.

* Fix TestTreeViewColor unit test fail.

* Using location of 3 to avoid be divisible by 2 and so avoiding bugs.

* Revert "Using location of 3 to avoid be divisible by 2 and so avoiding bugs."

This reverts commit dd3df13.

* Revert "I will never rely on zero-location-based unit test again."

This reverts commit 62adf6f.

* Revert "Fix newline conflict errors."

This reverts commit 4acf726.

* Revert "Add more unit tests to LineCanvas."

This reverts commit 66bc6f5.

* Revert "Add DrawIncompleteFrame method and unit tests."

This reverts commit 680ba26.

* Resolving merge conflicts.

* Revert "Use new DrawFrame method."

This reverts commit 69a7f17.

* Revert "Fixes #2983. View need a alternative DrawFrame for the v2."

This reverts commit dade9fd.

* Reverting this changes to start a new one.

* Add horizontal and vertical support for combining glyphs.

* Fix text and auto size behavior.

* Add TabWidth property.

* Add unit test for WordWrap.

* Fixes #3017. View TextDirection returns incorrect size on a vertical direction instance with AutoSize as false.

* Using Frame to force read from the get method.

* Fix some issues with AutoSize and ForceValidatePosDim.

* Fixing broken unit tests.

* Restoring code I've broken.

* Removing forgotten code.

* Only LayoutStyle.Computed can change the Frame.

* DateField and TimeField depends on LayoutStyle.Computed.

* Fix unit tests related with LayoutStyle.

* Implements tabs, left and right arrows as View.

* Draws a minimum full border.

* Adds missing XML parameter.

* Adds assert tests for Frame.

* Removes duplicates InlineData.

* Adds more unit tests for minimum full border without Left and Right thickness.

* Trying to fix the TestTreeViewColor unit test fail.

* Prevents a user to set TextDirection to -1.

* Prevents any invalid TextDirection value.

* Removes (TextDirection)(-1).

* Removes unnecessary TextDirection initialization.

* Removes LayoutStyle.

* Fixing unit tests with border.

* Trying to fix TestTreeViewColor again.

* Revert "Trying to fix TestTreeViewColor again."

This reverts commit c2efa8e.

* Trying to fix TestTreeViewColor again.

* Fix merge errors.

* Fix merge errors.

* Restoring unit test.

* Restores the right XML comment.

* Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes.

* Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes.

* Only call OnResizeNeeded if it's LayoutStyle.Computed.

* Fix merge errors.

* Fix merge errors.

* Fix unit tests fail.

* Reformat.

* Again.

* Rename to OnDrawAdornments.

* Fix failing unit tests.

* Reduces indentation and cleanup code.

* Cleanup code.

* Fix bug done when cleanup.

* Replace FrameHandledMouseEvent to AdornmentHandledMouseEvent.

* Removes Tab constructor parameters.

---------

Co-authored-by: Tig <tig@users.noreply.github.com>

* Fix merge errors.

* Remove constructors with parameters from Button.

* Remove parenthesis on objects initializers from Button.

* Remove constructors with parameters from CheckBox.

* Remove parenthesis on objects initializers from CheckBox.

* Remove constructors with parameters from ComboBox.

* Remove constructors with parameters from FrameView.

* Remove parenthesis on objects initializers from FrameView.

* Initial commit

* Renamed Direction enum for clarity in refactoring unit tests

* Moved nav tests to NavigationTests

* Moved view tests around

* Cleaning up TextFormatter and View.AutoSize code

* Fixed latent TextFormatter bug with \n

* removed Application dependency on some autosize unit tests

* Fixed Label tests to deal with auotsize overriding height/width

* Fixed more label tests. WIP

* Fixed all places where AutoSize = happend after setting Dims

* Started adding new primitive View.Text tests

* Code comments

* WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match.

* WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match.

* Remove frame set from the View constructor and prevent SetRelativeLayout running if not yet initialized.

* Changes needed for unit tests pass on remove parameters constructors from the Label class.

* Remove constructors with parameters from Label.

* Remove parenthesis on objects initializers from Label.

* Prefix private fields with underscore.

* Renamed to MaxLength.

* Remove constructors with parameters from ListView.

* MakeWrapper not needed anymore.

* Remove parenthesis on objects initializers from ListView.

* WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match.

* Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat.

* Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat.

* Fixed messagebox

* Remove constructors with parameters from ScrollBarView and ScrollView.

* Remove parenthesis on objects initializers from ScrollBarView and ScrollView.

* Cleanup code.

* Fix merge errors.

* Add empty dotsettings for solution and projects.

* Set ReSharper language analysis level for projects to  C#12

* Make ReSharper consider itself the boss for style

* Add rule to enforce property backing fields above the property

* Disable auto-detection of naming rules so ReSharper doesn't change them by itself

* Don't let someone's VS settings override the indent settings

* Explicitly set tab width to 4 spaces and force spaces.

* Rules to keep various multi-line constructs aligned within themselves

* Curly brace rules (Using K&R style, per current project spec)

* Blank line rules

Mostly to add breaks in various situations, and also to enforce max of 1 blank line.

* Increase auto-wrap to 160 from default of 120

* Line break at end of all files, to make Unixy systems happy

* Keep attributes on their own lines except for methods and records that are themselves single-line

* Increase attribute auto-wrap to 60 from default of 38

* Wrap/chop rules for long method signatures and record declarations

Chop if either already multi-line or if over 8 parameters.
Chop AFTER the left paren and BEFORE the first parameter.

* Chop rules for generics

For generics with multi-line type parameters or multiple type parameter constraints, chop in a way that has consistent alignment.

* Always enforce enum members on their own lines

* One-line functions completely on one line

They're usually expression-bodied anyway, here, so this is almost irrelevant

* Keep control flow statements on their own lines

* Follow same chop rules for method invocation as method declaration

* Chop long or multi-line method chains or patterns

* Wrap rules for binary operators

Operator at beginning of new lines
Auto-chop if long or already multi-line

* Spaces between keywords and their opening parentheses

* Add file layout rules for organization of reorderable items like fields, properties, etc.

Ugly XML, so load it up in the UI to look at it
It's MOSTLY the ReSharper defaults, but with more aggressive sorting, generally by access modifier and name, within each grouping.

* Deconstructors use per-member types

* Use keywords for built-in types and increase severity of inspection for violations

Also apply to IntPtr and similar, which should now be nint and similar

* Apply syntax style on completion.

* Use var when evident for built-in and simple types, but not elsewhere

* Increase severity for some minor redundancy and clarity inspections

* Enforce braces always required for blocks, and treat as error

* Warn if a local function is not statement-bodied

* Increase various inspection severities

IF Condition => Severity:
Attributes not wrapped property => Suggestion
Constructors expression-bodied => Error
default doesn't have type when it isn't clear => suggestion
Namespaces not file-scoped => error
Methods not statement-bodied => hint
Null check pattern not the object property pattern => Error

* Adjust preference order of null check patterns to make object pattern highest

* XmlDoc rules to keep tags and contents aligned and wrapped

* Add a few custom profiles for code cleanup and make the full profile default

* Remove parts for languages not used in this solution

* copied in v2_develop changes

* Merged v2_develop

* Added Begin/Init unit tests. Removed Application dependencey from AutoSizeFalse tests

* TextFormatter.Lines -> GetLines ()

* Let ReSharper know we intend to localize things

* TextFormatter code cleanup

* copied in v2_develop changes

* Merged v2_develop

* Spaces aren't wanted here either.

* Fix merge errors.

* Fixes ContentBottomRightCorner related with #3211 (comment)

* Remove constructors with parameters from ContextMenu.

* Remove commented code.

* Remove constructors with parameters from OpenDialog.

* Remove constructors with parameters from SaveDialog.

* Remove constructors with parameters from TextField.

* Remove constructors with parameters from TimeField.

* Fix unit test.

* Remove unnecessary SetInitialProperties method.

* Remove unnecessary SetInitialProperties method.

* Remove parenthesis on objects initializers from Toplevel and Window.

* Remove constructors with parameters from RadioGroup.

* Remove constructors with parameters from TextView.

* Remove constructors with parameters from MenuBar.

* TEMPORARY: Turn everything that was set to error down to warning or lower

* Fixes #3219. MenuBar is opened by call OpenMenu even it's disabled.

* Remove constructors with parameters from Menu.

* Remove constructors with parameters from View.

* Change constructor to internal because is mainly useful for testing.

* ReSharper Cleanup Code.

* Added format only r# config

* Fixes #3224. TextFormatter.Lines should return a single string.Empty list even with Width or Height equal to zero.

* Remove constructors with parameters from Dialog.

* Remove constructors with parameters from TextValidateField.

* Fixes #3224 (comment)

* Fixes #3225. Press CursorDown on TabView doesn't move to the next view.

* Fixes #3229. TextFormatter should have a FillRemaining property.

* Testing formatting merge in bdisp

* Testing formatting merge

* Testing formatting merge bdisp

* Testing formatting merge 2

* xmldoc format

* R# Full Code Cleanup

* R# Full Code Cleanup2

* R# Full Code Cleanup2

* Merged! But broke tests

* Refixing...

* Refixed DrawTests

* Refixed ViewTests

* Refixed Text Tests

* Refixed more unit tests

* Refixed scenarios

* Refixed rest of scenarios

* Refixed ViewsTests

* Refixed rest of tests. All unit tests pass again!

* Fixed warnings

* Updated R# version. Added new code cleanup settings

* Applied latest code cleanup to solution

* Another code cleanup pass

* Tweaked r# settings. .editorconfig now matches.

* r# else on separate line

* r# - update

* r# - full solution

* test commit

* test commit

* test commit

* Removed extra profiles

* Full cleanup following cleaning up profiles

* Null checking pattern rules/inspections

* Tabs and extra whitespace are evil

* Attributes on their own lines

* Code layout rules to put fields first and to put backing fields with their properties

* Merged v2_develop

* Full cleanup following dodexahedron's PR

* Told ReSharper to write its settings to the .editorconfig, to sync them up

* Update CONTRIBUTING.md for new formatting rules and link some bullets for convenience

#21

* Fix anchor

Signed-off-by: dodexahedron <dodexahedron@users.noreply.github.com>

* Tweak bullet indent for clarity

Signed-off-by: dodexahedron <dodexahedron@users.noreply.github.com>

---------

Signed-off-by: dodexahedron <dodexahedron@users.noreply.github.com>
Co-authored-by: Tig Kindel <tig@kindel.com>
Co-authored-by: Tig Kindel <tig@users.noreply.github.com>
Co-authored-by: BDisp <bd.bdisp@gmail.com>
@BDisp
Copy link
Collaborator Author

BDisp commented Feb 12, 2024

Closing this because the Button is a special view that overrides the UpdateTextFormatterText method and thus set a minimal sie of 4 for the brackets and spaces if no width is set at object initializer. Setting only the width equal to zero, as the Button already sets the height on the constructor, the test pass. Thanks @tig.

@BDisp BDisp closed this as completed Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants