mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-02 04:20:16 +00:00
Minor changes in ui::View
This commit is contained in:
parent
a08cfa9e13
commit
eed5f98b75
@ -11,6 +11,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "base/clamp.h"
|
||||||
#include "gfx/size.h"
|
#include "gfx/size.h"
|
||||||
#include "ui/intern.h"
|
#include "ui/intern.h"
|
||||||
#include "ui/manager.h"
|
#include "ui/manager.h"
|
||||||
@ -31,6 +32,7 @@
|
|||||||
#include "os/surface.h"
|
#include "os/surface.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
#define HBAR_SIZE (m_scrollbar_h.getBarWidth())
|
#define HBAR_SIZE (m_scrollbar_h.getBarWidth())
|
||||||
@ -97,7 +99,7 @@ void View::showScrollBars()
|
|||||||
updateView();
|
updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
Size View::getScrollableSize()
|
Size View::getScrollableSize() const
|
||||||
{
|
{
|
||||||
return Size(m_scrollbar_h.size(),
|
return Size(m_scrollbar_h.size(),
|
||||||
m_scrollbar_v.size());
|
m_scrollbar_v.size());
|
||||||
@ -247,11 +249,7 @@ void View::onSetViewScroll(const gfx::Point& pt)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Point oldScroll = viewScroll();
|
Point oldScroll = viewScroll();
|
||||||
Size maxsize = getScrollableSize();
|
Point newScroll = limitScrollPosToViewport(pt);
|
||||||
Size visible = visibleSize();
|
|
||||||
Point newScroll(MID(0, pt.x, MAX(0, maxsize.w - visible.w)),
|
|
||||||
MID(0, pt.y, MAX(0, maxsize.h - visible.h)));
|
|
||||||
|
|
||||||
if (newScroll == oldScroll)
|
if (newScroll == oldScroll)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -374,4 +372,12 @@ void View::onScrollChange()
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gfx::Point View::limitScrollPosToViewport(const gfx::Point& pt) const
|
||||||
|
{
|
||||||
|
const Size maxSize = getScrollableSize();
|
||||||
|
const Size visible = visibleSize();
|
||||||
|
return Point(base::clamp(pt.x, 0, std::max(0, maxSize.w - visible.w)),
|
||||||
|
base::clamp(pt.y, 0, std::max(0, maxSize.h - visible.h)));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
|
@ -42,7 +42,7 @@ namespace ui {
|
|||||||
|
|
||||||
// Returns the maximum viewable size requested by the attached
|
// Returns the maximum viewable size requested by the attached
|
||||||
// widget in the viewport.
|
// widget in the viewport.
|
||||||
gfx::Size getScrollableSize();
|
gfx::Size getScrollableSize() const;
|
||||||
void setScrollableSize(const gfx::Size& sz,
|
void setScrollableSize(const gfx::Size& sz,
|
||||||
const bool setScrollPos = true);
|
const bool setScrollPos = true);
|
||||||
|
|
||||||
@ -71,6 +71,8 @@ namespace ui {
|
|||||||
virtual void onScrollChange();
|
virtual void onScrollChange();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
gfx::Point limitScrollPosToViewport(const gfx::Point& pt) const;
|
||||||
|
|
||||||
bool m_hasBars;
|
bool m_hasBars;
|
||||||
Viewport m_viewport;
|
Viewport m_viewport;
|
||||||
ScrollBar m_scrollbar_h;
|
ScrollBar m_scrollbar_h;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user