UI: rich_image_view use loop instead of calling reshape & region_changed directly
This commit is contained in:
parent
3c4e1f99df
commit
49b58f76c5
2 changed files with 15 additions and 4 deletions
|
|
@ -53,6 +53,8 @@ namespace psemek::ui
|
||||||
bool mouseover_ = false;
|
bool mouseover_ = false;
|
||||||
std::optional<geom::point<int, 2>> mouse_;
|
std::optional<geom::point<int, 2>> mouse_;
|
||||||
std::optional<geom::point<int, 2>> drag_;
|
std::optional<geom::point<int, 2>> drag_;
|
||||||
|
|
||||||
|
void post_region_changed();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@ namespace psemek::ui
|
||||||
void rich_image_view::set_image(std::shared_ptr<gfx::texture_2d> image)
|
void rich_image_view::set_image(std::shared_ptr<gfx::texture_2d> image)
|
||||||
{
|
{
|
||||||
image_ = std::move(image);
|
image_ = std::move(image);
|
||||||
element::reshape();
|
post_reshape();
|
||||||
on_region_changed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rich_image_view::set_zoom_range(geom::interval<float> range)
|
void rich_image_view::set_zoom_range(geom::interval<float> range)
|
||||||
|
|
@ -35,7 +34,7 @@ namespace psemek::ui
|
||||||
|
|
||||||
center_ = geom::clamp(center_, b);
|
center_ = geom::clamp(center_, b);
|
||||||
}
|
}
|
||||||
on_region_changed();
|
post_region_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void rich_image_view::set_zoom(float zoom)
|
void rich_image_view::set_zoom(float zoom)
|
||||||
|
|
@ -135,7 +134,7 @@ namespace psemek::ui
|
||||||
void rich_image_view::reshape(geom::box<float, 2> const & bbox)
|
void rich_image_view::reshape(geom::box<float, 2> const & bbox)
|
||||||
{
|
{
|
||||||
shape_.box = bbox;
|
shape_.box = bbox;
|
||||||
on_region_changed();
|
post_region_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void rich_image_view::draw(painter & p) const
|
void rich_image_view::draw(painter & p) const
|
||||||
|
|
@ -171,4 +170,14 @@ namespace psemek::ui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rich_image_view::post_region_changed()
|
||||||
|
{
|
||||||
|
auto weak_self = std::weak_ptr{std::dynamic_pointer_cast<rich_image_view>(shared_from_this())};
|
||||||
|
post([weak_self]{
|
||||||
|
auto self = weak_self.lock();
|
||||||
|
if (!self) return;
|
||||||
|
self->on_region_changed();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue