[escher] [apps] Add a title bar in all apps

Change-Id: If545e9b6cd96aa1189d83120f047ac7746a5a9d6
This commit is contained in:
Émilie Feral
2017-01-23 10:56:32 +01:00
parent 237f214fae
commit a4df89d2f5
10 changed files with 92 additions and 13 deletions

View File

@@ -8,6 +8,7 @@ include apps/statistics/Makefile
app_objs += $(addprefix apps/,\
apps_container.o\
apps_window.o\
banner_view.o\
constant.o\
cursor_view.o\

View File

@@ -5,6 +5,7 @@ extern "C" {
AppsContainer::AppsContainer() :
Container(),
m_window(AppsWindow()),
m_homeApp(this),
m_graphApp(this, &m_globalContext),
m_probabilityApp(this),
@@ -53,3 +54,12 @@ bool AppsContainer::handleEvent(Ion::Events::Event event) {
}
return false;
}
void AppsContainer::switchTo(App * app) {
Container::switchTo(app);
/*do something with title bar*/
}
Window * AppsContainer::window() {
return &m_window;
}

View File

@@ -7,6 +7,7 @@
#include "calculation/app.h"
#include "regression/app.h"
#include "statistics/app.h"
#include "apps_window.h"
#include "toolbox_controller.h"
#include "variable_box_controller.h"
@@ -25,8 +26,11 @@ public:
ToolboxController * toolboxController();
VariableBoxController * variableBoxController();
bool handleEvent(Ion::Events::Event event) override;
void switchTo(App * app) override;
private:
Window * window() override;
static constexpr int k_numberOfApps = 6;
AppsWindow m_window;
Home::App m_homeApp;
Graph::App m_graphApp;
Probability::App m_probabilityApp;

43
apps/apps_window.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include "apps_window.h"
extern "C" {
#include <assert.h>
}
/* Title Bar View */
void AppsWindow::TitleBarView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorBlack);
}
/* Window */
AppsWindow::AppsWindow() :
Window(),
m_titleBarView(TitleBarView())
{
}
int AppsWindow::numberOfSubviews() const {
return (m_contentView == nullptr ? 1 : 2);
}
View * AppsWindow::subviewAtIndex(int index) {
if (index == 0) {
return &m_titleBarView;
}
assert(m_contentView != nullptr && index == 1);
return m_contentView;
}
void AppsWindow::layoutSubviews() {
m_titleBarView.setFrame(KDRect(0, 0, bounds().width(), k_titleBarHeight));
if (m_contentView != nullptr) {
m_contentView->setFrame(KDRect(0, k_titleBarHeight, bounds().width(), bounds().height()-k_titleBarHeight));
}
}
#if ESCHER_VIEW_LOGGING
const char * AppsWindow::className() const {
return "Window";
}
#endif

20
apps/apps_window.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef APPS_WINDOW_H
#define APPS_WINDOW_H
#include <escher.h>
class AppsWindow : public Window {
public:
AppsWindow();
private:
class TitleBarView : public View {
void drawRect(KDContext * ctx, KDRect rect) const override;
};
constexpr static KDCoordinate k_titleBarHeight = 18;
int numberOfSubviews() const override;
void layoutSubviews() override;
View * subviewAtIndex(int index) override;
TitleBarView m_titleBarView;
};
#endif

View File

@@ -20,11 +20,12 @@ public:
void run();
App * activeApp();
virtual bool handleEvent(Ion::Events::Event event);
void switchTo(App * app);
virtual void switchTo(App * app);
protected:
virtual Window * window() = 0;
private:
void step();
App * m_activeApp;
Window m_window;
};
#endif

View File

@@ -12,12 +12,12 @@ protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;
#endif
int numberOfSubviews() const override;
void layoutSubviews() override;
virtual int numberOfSubviews() const override;
virtual void layoutSubviews() override;
virtual View * subviewAtIndex(int index) override;
View * m_contentView;
private:
const Window * window() const override;
View * subviewAtIndex(int index) override;
View * m_contentView;
};
#endif

View File

@@ -24,7 +24,6 @@ void App::setWindow(Window * window) {
assert(m_modalViewController.app() == this);
window->setContentView(view);
view->setFrame(window->bounds());
window->redraw();
}

View File

@@ -11,7 +11,7 @@ Container::Container() :
void Container::switchTo(App * app) {
m_activeApp = app;
m_activeApp->setWindow(&m_window);
m_activeApp->setWindow(window());
}
App * Container::activeApp() {
@@ -23,8 +23,8 @@ bool Container::handleEvent(Ion::Events::Event event) {
}
void Container::run() {
m_window.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height));
m_window.redraw();
window()->setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height));
window()->redraw();
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop_arg([](void * ctx){ ((Container *)ctx)->step(); }, this, 0, 1);
@@ -44,5 +44,5 @@ void Container::step() {
return;
}
m_activeApp->processEvent(event);
m_window.redraw();
window()->redraw();
}

View File

@@ -16,8 +16,9 @@ void Window::setContentView(View * contentView) {
if (m_contentView != contentView) {
m_contentView = contentView;
markRectAsDirty(bounds());
layoutSubviews();
}
};
}
const Window * Window::window() const {
return this;
@@ -34,7 +35,7 @@ View * Window::subviewAtIndex(int index) {
void Window::layoutSubviews() {
if (m_contentView != nullptr) {
m_contentView->setFrame(this->bounds());
m_contentView->setFrame(bounds());
}
}