Constraint icons size at Sketcher edit (PR ready)

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
abdullah
Posts: 3883
Joined: Sun May 04, 2014 3:16 pm

Re: Constraint icons size at Sketcher edit

Postby abdullah » Mon Dec 21, 2020 8:10 am

vanuan wrote:
Thu Dec 17, 2020 4:18 pm
But it makes a bad UX. What's so special about FreeCAD that every single option must be user configurable? Wouldn't it be nice if it just sized all its UI elements relative to the system's font like every other application?

So the ideal solution would be this:
  • Take the system font in points
  • Make all the fonts be specified in relative units to that system font (1.5, 0.8, etc)
  • Make all the icons be sized in relation to the font size (pixelSize = pointSize / 72 * dpi_ratio)
  • Make sure we take into an account the device pixel ratio (fonts specified in points should remain the same, while the pixel size should increase according to DPR)

Here we see two half-baked solutions. One lacks proper scaling (or rather OS display text size / scaling setting), another lacks the UI element sizing relative to the system font.
Ok. We have two "clashing" sketcher PRs and I would like to have something done about them.

The main problem is not the two PRs, but the fact that I lack the knowledge about how this is done in the real world. I am the kind of developer happy to code the algorithms and pass them to the magic "put this into the screen" function that someone else coded.

Because from your summary you seem to know better than I do, probably it makes sense to ask you.

1. Is it customary that icon size relates to font size?

I do understand that somebody made sure the text renders properly on your screen. I understand that one could leverage that knowledge to get some scaling factor for other elements, such as icons. However, it is still unclear to me if this is how things are done (tm).

What happens if I have an oversized text font in my system, not because I cannot read smaller text, but rather because I read a lot of text on the computer per day and I want to reduce my eye-strain. Do or should icons resize with my selected font size.

2. If yes, I see the comment about the two half-backed solutions. I see the lists of how an ideal solution should look like. What do you think is reasonable doing within the current limitations of FreeCAD.

Tomorrow morning I am going to read the code of both PRs. I am going to read your reply and I am going to give my impressions here in order to move forward.
Syres
Posts: 831
Joined: Thu Aug 09, 2018 11:14 am

Re: Constraint icons size at Sketcher edit

Postby Syres » Mon Dec 21, 2020 8:48 am

vanuan wrote:
Thu Dec 17, 2020 4:18 pm
You might quickly jump to the solution of making an additional user setting "scale factor" and multiply everything by it.
It might work for your immediate use case and other users can change the setting.

But it makes a bad UX.
Really, IMHO Blender Resolution Scale Factor is an excellent solution, I personally have no reason to change it unless I'm showing someone else with poor eyesight how to use a function/operation and I can quickly magnify the view and the way it proportions works very well, again IMHO. For those that haven't used Blender (I've included the Windows clock as a size reference:
0_8ResScale.jpg
0_8ResScale.jpg (189.77 KiB) Viewed 415 times
1Res_Scale.jpg
1Res_Scale.jpg (215.68 KiB) Viewed 415 times
1_2ResScale.jpg
1_2ResScale.jpg (227.44 KiB) Viewed 415 times
User avatar
vanuan
Posts: 497
Joined: Wed Oct 24, 2018 9:49 pm

Re: Constraint icons size at Sketcher edit

Postby vanuan » Tue Dec 22, 2020 9:49 pm

Syres wrote:
Mon Dec 21, 2020 8:48 am
Really, IMHO Blender Resolution Scale Factor is an excellent solution, I personally have no reason to change it unless I'm showing someone else with poor eyesight how to use a function/operation and I can quickly magnify the view and the way it proportions works very well, again IMHO. For those that haven't used Blender (I've included the Windows clock as a size reference:
If you look at the history of introducing this option you'll see that it's a band-aid for lacking support of Retina (HiDPI) display, that is ignoring the OS scale factor setting.

Of course, there's another problem that the OS scaling setting is global and there are request to configure the scaling for each app.
Qt has a dedicated environment variable for that:

Code: Select all

export "QT_SCREEN_SCALE_FACTORS=1;2"
That is if you have multiple displays (HiDPI and non-HiDPI), you could set 100% scaling for the first display and 200% scaling for the second display.

Blender interface is entirely custom, so it lacks the HiDPI scaling support we may leverage in FreeCAD. Though, some parts, like Coin3D window are OpenGL based too, so QT HiDPI support won't help there. But in any case, we can use Qt to fetch to system font, current screen size and device pixel ratio (scale factor) for that screen.
User avatar
vanuan
Posts: 497
Joined: Wed Oct 24, 2018 9:49 pm

Re: Constraint icons size at Sketcher edit

Postby vanuan » Tue Dec 22, 2020 10:18 pm

abdullah wrote:
Mon Dec 21, 2020 8:10 am
1. Is it customary that icon size relates to font size?

What happens if I have an oversized text font in my system, not because I cannot read smaller text, but rather because I read a lot of text on the computer per day and I want to reduce my eye-strain. Do or should icons resize with my selected font size.
The official Qt HiDPI guide only tells you to replace hard-coded sizes with values calculated from font metrics or screen size.

It doesn't tell you to use the system font. But it is a sane thing to do as you're not forcing user to go through UI elements size setup process. If we want to provide user with an option to override App's font (which we do and have done in FreeCAD), It's a reasonable thing to scale all the fonts, not just the default one or related to a particular portion of UI (sketcher in this case). As we want the font size to communicate the hierarchy of UI elements.

So, to answer you question, it depends on what UI designer intends to do. Does UI designer want icon to be complementary to the text (as in sketcher constraints) or does UI element should take a portion of a screen (e.g. 10% of the window as in 3D axis arrows).
abdullah wrote:
Mon Dec 21, 2020 8:10 am
2. If yes, I see the comment about the two half-backed solutions. I see the lists of how an ideal solution should look like. What do you think is reasonable doing within the current limitations of FreeCAD.
There are several approaches how to get there. Here's one suggestion:

1. Add a setting for the sketcher font size to be defined in points (device independent font size)
2. Add a setting "sketcher device pixel ratio / scale factor" that by default is set from the device pixel ratio
3. Use the font size in points, logical DPI, device pixel ratio to figure out the font size in pixels
4. Scale icon size to be in relation to the sketcher font size
5. Scale different font sizes in relation to the sketcher font size
6. Propagate the sketcher font size and sketcher device pixel ration to be global for all the Coin3D elements (add a new setting "3D view font size / scale factor")
7. Propagate the 3D view settings to the whole app and use them in all the Qt UI elements.
8. Use font and scaling OS settings as defaults, while leaving user an option to override them.

Another approach would be to go vice versa: remove all the custom font settings using only what is provided by the OS / Qt and gradually replace all the hard-coded values to related units (either a percentage of a system font or a percentage of a screen size).

Please read the official Qt HiDPI guide. It's quite short. Shorter than the version I laid out on the wiki and here in the comments.
abdullah
Posts: 3883
Joined: Sun May 04, 2014 3:16 pm

Re: Constraint icons size at Sketcher edit

Postby abdullah » Mon Jan 04, 2021 6:55 pm

vanuan wrote:
Tue Dec 22, 2020 10:18 pm
Please read the official Qt HiDPI guide. It's quite short. Shorter than the version I laid out on the wiki and here in the comments.
Thank you for the information and kind indications. It was really helpful for me to have a reference.

After too much procrastinating, I am currently reviewing these PRs.

I have reviewed the one of Kilsore and I am now reviewing the one of Elyas-Crimean.

I will post here when I finish with my impressions.

Thanks again.
abdullah
Posts: 3883
Joined: Sun May 04, 2014 3:16 pm

Re: Constraint icons size at Sketcher edit (PR ready)

Postby abdullah » Tue Jan 05, 2021 3:04 pm

I have looked into both PRs and I think it may make sense to reuse both concepts into a single PR.

Analysis

PR #4155 proposes a scaling factor to be used to scale up constraint icons and the subindex font of icons. The
scaling factor is a parameter.

PR #4146 proposes to derive the constraint icon size from the system font size via function of the dpi. The
constraint icon subindex is a factor of the constraint size.

Observations:
  • PR #4146 identifies the need for a scaling factor too, but this is a hardcoded 1.25 factor.
  • PR #4146 appears to mix font points and font pixels when deriving the sizes.
  • PR #4155 deals exclusively with icon size and subindex font, not with constraint label
Useful concepts:
  • Font point is a physical distance. There are 72 points in one inch.
  • Monitors have pixels with varying pixel densities. The number of pixels in one point varies
    with pixel density. Hence the need for a correction based on the dpi of the monitor.
API constraints:

While QT's configuration can be obtained in points or pixels, coin3D sets the font size in points.

Proposed Way Forward
  • Stop relying on the local font setting from preferences.
  • Introduce a sketcher wide 3D view scaling factor, as per #4155, but relative to the system font size as per #4146.
  • Derive the 3D view font size from the system font size by applying the scaling factor (while taking into account the dpi). The font size of QT is the same as the font size of the 3D view if the scaling factor is 1.0 .
  • Derive the 3D view icon size to be the same size as the 3D view font size.
  • The constraint icon subindex, being a special case of font relative to the accompanying icon, is set to be the 80% of the
    icon size (hardcoded). I think it is not worth to provide this as a configurable parameter.
In code:
https://github.com/FreeCAD/FreeCAD/pull/4246

How does this look like?
Screenshot_20210105_160054.png
Screenshot_20210105_160054.png (45.77 KiB) Viewed 220 times
Screenshot_20210105_155952.png
Screenshot_20210105_155952.png (117.29 KiB) Viewed 220 times
Feel free to comment.
chrisb
Posts: 30822
Joined: Tue Mar 17, 2015 9:14 am

Re: Constraint icons size at Sketcher edit (PR ready)

Postby chrisb » Tue Jan 05, 2021 11:04 pm

Right now I have the feeling I would like to have two independent scale factors, or fontsize plus icon scale. But then I have to admit, that I lived for years with a fixed icon size and I never had changed to fontsize until I got a highdpi display.

Anotherthing which could be taken into account is the marker size as an indicator. I have the marker size increased, and it is impossible to select a symmetry in a point. This will probably vanish as soon as the icons are increased.
You need at least FreeCAD 0.19.23300 to edit my current sketches.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
abdullah
Posts: 3883
Joined: Sun May 04, 2014 3:16 pm

Re: Constraint icons size at Sketcher edit (PR ready)

Postby abdullah » Wed Jan 06, 2021 6:26 am

chrisb wrote:
Tue Jan 05, 2021 11:04 pm
Right now I have the feeling I would like to have two independent scale factors, or fontsize plus icon scale. But then I have to admit, that I lived for years with a fixed icon size and I never had changed to fontsize until I got a highdpi display.
I need to understand the rationale behind that wish.

In the proposed implementation fontsize is based on system font and thus takes into account the pixel density of the display. Implicitly you have a font selection in your system font. That is something that the user should be comfortable with. Then, because a 3D view may be trickier and people work long periods of time with it, the scale factor is applied on top, so your font will be, for example 125% of the system font.

Is there a graphical or cosmetic behaviour you do not like and make you wish you had two independent scale factors?
chrisb wrote:
Tue Jan 05, 2021 11:04 pm
Anotherthing which could be taken into account is the marker size as an indicator. I have the marker size increased, and it is impossible to select a symmetry in a point. This will probably vanish as soon as the icons are increased.
The marker size is a global preference (not under Sketcher preferences). It is provided in pixels. That could even be seen as a problem. Like in your case, you had to adjust up the value just by changing your monitor.

The global marker size is currently used by:
- The ViewProvider of the MeasureDistance tool (Gui/ViewProviderMeasureDistance.cpp)
- The ViewProvider of Path (Mod/Path/Gui/ViewProviderPath.cpp)
- FEM (Mod/Fem/Gui/TaskPostBoxes.cpp)
- The ViewProvider of the Datum point of PartDesign (Mod/PartDesign/Gui/ViewProviderDatumPoint.cpp)
- The validation tool of the Sketcher (Mod/Sketcher/Gui/TaskSketcherValidation.cpp)
- The ViewProvider of the Sketcher (Mod/Sketcher/Gui/ViewProviderSketch.cpp)
- The ViewProvider of defects of Mesh (Mod/Mesh/Gui/ViewProviderDefects.cpp)
- The ViewProvider of the Trajectory of the Robot WB (Mod/Robot/Gui/ViewProviderTrajectory.cpp)

I am not sure we should try to "change" the behaviour of the global marker size at this time. It is something that we could decide later (and I would invite Werner to comment on that).

I have also thought of making the Sketcher use a custom implementation of the marker size. Read (do not obey the global marker size, use it in part or not at all). The rationale could be that, if a user modifies the (new) scaling factor, the user wants constraint icons, fonts and markers to be increased in the same proportion.

So one could decide marker size as a fixed hardcoded factor of the font size scaled by the scaling factor. Alternatively, one could derive a second scaling factor from the marker size preference (for example: markersize/7, 7 being 7px, the default marker size). So, for example if somebody is selecting 15px, this second scaling factor would be around 2. So sketch marker size would be something like: 20% of fontsize * sketcher_scaling_factor (1.25) * marker_scaling_factor (2).

I am not sure that such implementation will work well and would not interfere with other functionalities like the selection mechanism. I have not looked at that code and I do not know it by heart.
chrisb
Posts: 30822
Joined: Tue Mar 17, 2015 9:14 am

Re: Constraint icons size at Sketcher edit (PR ready)

Postby chrisb » Wed Jan 06, 2021 9:24 am

Thanks for the detailed answer. For now I think you should do nothing beyond your proposal. I will wait until it is available in the precompiled version and have a look. I was too anxious with my previous post, because I hate clutter on the screen, so I like to have fonts and symbol as small as possible, but they have of course to be easily readable.
Best thing for now: ignore my previous post.
You need at least FreeCAD 0.19.23300 to edit my current sketches.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
abdullah
Posts: 3883
Joined: Sun May 04, 2014 3:16 pm

Re: Constraint icons size at Sketcher edit (PR ready)

Postby abdullah » Wed Jan 06, 2021 7:21 pm

Chennes interacted with me in GitHub.
Is it possible to make the setting apply to the current open sketch when you click "Apply" in the preferences? Also, I note that there are some things that are not scaled by the scale factor: vertex size and line widths are not affected. Is this intentional?
At the end, I have pushed new changes and commented as follows:
Following your request, I have added the scaling of basically all remaining sizes in pixels by the scaling factor. The scaling factor is the product of the dpi ratio with respect to the standard 96 dpi and the view scaling ratio from preferences.

I appreciate you give it a run in HDPI monitors. I run a 96 dpi environment, so testing is not optimal.

I am not sure about the default font size, so I am starting to side with Chrisb, that maybe it makes sense to have an extra box for font size, as it was before.
Ah! I wanted to comment on the Vertex. If you look at the code I even made some changes to scale vertex markers too. However, I have realised that if a user changes the marker size taking into account other WBs and the Sketcher implements its own scaling, at the end the Sketcher will have a double correction, which should be undesirable. So, marker size is not corrected by this PR.
As I was saying, I am not sure about the font size. I guess HDPI users may be happy about the "thicker" lines (which will be the same size in a HDPI and LDPI monitor).
Screenshot_20210106_201803.png
Screenshot_20210106_201803.png (46.66 KiB) Viewed 128 times
I am open to comments...