[apps] Add a code app

Change-Id: Icc72c378a6434b5d3b0af74f23e31ea7514882b8
This commit is contained in:
Romain Goyet
2017-08-03 23:28:56 +02:00
parent 20e1554a13
commit 19cf3a4958
8 changed files with 114 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ include apps/sequence/Makefile
include apps/settings/Makefile
include apps/shared/Makefile
include apps/statistics/Makefile
include apps/code/Makefile
#include apps/picview/Makefile
app_objs += $(addprefix apps/,\

View File

@@ -58,6 +58,7 @@ App::Snapshot * AppsContainer::appSnapshotAtIndex(int index) {
&m_statisticsSnapshot,
&m_probabilitySnapshot,
&m_regressionSnapshot,
&m_codeSnapshot
};
assert(sizeof(snapshots)/sizeof(snapshots[0]) == k_numberOfCommonApps);
assert(index >= 0 && index < k_numberOfCommonApps);

View File

@@ -11,6 +11,7 @@
#include "statistics/app.h"
#include "on_boarding/app.h"
#include "hardware_test/app.h"
#include "code/app.h"
#include "on_boarding/update_controller.h"
#include "apps_window.h"
#include "empty_battery_window.h"
@@ -55,7 +56,7 @@ private:
int numberOfContainerTimers() override;
Timer * containerTimerAtIndex(int i) override;
bool processEvent(Ion::Events::Event event);
static constexpr int k_numberOfCommonApps = 8;
static constexpr int k_numberOfCommonApps = 9;
static constexpr int k_totalNumberOfApps = 2+k_numberOfCommonApps;
AppsWindow m_window;
EmptyBatteryWindow m_emptyBatteryWindow;
@@ -82,6 +83,7 @@ private:
Statistics::App::Snapshot m_statisticsSnapshot;
Probability::App::Snapshot m_probabilitySnapshot;
Regression::App::Snapshot m_regressionSnapshot;
Code::App::Snapshot m_codeSnapshot;
};
#endif

4
apps/code/Makefile Normal file
View File

@@ -0,0 +1,4 @@
app_objs += $(addprefix apps/code/,\
app.o\
editor_controller.o\
)

30
apps/code/app.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include "app.h"
#include "../apps_container.h"
#include <assert.h>
namespace Code {
I18n::Message App::Descriptor::name() {
return I18n::Message::Matrices;
}
I18n::Message App::Descriptor::upperName() {
return I18n::Message::Matrices;
}
App * App::Snapshot::unpack(Container * container) {
return new App(container, this);
}
App::Descriptor * App::Snapshot::descriptor() {
static Descriptor descriptor;
return &descriptor;
}
App::App(Container * container, Snapshot * snapshot) :
::App(container, snapshot, &m_editorController),
m_editorController(this)
{
}
}

33
apps/code/app.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef CODE_APP_H
#define CODE_APP_H
#include <escher.h>
#include "editor_controller.h"
namespace Code {
class App : public ::App {
public:
class Descriptor : public ::App::Descriptor {
public:
I18n::Message name() override;
I18n::Message upperName() override;
//const Image * icon() override;
};
class Snapshot : public ::App::Snapshot {
public:
App * unpack(Container * container) override;
Descriptor * descriptor() override;
};
//int numberOfTimers() override;
//Timer * timerAtIndex(int i) override;
//bool processEvent(Ion::Events::Event) override;
//void didBecomeActive(Window * window) override;
private:
App(Container * container, Snapshot * snapshot);
EditorController m_editorController;
};
}
#endif

View File

@@ -0,0 +1,25 @@
#include "editor_controller.h"
EditorController::EditorController(Responder * parentResponder) :
ViewController(parentResponder),
m_view(this, buffer, 256)
{
memcpy(buffer, "Hello\nWorld\nOhOhOh\nThis\nLooks\nlike\nso\nmuch\nfun\nI\nwonder\nhow\nmany very very very very very very very long\nlines\nI\ncan\ndisplay", 256);
}
void EditorController::didBecomeFirstResponder() {
app()->setFirstResponder(&m_view);
}
View * EditorController::view() {
return &m_view;
}
/*
const char * PicViewController::title() {
return "PicView";
}
*/

View File

@@ -0,0 +1,17 @@
#ifndef CODE_EDITOR_CONTROLLER_H
#define CODE_EDITOR_CONTROLLER_H
#include <escher.h>
class EditorController : public ViewController {
public:
EditorController(Responder * parentResponder);
View * view() override;
void didBecomeFirstResponder() override;
private:
char buffer[256];
TextArea m_view;
};
#endif