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

console.lua: improve the hovered item calculation with background-box #15711

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

guidocella
Copy link
Contributor

console.lua: improve the hovered item calculation with background-box

Follow up to c438732 which improved the calculation with the default outline-and-shadow. We can make the calculation accurate for background-box too without making semitransparent rectangle backgrounds overlap by adding margin between items.

We could calculate the height of each item to make them perfectly adjacent by rendering each one with compute_bounds, but that takes 15ms per render, so 20 lines would take 300ms, which is too slow.

Instead add a fixed 0.1 * opts.font_size to each item's height. This ensures the backgrounds don't overlap with tall CJK text or track circles and --osd-shadow-offset=0. Add this to outline-and-shadow too since it looks better with some margin between the items. Then add the rectangle offset to the height depending on the border style.

Copy link

github-actions bot commented Jan 19, 2025

Download the artifacts for this pull request:

Windows
macOS

@na-na-hi
Copy link
Contributor

Instead add a fixed 0.1 * opts.font_size to each item's height. This ensures the backgrounds don't overlap with tall CJK text or track circles and --osd-shadow-offset=0.

How do you ensure that the "tall characters" are at most 10% larger than normal characters, but not more?

@guidocella
Copy link
Contributor Author

You don't, it's a heuristic. It works with the fonts I tried and can be increased if it doesn't work with some others.

@na-na-hi
Copy link
Contributor

You don't, it's a heuristic. It works with the fonts I tried and can be increased if it doesn't work with some others.

"Works for me" isn't a good enough justification when it changes the appearance significantly:
select
It now looks very different from console, especially when the gaps and item background width don't even have the same size. No other menu-like UI do anything like this.

@guidocella
Copy link
Contributor Author

Well it was kasper's request to do it like this. I don't use background-box personally.

@kasper93
Copy link
Contributor

LGTM

This should not divide by scale_factor() because osd_w is already scaled
pixels.

Also add a TODO to fix --osd-margin-x's scaling.
Follow up to c438732 which improved the calculation with the default
outline-and-shadow. We can make the calculation accurate for
background-box too without making semitransparent rectangle backgrounds
overlap by adding margin between items.

We could calculate the height of each item to make them perfectly
adjacent by rendering each one with compute_bounds, but that takes 15ms
per render, so 20 lines would take 300ms, which is too slow.

Instead add a fixed 0.1 * opts.font_size to each item's height. This
ensures the backgrounds don't overlap with tall CJK text or track
circles and --osd-shadow-offset=0. Add this to outline-and-shadow too
since it looks better with some margin between the items. Then add the
rectangle offset to the height depending on the border style.
@kasper93
Copy link
Contributor

You don't, it's a heuristic. It works with the fonts I tried and can be increased if it doesn't work with some others.

"Works for me" isn't a good enough justification when it changes the appearance significantly: select It now looks very different from console, especially when the gaps and item background width don't even have the same size. No other menu-like UI do anything like this.

It's is improvement over current status, feel free to come up with better ideas for this problem. @guidocella said that compute_bounds is too slow to work with, so we are quite limited in what we can do here. Otherwise we could match the spacing or draw background separately, but we would need a bounding box for this, which is apparently no-go.

@na-na-hi
Copy link
Contributor

It's is improvement over current status

It has appearance regression and not 100% improvement.

Otherwise we could match the spacing or draw background separately, but we would need a bounding box for this, which is apparently no-go.

Here is a bounding box that doesn't require compute_bounds:

You already know the total height of the box because you know the number of lines. The width can simply be the whole window width.

@kasper93
Copy link
Contributor

You already know the total height of the box because you know the number of lines. The width can simply be the whole window width.

It has appearance regression and not 100% improvement.

See, I find separate buttons with separate background just as nice.

We could compute bounds of longest string in selections, but it still means that we need to draw custom background and disable the style of default background, but I guess this can be done, wit tags for the events.

@guidocella
Copy link
Contributor Author

This looks fine to me too by making them look like separate buttons and not drawing more background width than necessary for each item. We will also add --osd-selected-back-color to give a different background color only to the selected item, this will be simpler if we don't have to draw ourselves. Also if we don't override libass' border style and libass/libass#688 is ever closed it will have rounded corners for free.

Computing the longest width is too slow with something like 10k properties. And if you compute the width only of current matches, the background width would change as you scroll.

@na-na-hi
Copy link
Contributor

It has appearance regression and not 100% improvement.

Which one has larger appearance change, especially compared to regular console?

See, I find separate buttons with separate background just as nice.
This looks fine to me too by making them look like separate buttons and not drawing more background width than necessary for each item.

It's not nice when they have different width. As I already said no other menus look like this.

We will also add --osd-selected-back-color to give a different background color only to the selected item, this will be simpler if we don't have to draw ourselves. Also if we don't override libass' border style and libass/libass#688 is ever closed it will have rounded corners for free.

I don't see how is this complicated. You draw the selected item background over the whole background. And if you really think rounded corners are important enough here (and not just bringing it up for the sake of argument), you can draw them already, there is no need to wait for libass.

Computing the longest width is too slow with something like 10k properties. And if you compute the width only of current matches, the background width would change as you scroll.

There is no problem if you make the background fixed width, like I originally mentioned.

I will end my remark by pointing out that the uosc playlist selection menu uses the drawing methods I mentioned and looks much better than this PR. It additionally calculates the longest item's width, but we don't have to do that and instead keep it a constant width to avoid width calculation.

@kasper93
Copy link
Contributor

It additionally calculates the longest item's width, but we don't have to do that and instead keep it a constant width to avoid width calculation.

I would prefer to not cover whole screen in background-box, just because we are too lazy to calculate the width of it. It will look obnoxious for short menu items.

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.

3 participants