aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/image.cc16
-rw-r--r--dw/image.hh1
-rw-r--r--dw/widget.cc19
-rw-r--r--dw/widget.hh1
4 files changed, 36 insertions, 1 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;
diff --git a/dw/image.hh b/dw/image.hh
index ae47f307..5d890c4e 100644
--- a/dw/image.hh
+++ b/dw/image.hh
@@ -130,6 +130,7 @@ private:
bool isMap;
protected:
+ void setReqWidth(core::Requisition *requisition, int width);
void sizeRequestSimpl (core::Requisition *requisition);
void getExtremesSimpl (core::Extremes *extremes);
void sizeAllocateImpl (core::Allocation *allocation);
diff --git a/dw/widget.cc b/dw/widget.cc
index 1099ee77..ce5286b9 100644
--- a/dw/widget.cc
+++ b/dw/widget.cc
@@ -1873,6 +1873,17 @@ void Widget::correctRequisitionOfChild (Widget *child, Requisition *requisition,
requisition->descent);
}
+void Widget::setReqWidth (Requisition *requisition, int width)
+{
+ /* Naive implementation */
+ requisition->width = width;
+}
+
+/** Correct a child requisition to fit the parent.
+ *
+ * The \param requisition is adjusted in width so it fits in the current widget
+ * (parent).
+ */
void Widget::correctReqWidthOfChild (Widget *child, Requisition *requisition,
bool allowDecreaseWidth)
{
@@ -1887,8 +1898,14 @@ void Widget::correctReqWidthOfChild (Widget *child, Requisition *requisition,
if (!allowDecreaseWidth && limitMinWidth < requisition->width)
limitMinWidth = requisition->width;
+ int width = requisition->width;
child->calcFinalWidth (child->getStyle(), -1, this, limitMinWidth, true,
- &requisition->width);
+ &width);
+
+
+ /* Ask the child widget to adjust its own requisition in case it has to
+ * modify the height too (like images to try to preserve the aspect ratio) */
+ child->setReqWidth(requisition, width);
DBG_OBJ_LEAVE_VAL ("%d * (%d + %d)", requisition->width, requisition->ascent,
requisition->descent);
diff --git a/dw/widget.hh b/dw/widget.hh
index 1787be1f..a7daa91d 100644
--- a/dw/widget.hh
+++ b/dw/widget.hh
@@ -351,6 +351,7 @@ 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*,