From 0b4b3b1332fcf6b8fbf3081b862ce2ed389978fc Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Wed, 15 Jun 2022 21:15:29 +0300 Subject: [PATCH] add resize_fixed() function for widgets --- src/Widget.cpp | 17 +++++++++++++++++ src/Widget.hpp | 1 + 2 files changed, 18 insertions(+) diff --git a/src/Widget.cpp b/src/Widget.cpp index 687f800..a98ac42 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -41,6 +41,23 @@ bool Widget::resize(double width, double height) { return true; } +bool Widget::resize_fixed(double width, double height) { + if (m_rect.width() == width && m_rect.height() == height) + return false; + + if (width < 0 || height < 0) + return false; + + m_rect.set_max_width(width); + m_rect.set_max_height(height); + m_rect.set_min_width(width); + m_rect.set_min_height(height); + m_rect.set_width(width); + m_rect.set_height(height); + reflow(); + return true; +} + void Widget::move_to(double x, double y) { if (m_rect.x() == x && m_rect.y() == y) return; diff --git a/src/Widget.hpp b/src/Widget.hpp index 95084ec..fc6b626 100644 --- a/src/Widget.hpp +++ b/src/Widget.hpp @@ -48,6 +48,7 @@ public: void move_to(double x, double y); bool resize(double width, double height); + bool resize_fixed(double width, double height); bool resize(Point &point) { return resize(point.x(), point.y()); } std::vector> &children() { return m_children; }