Browse Source

Grid: Ensure that items with absolute sizes will maintain correctly rounded dimensions

Prior to this commit all Grid calculations were carried out using
floating point numbers. The dimensions of all items would then be
rounded with the same function to calculate the integer dimensions used
for Component layout. This resulted in layout solutions where the width
or height of items with dimensions specified using the absolute Px
quantity could differ from the correctly rounded value of these values.

This commit ensures that the width and height of these items are always
correct and their cumulative error in size is distributed among items
with fractional dimensions.
v7.0.9
attila 2 years ago
parent
commit
a6761f9eb8
3 changed files with 913 additions and 727 deletions
  1. +29
    -0
      BREAKING-CHANGES.txt
  2. +883
    -723
      modules/juce_gui_basics/layout/juce_Grid.cpp
  3. +1
    -4
      modules/juce_gui_basics/layout/juce_Grid.h

+ 29
- 0
BREAKING-CHANGES.txt View File

@@ -4,6 +4,35 @@ JUCE breaking changes
develop
=======

Change
------
The Grid layout algorithm has been slightly altered to provide more consistent
behaviour. The new approach guarantees that dimensions specified using the
absolute Px quantity will always be correctly rounded when applied to the
integer dimensions of Components.

Possible Issues
---------------
Components laid out using Grid can observe a size or position change of +/- 1px
along each dimension compared with the result of the previous algorithm.

Workaround
----------
If the Grid based graphical layout is sensitive to changes of +/- 1px, then the
UI layout code may have to be adjusted to the new algorithm.

Rationale
---------
The old Grid layout algorithm could exhibit surprising and difficult to control
single pixel artifacts, where an item with a specified absolute size of
e.g. 100px could end up with a layout size of 101px. The new approach
guarantees that such items will have a layout size exactly as specified, and
this new behaviour is also in line with CSS behaviour in browsers. The new
approach makes necessary corrections easier as adding 1px to the size of an
item with absolute dimensions is guaranteed to translate into an observable 1px
increase in the layout size.


Change
------
The k91_4 and k90_4 VST3 layouts are now mapped to the canonical JUCE 9.1.4 and


+ 883
- 723
modules/juce_gui_basics/layout/juce_Grid.cpp
File diff suppressed because it is too large
View File


+ 1
- 4
modules/juce_gui_basics/layout/juce_Grid.h View File

@@ -216,10 +216,7 @@ public:
private:
//==============================================================================
struct SizeCalculation;
struct PlacementHelpers;
struct AutoPlacement;
struct BoxAlignment;
struct Helpers;
};
constexpr Grid::Px operator"" _px (long double px) { return Grid::Px { px }; }


Loading…
Cancel
Save