diff --git a/apps/graph/Makefile b/apps/graph/Makefile index f9ee40d90..8cb695834 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -11,3 +11,5 @@ app_objs += $(addprefix apps/graph/,\ list/list_controller.o\ list/parameter_controller.o\ ) + +inline_images += apps/graph/graph_icon.png diff --git a/apps/graph/graph_app.cpp b/apps/graph/graph_app.cpp index b67ce0d92..5f913ddce 100644 --- a/apps/graph/graph_app.cpp +++ b/apps/graph/graph_app.cpp @@ -1,7 +1,8 @@ #include "graph_app.h" +#include "graph_icon.h" GraphApp::GraphApp() : - App(), + App("Graph", ImageStore::GraphIcon), m_functionStore(Graph::FunctionStore()), m_listController(ListController(nullptr, &m_functionStore)), m_listStackViewController(StackViewController(&m_tabViewController, &m_listController)), diff --git a/apps/graph/graph_icon.png b/apps/graph/graph_icon.png new file mode 100644 index 000000000..3818c7bf1 Binary files /dev/null and b/apps/graph/graph_icon.png differ diff --git a/apps/home/app_cell.cpp b/apps/home/app_cell.cpp index 6add97c67..76342fec5 100644 --- a/apps/home/app_cell.cpp +++ b/apps/home/app_cell.cpp @@ -4,26 +4,47 @@ namespace Home { AppCell::AppCell() : - ChildlessView(), + View(), + m_visible(true), m_active(false) { } +int AppCell::numberOfSubviews() const { + return m_visible ? 2 : 0; +} + +View * AppCell::subviewAtIndex(int index) { + View * views[] = {&m_iconView, &m_nameView}; + return views[index]; +} + +void AppCell::layoutSubviews() { + m_iconView.setFrame(KDRect(0,0,k_iconSize,k_iconSize)); + if (bounds().height() > k_iconSize) { + m_nameView.setFrame(KDRect(0, k_iconSize, bounds().width(), bounds().height()-k_iconSize)); + } +} + +void AppCell::setApp(::App * app) { + m_iconView.setImage(app->icon()); + m_nameView.setText(app->name()); +} + +void AppCell::setVisible(bool visible) { + if (m_visible != visible) { + m_visible = visible; + markRectAsDirty(bounds()); + } +} + void AppCell::setActive(bool active) { if (m_active != active) { m_active = active; + m_nameView.setBackgroundColor(m_active ? KDColorRed : KDColorWhite); + markRectAsDirty(bounds()); } } -void AppCell::drawRect(KDContext * ctx, KDRect rect) const { - KDColor c = m_active ? KDColorRed : KDColorBlack; - ctx->fillRect(KDRect(0,0, 20, 20), c); - /* - KDColor * pixels = (KDColor *)apps_picview_image_raw; - assert(apps_picview_image_raw_len == bounds().width() * bounds().height() * sizeof(KDColor)); - ctx->fillRectWithPixels(bounds(), pixels, nullptr); - */ -} - } diff --git a/apps/home/app_cell.h b/apps/home/app_cell.h index 854a75123..4d27274f3 100644 --- a/apps/home/app_cell.h +++ b/apps/home/app_cell.h @@ -5,12 +5,22 @@ namespace Home { -class AppCell : public ChildlessView { +class AppCell : public View { public: AppCell(); - void drawRect(KDContext * ctx, KDRect rect) const override; + + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + + void setVisible(bool visible); void setActive(bool active); + void setApp(::App * app); private: + static constexpr KDCoordinate k_iconSize = 32; + ImageView m_iconView; + TextView m_nameView; + bool m_visible; bool m_active; }; diff --git a/apps/home/controller.cpp b/apps/home/controller.cpp index ebe303840..672f5d209 100644 --- a/apps/home/controller.cpp +++ b/apps/home/controller.cpp @@ -77,6 +77,18 @@ int Controller::reusableCellCount() { return k_maxNumberOfCells; } +void Controller::willDisplayCellAtLocation(View * cell, int i, int j) { + AppCell * appCell = (AppCell *)cell; + int appIndex = (j*k_numberOfColumns+i)+1; + if (appIndex >= m_container->numberOfApps()) { + appCell->setVisible(false); + } else { + appCell->setVisible(true); + ::App * app = m_container->appAtIndex((j*k_numberOfColumns+i)+1); + appCell->setApp(app); + } +} + int Controller::numberOfIcons() { assert(m_container->numberOfApps() > 0); return m_container->numberOfApps() - 1; diff --git a/apps/home/controller.h b/apps/home/controller.h index ff93fbdb9..20670318c 100644 --- a/apps/home/controller.h +++ b/apps/home/controller.h @@ -23,6 +23,7 @@ public: virtual KDCoordinate cellWidth() override; virtual View * reusableCell(int index) override; virtual int reusableCellCount() override; + void willDisplayCellAtLocation(View * cell, int i, int j) override; private: int numberOfIcons(); void setActiveIndex(int index); diff --git a/apps/probability/Makefile b/apps/probability/Makefile index b76e2cc01..23c8b5b93 100644 --- a/apps/probability/Makefile +++ b/apps/probability/Makefile @@ -3,3 +3,5 @@ app_objs += $(addprefix apps/probability/,\ law/law_controller.o\ parameters/parameters_controller.o\ ) + +inline_images += apps/probability/probability_icon.png diff --git a/apps/probability/app.cpp b/apps/probability/app.cpp index 59adde71c..23de2c9de 100644 --- a/apps/probability/app.cpp +++ b/apps/probability/app.cpp @@ -1,7 +1,8 @@ #include "app.h" +#include "probability_icon.h" Probability::App::App() : - ::App(), + ::App("Probability", ImageStore::ProbabilityIcon), m_lawController(LawController(nullptr)), m_parametersController(ParametersController(nullptr)), m_stackViewController(this, &m_lawController, true) diff --git a/apps/probability/probability_icon.png b/apps/probability/probability_icon.png new file mode 100644 index 000000000..e8dbe4dc8 Binary files /dev/null and b/apps/probability/probability_icon.png differ