pencil2d / pencil

Pencil2D is an easy, intuitive tool to make 2D hand-drawn animations. Pencil2D is open source and cross-platform.
http://pencil2d.org
GNU General Public License v2.0
1.48k stars 273 forks source link

Improve dock layout for lower resolution #1840

Closed MrStevns closed 3 months ago

MrStevns commented 6 months ago

A follow up PR from #1824

I've adjusted the margin as well as the min width for all the dock widgets so they are aligned. In addition the font has also been adjusted from 13 pt to 11 pt.

The result looks like this:

image

Front: new layout Back: old layout

The widgets that had the greatest impact adjusting this was the tool options widget as well as the onion skin widget.

Side by side: Old New
image image
Adjusting the font also helped quite a bit. 11 point font size 13 point font size
image image
142 px 162 px

I've also added extra QLayout around certain elements, which is not a mistake. Doing so fixes some problems where Qt added extra margins around checkboxes and labels.

chchwy commented 6 months ago

Would you be able to change the margins of the flowlayout in the toolbox as well? It should be at toolbox.cpp line141 something like:

FlowLayout* flowlayout = new FlowLayout(0, 3, 3);
MrStevns commented 6 months ago

I played around with that too, though it causes the widget to never go into one vertical line, at least on mac.

3 px margin 0 px margin
image image

It bothers me a bit but I can't figure out how to force the layout into submission. For some reason it won't get smaller than 60 px or so... even though I believe i've tweaked all possible values. I must be missing something.

edit: Aha! it's the title widget that enforces the min width.

chchwy commented 6 months ago

It bothers me a bit but I can't figure out how to force the layout into submission. For some reason it won't get smaller than 60 px or so... even though I believe i've tweaked all possible values. I must be missing something.

edit: Aha! it's the title widget that enforces the min width.

yea, title bar is to blame.

MrStevns commented 6 months ago

Small improvement. The toolbox can now also be shrunk down when laid out horizontally. dock-widget-layout2

MrStevns commented 6 months ago

Hmm not sure what's up but the font looks larger on some of the widgets on my windows machine. it looks like setting the font point size specifically almost has the opposite effect on windows... sigh šŸ˜©

https://forum.qt.io/topic/125993/font-point-size-weird-behaviour-on-windows I found this and some other threads mentioning similar problems... what a can of worms.

image

Sure we could just go back to the old font but seriously... Qt, you had one job.

MrStevns commented 6 months ago

Fixed. The "solution" is to use qstylesheet instead. In this case i'm setting the font-size of all widgets that are children of BaseDockWidget.

image
MrStevns commented 6 months ago

I have also tested these changes on a linux distro now.

image
J5lx commented 6 months ago

The overall direction of this PR looks fine to me, but thereā€™s something weird going on with the font size. On Windows, it looks practically unchanged except for the title bars, whereas on Linux the text is painfully tiny for me, much smaller than the default font size (note the status bar for comparison): image My theory is that this is because of the way youā€™re hard-coding the font size. I experimented around a little and found that setting the font size to 86% (first screenshot) of the global default gave me a result that (subjectively) seemed much closer to the effect seen in your original screenshots, while 85% (second screenshot), which is closer to your original 11/13 ratio, still looked a little too small for my liking but still better than the original hard-coded 11px. image image For reference, Iā€™m using setStyleSheet(QString("QWidget { font-size: %1pt }").arg(.86 * QFont().pointSizeF())); (pixelSize() does not work). Note that I havenā€™t tried this on Windows yet.

Also, on Qt 6, I now get a new warning in the console:

Init Dock widget: "TimeLine" Init Dock widget: "ColorWheel" Init Dock widget: "Color Inspector" Init Dock widget: "ColorPalette" Init Dock widget: "Onion Skin" Init Dock widget: "ToolOption" QWidget::setMinimumSize: (scrollArea/QScrollArea) Negative sizes (0,-1) are not possible Init Dock widget: "ToolBox"

And lastly, your most recent commit seems to have broken the colour inspector preview somehow, it now defaults to the standard widget background on startup. Not sure what exactly is going on thereā€¦

MrStevns commented 6 months ago

Thanks for testing it out. šŸ‘

On Windows, it looks practically unchanged except for the title bars, whereas on Linux the text is painfully tiny for me, much smaller than the default font size (note the status bar for comparison):

I've reverted the font change again. This seems to be one of the those things that require a greater understanding of Qt in order to change properly, so we'll keep the same font for now. I don't like the idea of scaling the font with some arbitrary number. It must be possible to use proper px or pt values and then it's a matter of figuring out how those work in Qt compared to web, if it's css they're basing their logic of.

Also, on Qt 6, I now get a new warning in the console:

I'll fix that.

J5lx commented 6 months ago

I don't like the idea of scaling the font with some arbitrary number. It must be possible to use proper px or pt values and then it's a matter of figuring out how those work in Qt compared to web, if it's css they're basing their logic of.

ā€œScaling the font with some arbitrary numberā€ is pretty standard on the web and generally recommended for accessibility, Iā€™m not sure whatā€™s the problem with it. E.g. the main font size on our forum is 0.938em, and I havenā€™t changed it. If you have something else in mind, sure. But please consider taking the system default as a base in one way or another since we mainly use native styling.

MrStevns commented 3 months ago

ā€œScaling the font with some arbitrary numberā€ is pretty standard on the web and generally recommended for accessibility, Iā€™m not sure whatā€™s the problem with it. E.g. the main font size on our forum is 0.938em, and I havenā€™t changed it. If you have something else in mind, sure. But please consider taking the system default as a base in one way or another since we mainly use native styling.

Alright fair enough, I'm used to mobile development where it's not like this but if that's how it's done, then we'll do it like that. I've reverted the font changes now though, instead I think it would be wiser to create a font size preference, so the user can control this themselves. That's out of scope for this PR though.

And lastly, your most recent commit seems to have broken the colour inspector preview somehow, it now defaults to the standard widget background on startup. Not sure what exactly is going on thereā€¦

This was caused by a style override which has been reverted.

Would you mind reviewing again @J5lx

MrStevns commented 3 months ago

Hmm strange, it's not something i'm seeing in my build anymore. I'm using Qt 6.7.0, what version are you on?

Also, is this with the default layout or have you moved the docks around?

J5lx commented 3 months ago

Iā€™m on 6.7.2 and seeing that warning with the default layout although, upon closer inspection, only some of the time. I did some debugging and I found thereā€™s at least two issues at play here. The first one is only indirectly related to the warning, but could very well be the reason why youā€™re not seeing it. Thatā€™s because at its very end, initUI calls getMinHeightForWidth which reads mDockArea. However, mDockArea is only written in the dockLocationChanged signal handler which was only connected earlier in initUI. Therefore the mDockArea value is uninitialized at that time and reading it in getMinHeightForWidth results in undefined behaviour ā€“ sometimes the if branch executes, other times the ā€œelse branchā€.

Only in the latter case does the second issue occur which is what actually causes the warning. Thatā€™s because at this point in time, BaseDockWidget::getMinHeightForWidth always returns -1, which is then directly passed directly into setMinimumHeight in initUI, resulting in the warning ā€œQWidget::setMinimumSize: (scrollArea/QScrollArea) Negative sizes (0,-1) are not possibleā€.

MrStevns commented 3 months ago

Ah... good point regarding mDockArea being uninitialized, I forget that it was an enum šŸ˜…

I've made a few changes, though i'm unsure about whether we should simply change -1 to 1 in BaseDockWidget rather than me simply not calling the base class at all, if it always gives a warning. What do you think?

J5lx commented 3 months ago

Since you brought up BaseDockWidget, I had a closer look at it and realised that the entire min height handling in there is actually entirely Toolbox-specific and it can be simplified a bit by consolidating that in Toolbox itself. Please take a look: MrStevns#23

MrStevns commented 3 months ago

Thanks Jakob! šŸ™