[apps/home] Do not redraw the white background at each scroll

Change-Id: Ifc7c30862ca9034dbdb22600e399792061f6ee4d
This commit is contained in:
Émilie Feral
2017-04-04 18:08:39 +02:00
parent 6c2dabe7cc
commit e2d46081da
2 changed files with 47 additions and 10 deletions

View File

@@ -6,37 +6,63 @@ extern "C" {
namespace Home { namespace Home {
Controller::ContentView::ContentView(Controller * controller) :
m_selectableTableView(SelectableTableView(controller, controller, 0, 0, 0, k_sideMargin, 0, k_sideMargin, controller, true, false,
KDColorBlack, k_indicatorThickness, Palette::GreyDark, Palette::GreyMiddle, k_indicatorMargin))
{
}
SelectableTableView * Controller::ContentView::selectableTableView() {
return &m_selectableTableView;
}
void Controller::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorWhite);
}
int Controller::ContentView::numberOfSubviews() const {
return 1;
}
View * Controller::ContentView::subviewAtIndex(int index) {
assert(index == 0);
return &m_selectableTableView;
}
void Controller::ContentView::layoutSubviews() {
m_selectableTableView.setFrame(bounds());
}
Controller::Controller(Responder * parentResponder, ::AppsContainer * container) : Controller::Controller(Responder * parentResponder, ::AppsContainer * container) :
ViewController(parentResponder), ViewController(parentResponder),
m_container(container), m_container(container),
m_selectableTableView(SelectableTableView(this, this, 0, 0, 0, k_sideMargin, 0, k_sideMargin, this, true, true, m_view(ContentView(this))
KDColorWhite, k_indicatorThickness, Palette::GreyDark, Palette::GreyMiddle, k_indicatorMargin))
{ {
} }
bool Controller::handleEvent(Ion::Events::Event event) { bool Controller::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK) { if (event == Ion::Events::OK) {
m_container->switchTo(m_container->appAtIndex(m_selectableTableView.selectedRow()*k_numberOfColumns+m_selectableTableView.selectedColumn()+1)); m_container->switchTo(m_container->appAtIndex(m_view.selectableTableView()->selectedRow()*k_numberOfColumns+m_view.selectableTableView()->selectedColumn()+1));
return true; return true;
} }
return false; return false;
} }
void Controller::didBecomeFirstResponder() { void Controller::didBecomeFirstResponder() {
if (m_selectableTableView.selectedRow() == -1) { if (m_view.selectableTableView()->selectedRow() == -1) {
m_selectableTableView.selectCellAtLocation(0, 0); m_view.selectableTableView()->selectCellAtLocation(0, 0);
} else { } else {
m_selectableTableView.selectCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); m_view.selectableTableView()->selectCellAtLocation(m_view.selectableTableView()->selectedColumn(), m_view.selectableTableView()->selectedRow());
} }
app()->setFirstResponder(&m_selectableTableView); app()->setFirstResponder(m_view.selectableTableView());
} }
void Controller::viewWillAppear() { void Controller::viewWillAppear() {
m_selectableTableView.reloadData(); m_view.selectableTableView()->reloadData();
} }
View * Controller::view() { View * Controller::view() {
return &m_selectableTableView; return &m_view;
} }
int Controller::numberOfRows() { int Controller::numberOfRows() {

View File

@@ -28,8 +28,18 @@ public:
void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) override; void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) override;
private: private:
int numberOfIcons(); int numberOfIcons();
class ContentView : public View {
public:
ContentView(Controller * controller);
SelectableTableView * selectableTableView();
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
SelectableTableView m_selectableTableView;
};
AppsContainer * m_container; AppsContainer * m_container;
SelectableTableView m_selectableTableView;
static constexpr KDCoordinate k_sideMargin = 4; static constexpr KDCoordinate k_sideMargin = 4;
static constexpr KDCoordinate k_indicatorThickness = 28; static constexpr KDCoordinate k_indicatorThickness = 28;
static constexpr KDCoordinate k_indicatorMargin = 116; static constexpr KDCoordinate k_indicatorMargin = 116;
@@ -38,6 +48,7 @@ private:
static constexpr int k_maxNumberOfCells = 16; static constexpr int k_maxNumberOfCells = 16;
static constexpr int k_cellHeight = 98; static constexpr int k_cellHeight = 98;
static constexpr int k_cellWidth = 104; static constexpr int k_cellWidth = 104;
ContentView m_view;
AppCell m_cells[k_maxNumberOfCells]; AppCell m_cells[k_maxNumberOfCells];
}; };