From 14cc7cdaa1b3959e27a1ac54f81679c5fc555793 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 19 Nov 2017 07:04:34 +0800 Subject: [PATCH] fix issue that progress is incorrect when it is resized --- source/gui/widgets/progress.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/source/gui/widgets/progress.cpp b/source/gui/widgets/progress.cpp index 20b46ddc..2c498f7c 100644 --- a/source/gui/widgets/progress.cpp +++ b/source/gui/widgets/progress.cpp @@ -91,19 +91,26 @@ namespace nana { return value_px_; } + + bool value_px_sync() + { + if (widget_) + { + auto value_px = (widget_->size().width - border_px * 2) * value_ / max_; + + if (value_px != value_px_) + { + value_px_ = value_px; + return true; + } + } + return false; + } private: void _m_try_refresh() { - if (nullptr == widget_) - return; - - auto value_px = (widget_->size().width - border_px * 2) * value_ / max_; - - if (value_px != value_px_) - { - value_px_ = value_px; + if (value_px_sync()) API::refresh_window(*widget_); - } } private: nana::progress * widget_{ nullptr }; @@ -144,6 +151,9 @@ namespace nana auto rt_bground = rt_val; if (false == progress_->unknown(nullptr)) { + //Sync the value_px otherwise the progress is incorrect when it is resized. + progress_->value_px_sync(); + rt_bground.x = static_cast(progress_->value_px()) + static_cast(border_px); rt_bground.width -= progress_->value_px();