mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[escher] Improve scroll indicator render
Change-Id: I22fa1035ba33d2cadfc68fa6727fbaecdadd4efe
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Home {
|
||||
Controller::Controller(Responder * parentResponder, ::AppsContainer * container) :
|
||||
ViewController(parentResponder),
|
||||
m_container(container),
|
||||
m_selectableTableView(SelectableTableView(this, this, 0, 4, 0, 4, this, true, true, KDColorWhite))
|
||||
m_selectableTableView(SelectableTableView(this, this, 0, 4, 0, 4, this, true, true, KDColorWhite, 28, Palette::YellowOne, Palette::GreyMiddle, 116))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@ class ScrollView : public View {
|
||||
public:
|
||||
ScrollView(View * contentView, KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0,
|
||||
KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0, bool showIndicators = true,
|
||||
bool colorBackground = true, KDColor backgroundColor = Palette::WallScreen);
|
||||
bool colorBackground = true, KDColor backgroundColor = Palette::WallScreen, KDCoordinate indicatorThickness = 10,
|
||||
KDColor indicatorColor = Palette::GreyMiddle, KDColor backgroundIndicatorColor = Palette::GreyWhite,
|
||||
KDCoordinate indicatorMargin = 14);
|
||||
|
||||
void setContentOffset(KDPoint offset);
|
||||
KDPoint contentOffset();
|
||||
@@ -28,7 +30,6 @@ protected:
|
||||
#endif
|
||||
private:
|
||||
KDPoint m_offset;
|
||||
constexpr static KDCoordinate k_indicatorThickness = 10;
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
|
||||
@@ -40,6 +41,7 @@ private:
|
||||
KDCoordinate m_rightMargin;
|
||||
KDCoordinate m_bottomMargin;
|
||||
KDCoordinate m_leftMargin;
|
||||
KDCoordinate m_indicatorThickness;
|
||||
bool m_showIndicators;
|
||||
bool m_colorBackground;
|
||||
KDColor m_backgroundColor;
|
||||
|
||||
@@ -9,7 +9,7 @@ public:
|
||||
Horizontal,
|
||||
Vertical
|
||||
};
|
||||
ScrollViewIndicator(Direction direction);
|
||||
ScrollViewIndicator(Direction direction, KDColor indicatorColor, KDColor backgroundColor, KDCoordinate margin);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
|
||||
float start() const;
|
||||
@@ -22,9 +22,13 @@ protected:
|
||||
virtual void logAttributes(std::ostream &os) const override;
|
||||
#endif
|
||||
private:
|
||||
constexpr static KDCoordinate k_indicatorThickness = 4;
|
||||
Direction m_direction;
|
||||
float m_start;
|
||||
float m_end;
|
||||
KDColor m_indicatorColor;
|
||||
KDColor m_backgroundColor;
|
||||
KDCoordinate m_margin;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -19,7 +19,10 @@ public:
|
||||
SelectableTableView(Responder * parentResponder, TableViewDataSource * dataSource,
|
||||
KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0,
|
||||
KDCoordinate leftMargin = 0, SelectableTableViewDelegate * delegate = nullptr,
|
||||
bool showIndicators = true, bool colorBackground = true, KDColor backgroundColor = Palette::WallScreen);
|
||||
bool showIndicators = true, bool colorBackground = true, KDColor backgroundColor = Palette::WallScreen,
|
||||
KDCoordinate indicatorThickness = 10, KDColor indicatorColor = Palette::GreyMiddle,
|
||||
KDColor backgroundIndicatorColor = Palette::GreyWhite, KDCoordinate indicatorMargin = 14);
|
||||
|
||||
int selectedRow();
|
||||
int selectedColumn();
|
||||
virtual bool handleEvent(Ion::Events::Event event) override;
|
||||
|
||||
@@ -10,7 +10,9 @@ class TableView : public ScrollView {
|
||||
public:
|
||||
TableView(TableViewDataSource * dataSource, KDCoordinate topMargin = 0,
|
||||
KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0,
|
||||
bool showIndicators = true, bool colorBackground = true, KDColor backgroundColor = Palette::WallScreen);
|
||||
bool showIndicators = true, bool colorBackground = true, KDColor backgroundColor = Palette::WallScreen,
|
||||
KDCoordinate indicatorThickness = 10, KDColor indicatorColor = Palette::GreyMiddle,
|
||||
KDColor backgroundIndicatorColor = Palette::GreyWhite, KDCoordinate indicatorMargin = 14);
|
||||
|
||||
virtual void scrollToCell(int i, int j);
|
||||
TableViewCell * cellAtLocation(int i, int j);
|
||||
|
||||
@@ -4,20 +4,20 @@ extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
|
||||
constexpr KDCoordinate ScrollView::k_indicatorThickness;
|
||||
|
||||
ScrollView::ScrollView(View * contentView, KDCoordinate topMargin, KDCoordinate rightMargin,
|
||||
KDCoordinate bottomMargin, KDCoordinate leftMargin, bool showIndicators, bool colorBackground,
|
||||
KDColor backgroundColor) :
|
||||
KDColor backgroundColor, KDCoordinate indicatorThickness, KDColor indicatorColor,
|
||||
KDColor backgroundIndicatorColor, KDCoordinate indicatorMargin) :
|
||||
View(),
|
||||
m_topMargin(topMargin),
|
||||
m_offset(KDPointZero),
|
||||
m_contentView(contentView),
|
||||
m_verticalScrollIndicator(ScrollViewIndicator(ScrollViewIndicator::Direction::Vertical)),
|
||||
m_horizontalScrollIndicator(ScrollViewIndicator(ScrollViewIndicator::Direction::Horizontal)),
|
||||
m_verticalScrollIndicator(ScrollViewIndicator(ScrollViewIndicator::Direction::Vertical, indicatorColor, backgroundIndicatorColor, indicatorMargin)),
|
||||
m_horizontalScrollIndicator(ScrollViewIndicator(ScrollViewIndicator::Direction::Horizontal, indicatorColor, backgroundIndicatorColor, indicatorMargin)),
|
||||
m_rightMargin(rightMargin),
|
||||
m_bottomMargin(bottomMargin),
|
||||
m_leftMargin(leftMargin),
|
||||
m_indicatorThickness(indicatorThickness),
|
||||
m_showIndicators(showIndicators),
|
||||
m_colorBackground(colorBackground),
|
||||
m_backgroundColor(backgroundColor)
|
||||
@@ -81,27 +81,27 @@ void ScrollView::layoutSubviews() {
|
||||
* bottom corner. Otherwise, the only indicator uses all the height/width. */
|
||||
if (hasHorizontalIndicator() && hasVerticalIndicator()) {
|
||||
KDRect verticalIndicatorFrame = KDRect(
|
||||
m_frame.width() - k_indicatorThickness, 0,
|
||||
k_indicatorThickness, m_frame.height() - k_indicatorThickness
|
||||
m_frame.width() - m_indicatorThickness, 0,
|
||||
m_indicatorThickness, m_frame.height() - m_indicatorThickness
|
||||
);
|
||||
m_verticalScrollIndicator.setFrame(verticalIndicatorFrame);
|
||||
KDRect horizontalIndicatorFrame = KDRect(
|
||||
0, m_frame.height() - k_indicatorThickness,
|
||||
m_frame.width() - k_indicatorThickness, k_indicatorThickness
|
||||
0, m_frame.height() - m_indicatorThickness,
|
||||
m_frame.width() - m_indicatorThickness, m_indicatorThickness
|
||||
);
|
||||
m_horizontalScrollIndicator.setFrame(horizontalIndicatorFrame);
|
||||
} else {
|
||||
if (hasVerticalIndicator()) {
|
||||
KDRect verticalIndicatorFrame = KDRect(
|
||||
m_frame.width() - k_indicatorThickness, 0,
|
||||
k_indicatorThickness, m_frame.height()
|
||||
m_frame.width() - m_indicatorThickness, 0,
|
||||
m_indicatorThickness, m_frame.height()
|
||||
);
|
||||
m_verticalScrollIndicator.setFrame(verticalIndicatorFrame);
|
||||
}
|
||||
if (hasHorizontalIndicator()) {
|
||||
KDRect horizontalIndicatorFrame = KDRect(
|
||||
0, m_frame.height() - k_indicatorThickness,
|
||||
m_frame.width(), k_indicatorThickness
|
||||
0, m_frame.height() - m_indicatorThickness,
|
||||
m_frame.width(), m_indicatorThickness
|
||||
);
|
||||
m_horizontalScrollIndicator.setFrame(horizontalIndicatorFrame);
|
||||
}
|
||||
|
||||
@@ -3,33 +3,40 @@ extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
|
||||
constexpr KDColor k_backgroundColor = KDColorBlack;
|
||||
constexpr KDColor k_indicatorColor = KDColorRed;
|
||||
|
||||
ScrollViewIndicator::ScrollViewIndicator(ScrollViewIndicator::Direction direction) :
|
||||
ScrollViewIndicator::ScrollViewIndicator(ScrollViewIndicator::Direction direction, KDColor indicatorColor, KDColor backgroundColor, KDCoordinate margin) :
|
||||
View(),
|
||||
m_direction(direction),
|
||||
m_start(0),
|
||||
m_end(0)
|
||||
m_end(0),
|
||||
m_indicatorColor(indicatorColor),
|
||||
m_backgroundColor(backgroundColor),
|
||||
m_margin(margin)
|
||||
{
|
||||
}
|
||||
|
||||
void ScrollViewIndicator::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(bounds(), k_backgroundColor);
|
||||
KDRect indicatorFrame = KDRectZero;
|
||||
KDRect frame = KDRectZero;
|
||||
if (m_direction == Direction::Horizontal) {
|
||||
indicatorFrame = KDRect(
|
||||
m_start*m_frame.width(), 0,
|
||||
(m_end-m_start)*m_frame.width(), m_frame.height()
|
||||
);
|
||||
frame = KDRect(m_margin, (m_frame.height() - k_indicatorThickness)/2,
|
||||
m_frame.width() - 2*m_margin, k_indicatorThickness);
|
||||
} else {
|
||||
assert(m_direction == Direction::Vertical);
|
||||
indicatorFrame = KDRect(
|
||||
0, m_start*m_frame.height(),
|
||||
m_frame.width(), (m_end-m_start)*m_frame.height()
|
||||
);
|
||||
frame = KDRect((m_frame.width() - k_indicatorThickness)/2, m_margin,
|
||||
k_indicatorThickness, m_frame.height() - 2*m_margin);
|
||||
}
|
||||
ctx->fillRect(indicatorFrame, k_indicatorColor);
|
||||
ctx->fillRect(frame, m_backgroundColor);
|
||||
KDRect indicatorFrame = KDRectZero;
|
||||
if (m_direction == Direction::Horizontal) {
|
||||
KDCoordinate indicatorWidth = m_frame.width() - 2*m_margin;
|
||||
indicatorFrame = KDRect(m_margin+m_start*indicatorWidth, (m_frame.height() - k_indicatorThickness)/2,
|
||||
(m_end-m_start)*indicatorWidth, k_indicatorThickness);
|
||||
} else {
|
||||
assert(m_direction == Direction::Vertical);
|
||||
KDCoordinate indicatorHeight = m_frame.height() - 2*m_margin;
|
||||
indicatorFrame = KDRect((m_frame.width() - k_indicatorThickness)/2, m_margin+m_start*indicatorHeight,
|
||||
k_indicatorThickness, (m_end-m_start)*indicatorHeight);
|
||||
}
|
||||
ctx->fillRect(indicatorFrame, m_indicatorColor);
|
||||
}
|
||||
|
||||
float ScrollViewIndicator::start() const {
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
SelectableTableView::SelectableTableView(Responder * parentResponder, TableViewDataSource * dataSource,
|
||||
KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin,
|
||||
SelectableTableViewDelegate * delegate, bool showIndicators, bool colorBackground,
|
||||
KDColor backgroundColor) :
|
||||
TableView(dataSource, topMargin, rightMargin, bottomMargin, leftMargin, showIndicators, colorBackground, backgroundColor),
|
||||
SelectableTableViewDelegate * delegate, bool showIndicators, bool colorBackground, KDColor backgroundColor,
|
||||
KDCoordinate indicatorThickness, KDColor indicatorColor, KDColor backgroundIndicatorColor, KDCoordinate indicatorMargin) :
|
||||
TableView(dataSource, topMargin, rightMargin, bottomMargin, leftMargin, showIndicators, colorBackground, backgroundColor,
|
||||
indicatorThickness, indicatorColor, backgroundIndicatorColor, indicatorMargin),
|
||||
Responder(parentResponder),
|
||||
m_delegate(delegate),
|
||||
m_selectedCellX(0),
|
||||
|
||||
@@ -9,9 +9,10 @@ extern "C" {
|
||||
|
||||
TableView::TableView(TableViewDataSource * dataSource, KDCoordinate topMargin, KDCoordinate rightMargin,
|
||||
KDCoordinate bottomMargin, KDCoordinate leftMargin, bool showIndicators, bool colorBackground,
|
||||
KDColor backgroundColor) :
|
||||
KDColor backgroundColor, KDCoordinate indicatorThickness, KDColor indicatorColor,
|
||||
KDColor backgroundIndicatorColor, KDCoordinate indicatorMargin) :
|
||||
ScrollView(&m_contentView, topMargin, rightMargin, bottomMargin, leftMargin, showIndicators, colorBackground,
|
||||
backgroundColor),
|
||||
backgroundColor, indicatorThickness, indicatorColor, backgroundIndicatorColor, indicatorMargin),
|
||||
m_contentView(TableView::ContentView(this, dataSource))
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user