mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[escher/scroll_view] Add arrow indicators
This commit is contained in:
committed by
EmilieNumworks
parent
1e958717fb
commit
1beb8ca98f
@@ -43,6 +43,22 @@ public:
|
||||
KDCoordinate m_barsFrameBreadth;
|
||||
};
|
||||
|
||||
class DecoratorV2 {
|
||||
public:
|
||||
DecoratorV2();
|
||||
int numberOfIndicators() { return 4; }
|
||||
View * indicatorAtIndex(int index) {
|
||||
assert(0 < index && index <= numberOfIndicators());
|
||||
return &m_topArrow + (index-1);
|
||||
}
|
||||
void layoutIndicators(KDSize content, KDPoint offset, KDSize frame);
|
||||
private:
|
||||
ScrollViewArrow m_topArrow;
|
||||
ScrollViewArrow m_rightArrow;
|
||||
ScrollViewArrow m_bottomArrow;
|
||||
ScrollViewArrow m_leftArrow;
|
||||
};
|
||||
|
||||
Decorator * decorator() { return &m_decorator; }
|
||||
void setShowsIndicators(bool s) { m_showsIndicators = s; }
|
||||
bool showsIndicators() const { return m_showsIndicators; }
|
||||
|
||||
@@ -43,4 +43,21 @@ private:
|
||||
KDCoordinate totalLength() const { return m_frame.height() - 2*m_margin; }
|
||||
};
|
||||
|
||||
class ScrollViewArrow : public ScrollViewIndicator {
|
||||
public:
|
||||
enum Side : char { //FIXME
|
||||
Top = 't',
|
||||
Right = '>',
|
||||
Bottom = 'b',
|
||||
Left = '<'
|
||||
};
|
||||
ScrollViewArrow(Side side);
|
||||
bool update(bool visible);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
bool m_visible;
|
||||
const char m_arrow;
|
||||
KDColor m_backgroundColor;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -175,6 +175,38 @@ void ScrollView::Decorator::layoutIndicators(KDSize content, KDPoint offset, KDS
|
||||
));
|
||||
}
|
||||
|
||||
ScrollView::DecoratorV2::DecoratorV2() :
|
||||
m_topArrow(ScrollViewArrow::Side::Top),
|
||||
m_rightArrow(ScrollViewArrow::Side::Right),
|
||||
m_bottomArrow(ScrollViewArrow::Side::Bottom),
|
||||
m_leftArrow(ScrollViewArrow::Side::Left)
|
||||
{
|
||||
}
|
||||
|
||||
void ScrollView::DecoratorV2::layoutIndicators(KDSize content, KDPoint offset, KDSize frame) {
|
||||
KDSize arrowSize = KDFont::LargeFont->glyphSize();
|
||||
KDCoordinate topArrowFrameBreadth = arrowSize.height() * m_topArrow.update(0 < offset.y());
|
||||
KDCoordinate rightArrowFrameBreadth = arrowSize.width() * m_rightArrow.update(offset.x() + frame.width() < content.width());
|
||||
KDCoordinate bottomArrowFrameBreadth = arrowSize.height() * m_bottomArrow.update(offset.y() + frame.height() < content.height());
|
||||
KDCoordinate leftArrowFrameBreadth = arrowSize.width() * m_leftArrow.update(0 < offset.x());
|
||||
m_topArrow.setFrame(KDRect(
|
||||
0, 0,
|
||||
frame.width(), topArrowFrameBreadth
|
||||
));
|
||||
m_rightArrow.setFrame(KDRect(
|
||||
frame.width() - rightArrowFrameBreadth, 0,
|
||||
rightArrowFrameBreadth, frame.height()
|
||||
));
|
||||
m_bottomArrow.setFrame(KDRect(
|
||||
0, frame.height() - bottomArrowFrameBreadth,
|
||||
frame.width(), bottomArrowFrameBreadth
|
||||
));
|
||||
m_leftArrow.setFrame(KDRect(
|
||||
0, 0,
|
||||
leftArrowFrameBreadth, frame.height()
|
||||
));
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * ScrollView::className() const {
|
||||
return "ScrollView";
|
||||
|
||||
@@ -72,6 +72,30 @@ void ScrollViewVerticalBar::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
);
|
||||
}
|
||||
|
||||
ScrollViewArrow::ScrollViewArrow(Side side) :
|
||||
m_visible(false),
|
||||
m_arrow(side)
|
||||
{
|
||||
}
|
||||
|
||||
bool ScrollViewArrow::update(bool visible) {
|
||||
if (m_visible != visible) {
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
m_visible = visible;
|
||||
return visible;
|
||||
}
|
||||
|
||||
void ScrollViewArrow::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(bounds(), m_backgroundColor);
|
||||
KDSize arrowSize = KDFont::LargeFont->glyphSize();
|
||||
const KDPoint arrowAlign = KDPoint(
|
||||
(m_arrow == Top || m_arrow == Bottom) * (m_frame.width() - arrowSize.width()) / 2,
|
||||
(m_arrow == Left || m_arrow == Right) * (m_frame.height() - arrowSize.height()) / 2
|
||||
);
|
||||
ctx->drawString(&m_arrow, arrowAlign, KDFont::LargeFont, m_color, m_backgroundColor, m_visible);
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * ScrollViewIndicator::className() const {
|
||||
return "ScrollViewIndicator";
|
||||
|
||||
Reference in New Issue
Block a user