Browse Source

Fix widget margins for a few special cases

Signed-off-by: falkTX <falktx@falktx.com>
pull/344/head
falkTX 2 years ago
parent
commit
cac786dcf6
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 20 additions and 11 deletions
  1. +14
    -5
      dgl/src/SubWidget.cpp
  2. +6
    -6
      dgl/src/WidgetPrivateData.cpp

+ 14
- 5
dgl/src/SubWidget.cpp View File

@@ -35,8 +35,8 @@ template<typename T>
bool SubWidget::contains(const T x, const T y) const noexcept
{
return Rectangle<double>(0, 0,
static_cast<double>(getWidth()) - pData->margin.getX(),
static_cast<double>(getHeight()) - pData->margin.getY()).contains(x, y);
static_cast<double>(getWidth()),
static_cast<double>(getHeight())).contains(x, y);
}

template<typename T>
@@ -67,9 +67,18 @@ Rectangle<int> SubWidget::getAbsoluteArea() const noexcept

Rectangle<uint> SubWidget::getConstrainedAbsoluteArea() const noexcept
{
return Rectangle<uint>(static_cast<uint>(std::max(0, getAbsoluteX())),
static_cast<uint>(std::max(0, getAbsoluteY())),
getSize());
const int x = getAbsoluteX();
const int y = getAbsoluteY();

if (x >= 0 && y >= 0)
return Rectangle<uint>(x, y, getSize());

const int xOffset = std::min(0, x);
const int yOffset = std::min(0, y);
const int width = std::max(0, static_cast<int>(getWidth()) + xOffset);
const int height = std::max(0, static_cast<int>(getHeight()) + yOffset);

return Rectangle<uint>(0, 0, static_cast<uint>(width), static_cast<uint>(height));
}

void SubWidget::setAbsoluteX(const int x) noexcept


+ 6
- 6
dgl/src/WidgetPrivateData.cpp View File

@@ -119,8 +119,8 @@ bool Widget::PrivateData::giveMouseEventForSubWidgets(MouseEvent& ev)
{
if (selfw->pData->needsViewportScaling)
{
ev.absolutePos.setX(x - selfw->getAbsoluteX());
ev.absolutePos.setY(y - selfw->getAbsoluteY());
ev.absolutePos.setX(x - selfw->getAbsoluteX() + selfw->getMargin().getX());
ev.absolutePos.setY(y - selfw->getAbsoluteY() + selfw->getMargin().getY());
}
}

@@ -155,8 +155,8 @@ bool Widget::PrivateData::giveMotionEventForSubWidgets(MotionEvent& ev)
{
if (selfw->pData->needsViewportScaling)
{
ev.absolutePos.setX(x - selfw->getAbsoluteX());
ev.absolutePos.setY(y - selfw->getAbsoluteY());
ev.absolutePos.setX(x - selfw->getAbsoluteX() + selfw->getMargin().getX());
ev.absolutePos.setY(y - selfw->getAbsoluteY() + selfw->getMargin().getY());
}
}

@@ -191,8 +191,8 @@ bool Widget::PrivateData::giveScrollEventForSubWidgets(ScrollEvent& ev)
{
if (selfw->pData->needsViewportScaling)
{
ev.absolutePos.setX(x - selfw->getAbsoluteX());
ev.absolutePos.setY(y - selfw->getAbsoluteY());
ev.absolutePos.setX(x - selfw->getAbsoluteX() + selfw->getMargin().getX());
ev.absolutePos.setY(y - selfw->getAbsoluteY() + selfw->getMargin().getY());
}
}



Loading…
Cancel
Save