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

Introduce Autofit choice for groups per row #82

Merged

Conversation

haydar-metin
Copy link
Contributor

@haydar-metin haydar-metin commented Feb 23, 2024

What it does

Introduces the Autofit element for Groups per Row.

IMPORTANT: The selected Groups per Row is based on the available choices! That means, it is not possible to render, e.g., 7 groups per rows (for now). HOWEVER, code-wise it should be still possible if requested.

How to test

  1. Select Autofit in the options for Groups per Row
  2. Change Bytes per Word, Words per Group or toggle the columns
  3. Resize either the view or the colums
  4. Go to 2.

Review checklist

Reminder for reviewers

Closes #73

@haydar-metin haydar-metin self-assigned this Feb 23, 2024
@haydar-metin haydar-metin requested a review from planger February 23, 2024 13:49
Copy link
Contributor

@planger planger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this looks and works great!
I personally would find it even better if we'd allow any number of groups per row with the Autofit option active. I don't really see a reason why not allowing e.g. 3, 7, or 10. But then on the other hand I'm not a typical user, so I might be wrong. Better to let Jens and Colin chime in on this one.
Thank you!

src/webview/components/memory-table.tsx Outdated Show resolved Hide resolved
src/common/typescript.ts Outdated Show resolved Hide resolved
src/common/typescript.ts Outdated Show resolved Hide resolved
src/webview/components/memory-table.tsx Outdated Show resolved Hide resolved
src/webview/components/memory-table.tsx Outdated Show resolved Hide resolved
src/webview/components/memory-table.tsx Outdated Show resolved Hide resolved
src/webview/components/options-widget.tsx Outdated Show resolved Hide resolved
/**
* Calculates the width of the provided text within the container
*
* @see https://stackoverflow.com/a/21015393
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, it is not good practice to copy Stack Overflow code, as it implicates the including project in the licensing of the included code, which is a copy-left license:

https://stackoverflow.com/help/licensing
https://creativecommons.org/licenses/by-sa/4.0/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the link to use the API doc as I only provided the link in the beginning to read more about the topic if necessary

@haydar-metin haydar-metin marked this pull request as draft February 26, 2024 10:11
@haydar-metin
Copy link
Contributor Author

haydar-metin commented Feb 26, 2024

@colin-grant-work I moved the calculations to the column contribution in commit 413ca77
@planger The groups per row can now be any value independently of the choices we have. The advantage is, the full width will be now used.

@haydar-metin haydar-metin marked this pull request as ready for review February 26, 2024 14:43
@planger
Copy link
Contributor

planger commented Feb 27, 2024

Great, thanks for the update! From my point of view this works very well now. @colin-grant-work @jreineckearm what do you think?

src/common/typescript.ts Outdated Show resolved Hide resolved
src/plugin/manifest.ts Outdated Show resolved Hide resolved
src/common/typescript.ts Outdated Show resolved Hide resolved
src/webview/columns/column-fitting.ts Outdated Show resolved Hide resolved
src/webview/columns/column-fitting.ts Outdated Show resolved Hide resolved
src/webview/columns/column-fitting.ts Outdated Show resolved Hide resolved
*
* **Note**
*
* The returned `groups per row` value is based on {@link CONFIG_GROUPS_PER_ROW_NUMERIC_CHOICES}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see code that would enforce this. In the for loop below, we appear to decrement by one and return whenever the value works, which certainly doesn't guarantee a power of two.

Copy link
Contributor Author

@haydar-metin haydar-metin Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My error. Removed the note, as Autofit should use the width as whole.

Comment on lines 422 to 384
if (row) {
const fitting = SupportedColumnFitting.findAll(this.props.columnOptions.map(c => c.contribution), ColumnGroupsPerRowFit.is);
return Math.max(...fitting.map(s => s.calculateGroupsPerRow(row, options)));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my previous suggestion to come up with an API for column behaviors may have produced an excess of abstraction.

In fact, we can only get one value out of this calculation, and only one column has the right to calculate that value. Rather than pretending that ColumnGroupsPerRowFit could apply to more than one column, it would be better to just hardcode a reference to the calculation in the data ColumnContribution. It is still better for the code for calculating that value to be in that file, but there really isn't any way around just making that column responsible for this calculation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I removed the not necessary abstraction again. I just let the fittingType in the API for basic behaviors such as content-width fitting (e.g., the address column)

src/webview/columns/data-column.tsx Outdated Show resolved Hide resolved
@haydar-metin haydar-metin force-pushed the issues/73_auto_fitting branch from 2bc98bd to 106a12a Compare February 28, 2024 12:10
@jreineckearm
Copy link
Contributor

@haydar-metin , @planger , I have just tested this. Looks really great!
I've only noticed that it often doesn't make full use of the remaining space. In some scenarios, a fixed "Group per Row" setting fits in more than the autofit.

Example:
Started of with autofit. It fits in 7 groups per row with 1 word per group.
image

Then switched to using 8 groups per row, column width untouched. Which manages to fit an additional group in.
image

When resizing the column, it often looks like it's trying to wait for two groups to fit in before adding another one.
Is there any way to further optimize the width utilization?

@jreineckearm
Copy link
Contributor

BTW: looking forward to see this working in combination with the auto-append scrolling. :-)

@haydar-metin haydar-metin force-pushed the issues/73_auto_fitting branch from 7e4dc5b to 905e061 Compare March 5, 2024 11:52
@haydar-metin
Copy link
Contributor Author

@jreineckearm Thank you for testing it!

  • I now use the exact values (905e061) where possible. Unfortunately, the browser-engine rounds the values or uses different approaches to calculate the width. For this reason, we can only approximate the calculation. Improving this aspect would require us to further investigate how the engine renders it to exactly match (e.g., the width of the eight-bits varies). For this reason, there will be some edge cases where Autofit will require more space.

  • 30ab368 hides now the second row that we can see for a second if we resize the webview.

@colin-grant-work colin-grant-work merged commit 0f2411e into eclipse-cdt-cloud:main Mar 6, 2024
5 checks passed
@jreineckearm
Copy link
Contributor

Thanks, @haydar-metin ! Space utilization is much improved with the latest change! :-)

@tortmayr tortmayr mentioned this pull request Mar 7, 2024
1 task
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

Successfully merging this pull request may close these issues.

Add "autofit" option for memory data
4 participants