Page MenuHome

UI: View2D: Align vertical indicators to view
ClosedPublic

Authored by Pablo Vazquez (pablovazquez) on Oct 10 2021, 7:26 PM.
Tokens
"Like" token, awarded by Fracture128."Love" token, awarded by jwvd."Love" token, awarded by AndyCuccaro."Love" token, awarded by tintwotin."Love" token, awarded by gilberto_rodrigues."Love" token, awarded by mistrzjang."Love" token, awarded by Mylo."Love" token, awarded by HEYPictures."Love" token, awarded by jc4d."Like" token, awarded by EAW."Love" token, awarded by carlosmu."Love" token, awarded by RedMser."Love" token, awarded by harley.

Details

Summary

In editors with vertical scale indicators, such as Graph Editor,
Drivers, or VSE, display the values aligned to the view.

Also add a shadow (similar to the 3D View info) to improve readability when the text is on top of curves, strips, or other content.

Diff Detail

Repository
rB Blender
Branch
temp-view2d-vertical-indicator (branched from master)
Build Status
Buildable 17686
Build 17686: arc lint + arc unit

Event Timeline

Pablo Vazquez (pablovazquez) requested review of this revision.Oct 10 2021, 7:26 PM
Pablo Vazquez (pablovazquez) created this revision.

Nice change!

The numbers seem to be approximately a pixel too high in the graph editor, and slightly more in the Sequencer. I find it more noticeable in the Graph Editor because they all sit on top of the lines whose values’ they label. Did you experiment with other offsets?

Better calculate the center of the text by using BLF_height.

Nice change!

The numbers seem to be approximately a pixel too high in the graph editor, and slightly more in the Sequencer. I find it more noticeable in the Graph Editor because they all sit on top of the lines whose values’ they label. Did you experiment with other offsets?

Thanks! You were right about the alignment especially in the VSE. I tried different offsets but they didn't always align. I've now switched to use BLF_height to get the height of the string and divide it by 2 (then the infamous U.pixelsize offset). This one seems to do the trick! Also I assume it's more future proof if the font size or font family changes.

@Campbell Barton (campbellbarton) could you please check if I'm doing the right thing here? I'm calculating the height of the text and halving it so it's center, which I think it's correct but perhaps is overkill. Thanks!

@Pablo Vazquez (pablovazquez) - I'm calculating the height of the text and halving it so it's center, which I think it's correct but perhaps is overkill. Thanks!

There's probably not really a need to calculate the height of the entire string and do it inside the loop. I'd consider just getting the height of a digit "0" and do so before the loop, like this:

...
  const float ymax = rect->ymax;
  const float y_offset = (BLF_height(font_id, "0", 1) / 2.0f) - U.pixelsize;

  for (uint i = 0; i < steps; i++) {
...

Applied suggestions by @Harley Acheson (harley). Thanks!
Big oversight from my side, as we never have more than 1 line so no need to calculate it inside the loop.

Also increment the left padding a bit so it doesn't overlap with the sources-list toggle widget.

Think this is ready. It's a clear improvement to me.

Of course there are still issues with very low zooming levels, but it's a separate issue and I don't think your patch makes that worse.

source/blender/editors/interface/view2d_draw.c
408

You could also use BLF_height_max() for this I think, but probably doesn't matter in practice.

This revision is now accepted and ready to land.Oct 14 2021, 10:24 PM

Use BLF_height_max instead of BLF_height, suggested by @Julian Eisel (Severin). Thanks for taking the time to review!

Use BLF_height_max instead of BLF_height, suggested by @Julian Eisel (Severin). Thanks for taking the time to review!

With this item it is pretty important that the height used is correct so that it vertically centers correctly. Even out a pixel can make it line up oddly with the nearby line.

That BLF_height_max is basically the height of the tallest character in the font (bounding box xMax - xMin) . Are 0-9 always as tall as the tallest characters in the font? No, there are are fonts where the descenders are greater than ascenders, so p will be taller than an f, and so numbers will be not as tall as the maximum.

Note this bounding box cannot take Hinting into account so can be out by a pixel or more if hinting is enabled.

With OpenType variable fonts this bounding box is not updated even though some changes can affect the height.

Best to just measure a "0" as I mentioned above.

Edited: In our DejaVuSans the characters "$()[[]" are all taller than the numbers, so the height of the digits is less than font max height. Will be close at small sizes though.

With this item it is pretty important that the height used is correct so that it vertically centers correctly. Even out a pixel can make it line up oddly with the nearby line.

That BLF_height_max is basically the height of the tallest character in the font (bounding box xMax - xMin) . Are 0-9 always as tall as the tallest characters in the font? No, there are are fonts where the descenders are greater than ascenders, so p will be taller than an f, and so numbers will be not as tall as the maximum.

Note this bounding box cannot take Hinting into account so can be out by a pixel or more if hinting is enabled.

With OpenType variable fonts this bounding box is not updated even though some changes can affect the height.

Best to just measure a "0" as I mentioned above.

Edited: In our DejaVuSans the characters "$()[[]" are all taller than the numbers, so the height of the digits is less than font max height. Will be close at small sizes though.

Thanks for the heads up, I should have tested more. It's now fixed in master.