diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-08-16 13:19:26 +0200 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2024-10-17 20:38:16 +0200 |
commit | 49623838743ad69811dd8348c57ca0baed46934c (patch) | |
tree | 25f38db754a740e0880e6c7c1cc455e618033e03 /dw/image.cc | |
parent | b6c8599a5acdaddccca102bae4370316beaa1915 (diff) |
Allow widgets to adjust new requisition
When a widget calls the parent to correct its own requisition, let the
child widget perform adjustments on the requisition. This allows images
to control the height when the parent changes the width, so the image
can preserve its own aspect ratio.
Diffstat (limited to 'dw/image.cc')
-rw-r--r-- | dw/image.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/dw/image.cc b/dw/image.cc index 44a1ff45..603f2964 100644 --- a/dw/image.cc +++ b/dw/image.cc @@ -402,6 +402,22 @@ void Image::sizeRequestSimpl (core::Requisition *requisition) DBG_OBJ_LEAVE (); } +void Image::setReqWidth(core::Requisition *requisition, int width) +{ + /* If we have the image buffer, try to set the height to preserve the image + * ratio */ + if (buffer) { + int w = buffer->getRootWidth(); + int h = buffer->getRootHeight(); + float ratio = (float) h / (float) w; + int height = (float) width * ratio; + /* Preserve descent */ + requisition->ascent = height - requisition->descent; + } + + requisition->width = width; +} + void Image::getExtremesSimpl (core::Extremes *extremes) { int contentWidth; |