fix issue that progress is incorrect when it is resized

This commit is contained in:
Jinhao 2017-11-19 07:04:34 +08:00
parent 77f7bdb37c
commit 14cc7cdaa1

View File

@ -91,20 +91,27 @@ namespace nana
{ {
return value_px_; return value_px_;
} }
private:
void _m_try_refresh()
{
if (nullptr == widget_)
return;
bool value_px_sync()
{
if (widget_)
{
auto value_px = (widget_->size().width - border_px * 2) * value_ / max_; auto value_px = (widget_->size().width - border_px * 2) * value_ / max_;
if (value_px != value_px_) if (value_px != value_px_)
{ {
value_px_ = value_px; value_px_ = value_px;
API::refresh_window(*widget_); return true;
} }
} }
return false;
}
private:
void _m_try_refresh()
{
if (value_px_sync())
API::refresh_window(*widget_);
}
private: private:
nana::progress * widget_{ nullptr }; nana::progress * widget_{ nullptr };
unsigned max_{ 100 }; unsigned max_{ 100 };
@ -144,6 +151,9 @@ namespace nana
auto rt_bground = rt_val; auto rt_bground = rt_val;
if (false == progress_->unknown(nullptr)) 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<int>(progress_->value_px()) + static_cast<int>(border_px); rt_bground.x = static_cast<int>(progress_->value_px()) + static_cast<int>(border_px);
rt_bground.width -= progress_->value_px(); rt_bground.width -= progress_->value_px();