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,19 +91,26 @@ namespace nana
{ {
return value_px_; 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: private:
void _m_try_refresh() void _m_try_refresh()
{ {
if (nullptr == widget_) if (value_px_sync())
return;
auto value_px = (widget_->size().width - border_px * 2) * value_ / max_;
if (value_px != value_px_)
{
value_px_ = value_px;
API::refresh_window(*widget_); API::refresh_window(*widget_);
}
} }
private: private:
nana::progress * widget_{ nullptr }; nana::progress * widget_{ nullptr };
@ -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();