diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-08-16 17:32:51 +0200 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-10-17 20:38:16 +0200 |
commit | 7823c15c4dd68faa911d3807c8133f358854eb3e (patch) | |
tree | f3f937b5b5880b91f4597a00f43924cea9f8a8ec /dw/widget.hh | |
parent | a4301a9954d4835a4b87344b9b037a816b17286d (diff) |
Add support for aspect ratio in Widget
Images should preserve their own aspect ratio, which is determined by
the image buffer size, also known as the intrinsic size. Currently, when
a child requests a requisition to be corrected by correctRequisition(),
only the size was adjusted, ignoring the aspect ratio.
The new Widget ratio variable holds the desired aspect ratio for the
widget, and will only be taken into account when non-zero. In that case,
then correcting the requisition, a naive algorithm tries to first
increase the length of the small size to fill the preferred aspect
ratio. In the case that it is not enough, the larger size is then
decreased to fit the aspect ratio. And if that doesn't work either, the
aspect ratio is not enforced and the widget will be distorted.
There are special cases for correctRequisition() depending if the parent
exists or not. The same approach is taken for both cases, but using the
viewport size instead of the parent size.
Diffstat (limited to 'dw/widget.hh')
-rw-r--r-- | dw/widget.hh | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/dw/widget.hh b/dw/widget.hh index a7daa91d..8631b9db 100644 --- a/dw/widget.hh +++ b/dw/widget.hh @@ -207,6 +207,12 @@ protected: inline int getContentWidth() { return allocation.width - boxDiffWidth (); } inline int getContentHeight() { return getHeight () - boxDiffHeight (); } + /** + * Preferred aspect ratio of the widget. Set to 0 when there is none. It is + * computed as width / height. + */ + float ratio; + Layout *layout; /** @@ -351,18 +357,24 @@ protected: virtual int getAvailWidthOfChild (Widget *child, bool forceValue); virtual int getAvailHeightOfChild (Widget *child, bool forceValue); - virtual void setReqWidth (Requisition *requisition, int width); + virtual void correctRequisitionOfChild (Widget *child, Requisition *requisition, void (*splitHeightFun) (int, int*, int*), bool allowDecreaseWidth, bool allowDecreaseHeight); + void correctRequisitionViewport (Requisition *requisition, + void (*splitHeightFun) (int, int*, int*), + bool allowDecreaseWidth, bool allowDecreaseHeight); void correctReqWidthOfChild (Widget *child, Requisition *requisition, bool allowDecreaseWidth); void correctReqHeightOfChild (Widget *child, Requisition *requisition, void (*splitHeightFun) (int, int*, int*), bool allowDecreaseHeight); + bool correctReqAspectRatio (int pass, Widget *child, Requisition *requisition, + bool allowDecreaseWidth, bool allowDecreaseHeight, + void (*splitHeightFun) (int, int*, int*)); virtual void correctExtremesOfChild (Widget *child, Extremes *extremes, bool useAdjustmentWidth); |