mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[escher] Rework of timers and bigger text in toolboxes
This commit is contained in:
@@ -21,6 +21,7 @@ endif
|
||||
|
||||
escher_src += $(addprefix escher/src/,\
|
||||
alternate_empty_view_controller.cpp \
|
||||
animation_timer.cpp \
|
||||
app.cpp \
|
||||
background_view.cpp \
|
||||
bank_view_controller.cpp \
|
||||
@@ -84,6 +85,7 @@ escher_src += $(addprefix escher/src/,\
|
||||
selectable_table_view.cpp \
|
||||
simple_list_view_data_source.cpp \
|
||||
simple_table_view_data_source.cpp \
|
||||
slideable_message_text_view.cpp \
|
||||
solid_color_view.cpp \
|
||||
stack_view.cpp \
|
||||
stack_view_controller.cpp \
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <escher/alternate_empty_view_controller.h>
|
||||
#include <escher/alternate_empty_view_delegate.h>
|
||||
#include <escher/animated.h>
|
||||
#include <escher/animation_timer.h>
|
||||
#include <escher/background_view.h>
|
||||
#include <escher/bank_view_controller.h>
|
||||
#include <escher/buffer_text_view.h>
|
||||
@@ -66,6 +68,7 @@
|
||||
#include <escher/selectable_table_view_delegate.h>
|
||||
#include <escher/simple_table_view_data_source.h>
|
||||
#include <escher/simple_list_view_data_source.h>
|
||||
#include <escher/slideable_message_text_view.h>
|
||||
#include <escher/solid_color_view.h>
|
||||
#include <escher/stack_view_controller.h>
|
||||
#include <escher/switch_view.h>
|
||||
|
||||
11
escher/include/escher/animated.h
Normal file
11
escher/include/escher/animated.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef APPS_ANIMATED_H
|
||||
#define APPS_ANIMATED_H
|
||||
|
||||
class Animated {
|
||||
public:
|
||||
virtual void willStartAnimation() {};
|
||||
virtual void didStopAnimation() {};
|
||||
virtual void animate() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
25
escher/include/escher/animation_timer.h
Normal file
25
escher/include/escher/animation_timer.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef APPS_ANIMATION_TIMER_H
|
||||
#define APPS_ANIMATION_TIMER_H
|
||||
|
||||
#include <escher/timer.h>
|
||||
#include <escher/animated.h>
|
||||
#include <assert.h>
|
||||
|
||||
class AnimationTimer : public Timer {
|
||||
public:
|
||||
AnimationTimer():
|
||||
Timer(1),
|
||||
m_animated(nullptr)
|
||||
{}
|
||||
void setAnimated(Animated * animated);
|
||||
void removeAnimated(Animated * animated=nullptr);
|
||||
private:
|
||||
bool fire() override {
|
||||
assert(m_animated);
|
||||
m_animated->animate();
|
||||
return true;
|
||||
}
|
||||
Animated * m_animated;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -69,8 +69,6 @@ public:
|
||||
virtual void didBecomeActive(Window * window);
|
||||
virtual void willBecomeInactive();
|
||||
View * modalView();
|
||||
virtual int numberOfTimers() { return 0; }
|
||||
virtual Timer * timerAtIndex(int i) { assert(false); return nullptr; }
|
||||
virtual Poincare::Context * localContext() { return nullptr; }
|
||||
protected:
|
||||
App(Snapshot * snapshot, ViewController * rootViewController, I18n::Message warningMessage = (I18n::Message)0) :
|
||||
|
||||
@@ -36,10 +36,6 @@ protected:
|
||||
static App * s_activeApp;
|
||||
private:
|
||||
void step();
|
||||
int numberOfTimers() override;
|
||||
Timer * timerAtIndex(int i) override;
|
||||
virtual int numberOfContainerTimers();
|
||||
virtual Timer * containerTimerAtIndex(int i);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
#define ESCHER_MESSAGE_TABLE_CELL_H
|
||||
|
||||
#include <escher/message_text_view.h>
|
||||
#include <escher/slideable_message_text_view.h>
|
||||
#include <escher/i18n.h>
|
||||
#include <escher/table_cell.h>
|
||||
|
||||
template<class T=MessageTextView>
|
||||
class MessageTableCell : public TableCell {
|
||||
public:
|
||||
MessageTableCell(I18n::Message label = (I18n::Message)0, const KDFont * font = KDFont::SmallFont, Layout layout = Layout::HorizontalLeftOverlap);
|
||||
@@ -17,7 +19,7 @@ public:
|
||||
protected:
|
||||
KDColor backgroundColor() const override { return m_backgroundColor; }
|
||||
private:
|
||||
MessageTextView m_messageTextView;
|
||||
T m_messageTextView;
|
||||
KDColor m_backgroundColor;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <escher/message_table_cell.h>
|
||||
#include <escher/buffer_text_view.h>
|
||||
|
||||
class MessageTableCellWithBuffer : public MessageTableCell {
|
||||
class MessageTableCellWithBuffer : public MessageTableCell<> {
|
||||
public:
|
||||
MessageTableCellWithBuffer(I18n::Message message = (I18n::Message)0, const KDFont * font = KDFont::SmallFont, const KDFont * accessoryFont = KDFont::LargeFont, KDColor accessoryTextColor = Palette::PrimaryText);
|
||||
View * accessoryView() const override;
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include <escher/message_table_cell.h>
|
||||
#include <escher/chevron_view.h>
|
||||
|
||||
class MessageTableCellWithChevron : public MessageTableCell {
|
||||
template <class T=MessageTextView>
|
||||
class MessageTableCellWithChevron : public MessageTableCell<T> {
|
||||
public:
|
||||
MessageTableCellWithChevron(I18n::Message message = (I18n::Message)0, const KDFont * font = KDFont::SmallFont);
|
||||
View * accessoryView() const override;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <escher/message_table_cell_with_chevron.h>
|
||||
#include <escher/buffer_text_view.h>
|
||||
|
||||
class MessageTableCellWithChevronAndBuffer : public MessageTableCellWithChevron {
|
||||
class MessageTableCellWithChevronAndBuffer : public MessageTableCellWithChevron<> {
|
||||
public:
|
||||
MessageTableCellWithChevronAndBuffer(const KDFont * labelFont = KDFont::SmallFont, const KDFont * subAccessoryFont = KDFont::SmallFont);
|
||||
View * subAccessoryView() const override;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <escher/message_table_cell_with_chevron.h>
|
||||
#include <escher/expression_view.h>
|
||||
|
||||
class MessageTableCellWithChevronAndExpression : public MessageTableCellWithChevron {
|
||||
class MessageTableCellWithChevronAndExpression : public MessageTableCellWithChevron<> {
|
||||
public:
|
||||
MessageTableCellWithChevronAndExpression(I18n::Message message = (I18n::Message)0, const KDFont * font = KDFont::SmallFont);
|
||||
View * subAccessoryView() const override;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <escher/message_table_cell_with_chevron.h>
|
||||
|
||||
class MessageTableCellWithChevronAndMessage : public MessageTableCellWithChevron {
|
||||
class MessageTableCellWithChevronAndMessage : public MessageTableCellWithChevron<> {
|
||||
public:
|
||||
MessageTableCellWithChevronAndMessage(const KDFont * labelFont = KDFont::SmallFont, const KDFont * contentFont = KDFont::SmallFont);
|
||||
View * subAccessoryView() const override;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <escher/responder.h>
|
||||
#include <poincare/print_float.h>
|
||||
|
||||
class MessageTableCellWithEditableText : public Responder, public MessageTableCell {
|
||||
class MessageTableCellWithEditableText : public Responder, public MessageTableCell<> {
|
||||
public:
|
||||
MessageTableCellWithEditableText(Responder * parentResponder = nullptr, InputEventHandlerDelegate * inputEventHandlerDelegate = nullptr, TextFieldDelegate * textFieldDelegate = nullptr, I18n::Message message = (I18n::Message)0);
|
||||
View * accessoryView() const override;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <escher/message_table_cell.h>
|
||||
#include <escher/expression_view.h>
|
||||
|
||||
class MessageTableCellWithExpression : public MessageTableCell {
|
||||
class MessageTableCellWithExpression : public MessageTableCell<> {
|
||||
public:
|
||||
MessageTableCellWithExpression(I18n::Message message = (I18n::Message)0, const KDFont * font = KDFont::LargeFont);
|
||||
View * accessoryView() const override;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <escher/message_table_cell.h>
|
||||
#include <escher/gauge_view.h>
|
||||
|
||||
class MessageTableCellWithGauge : public MessageTableCell {
|
||||
class MessageTableCellWithGauge : public MessageTableCell<> {
|
||||
public:
|
||||
MessageTableCellWithGauge(I18n::Message message = (I18n::Message)0, const KDFont * font = KDFont::SmallFont);
|
||||
View * accessoryView() const override;
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
|
||||
#include <escher/message_table_cell.h>
|
||||
|
||||
class MessageTableCellWithMessage : public MessageTableCell {
|
||||
template <class T=MessageTextView>
|
||||
class MessageTableCellWithMessage : public MessageTableCell<T> {
|
||||
public:
|
||||
MessageTableCellWithMessage(I18n::Message message = (I18n::Message)0, Layout layout = Layout::Vertical);
|
||||
MessageTableCellWithMessage(I18n::Message message = (I18n::Message)0, TableCell::Layout layout = TableCell::Layout::Vertical);
|
||||
View * accessoryView() const override;
|
||||
void setHighlighted(bool highlight) override;
|
||||
void setAccessoryMessage(I18n::Message textBody);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <escher/message_table_cell.h>
|
||||
#include <escher/switch_view.h>
|
||||
|
||||
class MessageTableCellWithSwitch : public MessageTableCell {
|
||||
class MessageTableCellWithSwitch : public MessageTableCell<> {
|
||||
public:
|
||||
MessageTableCellWithSwitch(I18n::Message message = (I18n::Message)0, const KDFont * font = KDFont::SmallFont);
|
||||
View * accessoryView() const override;
|
||||
|
||||
@@ -9,13 +9,14 @@ public:
|
||||
RunLoop();
|
||||
void run();
|
||||
void runWhile(bool (*callback)(void * ctx), void * ctx);
|
||||
void addTimer(Timer * timer);
|
||||
void removeTimer(Timer * timer);
|
||||
protected:
|
||||
virtual bool dispatchEvent(Ion::Events::Event e) = 0;
|
||||
virtual int numberOfTimers();
|
||||
virtual Timer * timerAtIndex(int i);
|
||||
private:
|
||||
bool step();
|
||||
int m_time;
|
||||
Timer * m_firstTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
26
escher/include/escher/slideable_message_text_view.h
Normal file
26
escher/include/escher/slideable_message_text_view.h
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
#ifndef ESCHER_SLIDEABLE_MESSAGE_TEXT_VIEW_H
|
||||
#define ESCHER_SLIDEABLE_MESSAGE_TEXT_VIEW_H
|
||||
|
||||
#include <escher/message_text_view.h>
|
||||
#include <escher/animation_timer.h>
|
||||
|
||||
class SlideableMessageTextView : public MessageTextView, public Animated {
|
||||
public:
|
||||
SlideableMessageTextView(const KDFont * font = KDFont::LargeFont, I18n::Message message = (I18n::Message)0, float horizontalAlignment = 0.0f, float verticalAlignment = 0.0f,
|
||||
KDColor textColor = Palette::PrimaryText, KDColor backgroundColor = Palette::ListCellBackground);
|
||||
void willStartAnimation() override;
|
||||
void didStopAnimation() override;
|
||||
void animate() override;
|
||||
|
||||
/* TextView */
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
|
||||
private:
|
||||
static constexpr uint8_t k_numberOfSpaces = 3;
|
||||
KDCoordinate m_textOffset;
|
||||
bool m_goingLeft; // true if we are going left, false if we are going right
|
||||
bool m_paused;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,25 +3,24 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Timers we'll need
|
||||
* - Blink cursor timer
|
||||
* - Dim Screen timer
|
||||
* - Power down timer
|
||||
* - Watchdog timer ?
|
||||
* - Battery level timer
|
||||
* - LED blink timer
|
||||
/**
|
||||
* A timer that can be used to schedule events.
|
||||
* We organize timers in a linked list.
|
||||
*/
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
static constexpr int TickDuration = 300; // In Miliseconds
|
||||
Timer(uint32_t period); // Period is in ticks
|
||||
bool tick();
|
||||
void reset(uint32_t NewPeriod = -1);
|
||||
void setNext(Timer * next) { m_next = next; }
|
||||
Timer * next() { return m_next; }
|
||||
protected:
|
||||
virtual bool fire() = 0;
|
||||
uint32_t m_period;
|
||||
uint32_t m_numberOfTicksBeforeFire;
|
||||
private:
|
||||
Timer * m_next;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,8 +28,8 @@ protected:
|
||||
/* indexAfterFork is called when a fork-node is encountered to choose which
|
||||
* of its children should be selected, based on external context. */
|
||||
virtual int indexAfterFork() const { assert(false); return 0; };
|
||||
MessageTableCellWithMessage * leafCellAtIndex(int index) override = 0;
|
||||
MessageTableCellWithChevron * nodeCellAtIndex(int index) override = 0;
|
||||
MessageTableCellWithMessage<SlideableMessageTextView> * leafCellAtIndex(int index) override = 0;
|
||||
MessageTableCellWithChevron<SlideableMessageTextView> * nodeCellAtIndex(int index) override = 0;
|
||||
mutable const ToolboxMessageTree * m_messageTreeModel;
|
||||
/* m_messageTreeModel points at the messageTree of the tree (describing the
|
||||
* whole model) where we are located. It enables to know which rows are leaves
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
|
||||
class ToolboxMessageTree : public MessageTree {
|
||||
public:
|
||||
constexpr static ToolboxMessageTree Leaf(I18n::Message label, I18n::Message text = (I18n::Message)0, bool stripInsertedText = true, I18n::Message insertedText = (I18n::Message)0) {
|
||||
constexpr static ToolboxMessageTree Leaf(I18n::Message label, I18n::Message text = (I18n::Message)0, bool stripInsertedText = true, I18n::Message insertedText = (I18n::Message)0, bool multiLine = false, uint8_t numberOfLines = 1) {
|
||||
return ToolboxMessageTree(
|
||||
label,
|
||||
text,
|
||||
(insertedText == (I18n::Message)0) ? label : insertedText,
|
||||
static_cast<ToolboxMessageTree *>(0),
|
||||
0,
|
||||
stripInsertedText);
|
||||
stripInsertedText,
|
||||
multiLine,
|
||||
numberOfLines);
|
||||
};
|
||||
template <int N>
|
||||
constexpr static ToolboxMessageTree Node(I18n::Message label, const ToolboxMessageTree (&children)[N], bool fork = false) {
|
||||
@@ -41,22 +43,28 @@ public:
|
||||
I18n::Message insertedText() const { return m_insertedText; }
|
||||
bool stripInsertedText() const { return m_stripInsertedText; }
|
||||
bool isFork() const { return numberOfChildren() < 0; }
|
||||
bool isMultiLine() const { return m_multiLine; }
|
||||
uint8_t numberOfLines() const { return m_numberOfLines; }
|
||||
private:
|
||||
constexpr ToolboxMessageTree(I18n::Message label, I18n::Message text, I18n::Message insertedText, const ToolboxMessageTree * children, int numberOfChildren, bool stripInsertedText) :
|
||||
constexpr ToolboxMessageTree(I18n::Message label, I18n::Message text, I18n::Message insertedText, const ToolboxMessageTree * children, int numberOfChildren, bool stripInsertedText, bool multiLine = false, uint8_t numberOfLines = 1) :
|
||||
MessageTree(label, numberOfChildren),
|
||||
m_children(children),
|
||||
m_text(text),
|
||||
m_insertedText(insertedText),
|
||||
m_stripInsertedText(stripInsertedText),
|
||||
m_childrenConsecutive(true)
|
||||
m_childrenConsecutive(true),
|
||||
m_multiLine(multiLine),
|
||||
m_numberOfLines(numberOfLines)
|
||||
{}
|
||||
constexpr ToolboxMessageTree(I18n::Message label, I18n::Message text, I18n::Message insertedText, const ToolboxMessageTree ** children, int numberOfChildren, bool stripInsertedText) :
|
||||
constexpr ToolboxMessageTree(I18n::Message label, I18n::Message text, I18n::Message insertedText, const ToolboxMessageTree ** children, int numberOfChildren, bool stripInsertedText, bool multiLine = false, uint8_t numberOfLines = 1) :
|
||||
MessageTree(label, numberOfChildren),
|
||||
m_children(children),
|
||||
m_text(text),
|
||||
m_insertedText(insertedText),
|
||||
m_stripInsertedText(stripInsertedText),
|
||||
m_childrenConsecutive(false)
|
||||
m_childrenConsecutive(false),
|
||||
m_multiLine(multiLine),
|
||||
m_numberOfLines(numberOfLines)
|
||||
{}
|
||||
|
||||
union Children {
|
||||
@@ -71,6 +79,8 @@ private:
|
||||
I18n::Message m_insertedText;
|
||||
bool m_stripInsertedText;
|
||||
const bool m_childrenConsecutive;
|
||||
bool m_multiLine;
|
||||
uint8_t m_numberOfLines;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
15
escher/src/animation_timer.cpp
Normal file
15
escher/src/animation_timer.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <apps/apps_container.h>
|
||||
#include <escher/animation_timer.h>
|
||||
|
||||
|
||||
void AnimationTimer::setAnimated(Animated * animated) {
|
||||
m_animated = animated;
|
||||
AppsContainer::sharedAppsContainer()->addTimer(this);
|
||||
}
|
||||
|
||||
void AnimationTimer::removeAnimated(Animated * animated) {
|
||||
if (m_animated == animated || animated == nullptr) {
|
||||
m_animated = nullptr;
|
||||
AppsContainer::sharedAppsContainer()->removeTimer(this);
|
||||
}
|
||||
}
|
||||
@@ -55,23 +55,3 @@ void Container::run() {
|
||||
window()->redraw();
|
||||
RunLoop::run();
|
||||
}
|
||||
|
||||
int Container::numberOfTimers() {
|
||||
return s_activeApp->numberOfTimers() + numberOfContainerTimers();
|
||||
}
|
||||
|
||||
Timer * Container::timerAtIndex(int i) {
|
||||
if (i < s_activeApp->numberOfTimers()) {
|
||||
return s_activeApp->timerAtIndex(i);
|
||||
}
|
||||
return containerTimerAtIndex(i-s_activeApp->numberOfTimers());
|
||||
}
|
||||
|
||||
int Container::numberOfContainerTimers() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Timer * Container::containerTimerAtIndex(int i) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -1,39 +1,65 @@
|
||||
#include <escher/message_table_cell.h>
|
||||
#include <escher/palette.h>
|
||||
#include <escher/slideable_message_text_view.h>
|
||||
#include <assert.h>
|
||||
|
||||
MessageTableCell::MessageTableCell(I18n::Message label, const KDFont * font, Layout layout) :
|
||||
template<class T>
|
||||
MessageTableCell<T>::MessageTableCell(I18n::Message label, const KDFont * font, Layout layout) :
|
||||
TableCell(layout),
|
||||
m_messageTextView(font, label, 0, 0.5, Palette::PrimaryText, Palette::ListCellBackground),
|
||||
m_backgroundColor(KDColorWhite)
|
||||
{
|
||||
}
|
||||
|
||||
View * MessageTableCell::labelView() const {
|
||||
template<class T>
|
||||
View * MessageTableCell<T>::labelView() const {
|
||||
return (View *)&m_messageTextView;
|
||||
}
|
||||
|
||||
void MessageTableCell::setHighlighted(bool highlight) {
|
||||
template<>
|
||||
void MessageTableCell<SlideableMessageTextView>::setHighlighted(bool highlight) {
|
||||
HighlightCell::setHighlighted(highlight);
|
||||
KDColor backgroundColor = highlight? Palette::ListCellBackgroundSelected : Palette::ListCellBackground;
|
||||
m_messageTextView.setBackgroundColor(backgroundColor);
|
||||
static AnimationTimer s_animationTimer = AnimationTimer();
|
||||
if (highlight) {
|
||||
m_messageTextView.willStartAnimation();
|
||||
s_animationTimer.setAnimated(&m_messageTextView);
|
||||
} else {
|
||||
s_animationTimer.removeAnimated(&m_messageTextView);
|
||||
m_messageTextView.didStopAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void MessageTableCell<MessageTextView>::setHighlighted(bool highlight) {
|
||||
HighlightCell::setHighlighted(highlight);
|
||||
KDColor backgroundColor = highlight? Palette::ListCellBackgroundSelected : Palette::ListCellBackground;
|
||||
m_messageTextView.setBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
void MessageTableCell::setMessage(I18n::Message text) {
|
||||
template<class T>
|
||||
void MessageTableCell<T>::setMessage(I18n::Message text) {
|
||||
m_messageTextView.setMessage(text);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
void MessageTableCell::setTextColor(KDColor color) {
|
||||
template<class T>
|
||||
void MessageTableCell<T>::setTextColor(KDColor color) {
|
||||
m_messageTextView.setTextColor(color);
|
||||
}
|
||||
|
||||
void MessageTableCell::setMessageFont(const KDFont * font) {
|
||||
template<class T>
|
||||
void MessageTableCell<T>::setMessageFont(const KDFont * font) {
|
||||
m_messageTextView.setFont(font);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
void MessageTableCell::setBackgroundColor(KDColor color) {
|
||||
template<class T>
|
||||
void MessageTableCell<T>::setBackgroundColor(KDColor color) {
|
||||
m_backgroundColor = color;
|
||||
m_messageTextView.setBackgroundColor(color);
|
||||
}
|
||||
|
||||
template class MessageTableCell<MessageTextView>;
|
||||
template class MessageTableCell<SlideableMessageTextView>;
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
#include <escher/message_table_cell_with_chevron.h>
|
||||
|
||||
MessageTableCellWithChevron::MessageTableCellWithChevron(I18n::Message message, const KDFont * font) :
|
||||
MessageTableCell(message, font),
|
||||
template<>
|
||||
MessageTableCellWithChevron<MessageTextView>::MessageTableCellWithChevron(I18n::Message message, const KDFont * font) :
|
||||
MessageTableCell<MessageTextView>(message, font),
|
||||
m_accessoryView()
|
||||
{
|
||||
}
|
||||
|
||||
View * MessageTableCellWithChevron::accessoryView() const {
|
||||
template<>
|
||||
MessageTableCellWithChevron<SlideableMessageTextView>::MessageTableCellWithChevron(I18n::Message message, const KDFont * font) :
|
||||
MessageTableCell<SlideableMessageTextView>(message, font,TableCell::Layout::HorizontalRightOverlap),
|
||||
m_accessoryView()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
View * MessageTableCellWithChevron<T>::accessoryView() const {
|
||||
return (View *)&m_accessoryView;
|
||||
}
|
||||
|
||||
template class MessageTableCellWithChevron<MessageTextView>;
|
||||
template class MessageTableCellWithChevron<SlideableMessageTextView>;
|
||||
|
||||
|
||||
@@ -2,38 +2,47 @@
|
||||
#include <escher/palette.h>
|
||||
#include <string.h>
|
||||
|
||||
MessageTableCellWithMessage::MessageTableCellWithMessage(I18n::Message message, Layout layout) :
|
||||
MessageTableCell(message, KDFont::SmallFont, layout),
|
||||
template <class T>
|
||||
MessageTableCellWithMessage<T>::MessageTableCellWithMessage(I18n::Message message, TableCell::Layout layout) :
|
||||
MessageTableCell<T>(message, KDFont::SmallFont, layout),
|
||||
m_accessoryView(KDFont::SmallFont, (I18n::Message)0, 0.0f, 0.5f)
|
||||
{
|
||||
if (layout != Layout::Vertical) {
|
||||
if (layout != TableCell::Layout::Vertical) {
|
||||
m_accessoryView.setAlignment(1.0f, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageTableCellWithMessage::setAccessoryMessage(I18n::Message textBody) {
|
||||
template <class T>
|
||||
void MessageTableCellWithMessage<T>::setAccessoryMessage(I18n::Message textBody) {
|
||||
m_accessoryView.setMessage(textBody);
|
||||
reloadCell();
|
||||
this->reloadCell();
|
||||
}
|
||||
|
||||
View * MessageTableCellWithMessage::accessoryView() const {
|
||||
template <class T>
|
||||
View * MessageTableCellWithMessage<T>::accessoryView() const {
|
||||
if (strlen(m_accessoryView.text()) == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return (View *)&m_accessoryView;
|
||||
}
|
||||
|
||||
void MessageTableCellWithMessage::setHighlighted(bool highlight) {
|
||||
MessageTableCell::setHighlighted(highlight);
|
||||
KDColor backgroundColor = isHighlighted()? Palette::ListCellBackgroundSelected : Palette::ListCellBackground;
|
||||
template <class T>
|
||||
void MessageTableCellWithMessage<T>::setHighlighted(bool highlight) {
|
||||
MessageTableCell<T>::setHighlighted(highlight);
|
||||
KDColor backgroundColor = this->isHighlighted()? Palette::ListCellBackgroundSelected : Palette::ListCellBackground;
|
||||
m_accessoryView.setBackgroundColor(backgroundColor);
|
||||
}
|
||||
|
||||
void MessageTableCellWithMessage::setTextColor(KDColor color) {
|
||||
template <class T>
|
||||
void MessageTableCellWithMessage<T>::setTextColor(KDColor color) {
|
||||
m_accessoryView.setTextColor(color);
|
||||
MessageTableCell::setTextColor(color);
|
||||
MessageTableCell<T>::setTextColor(color);
|
||||
}
|
||||
|
||||
void MessageTableCellWithMessage::setAccessoryTextColor(KDColor color) {
|
||||
template <class T>
|
||||
void MessageTableCellWithMessage<T>::setAccessoryTextColor(KDColor color) {
|
||||
m_accessoryView.setTextColor(color);
|
||||
}
|
||||
|
||||
template class MessageTableCellWithMessage<MessageTextView>;
|
||||
template class MessageTableCellWithMessage<SlideableMessageTextView>;
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
#include <assert.h>
|
||||
|
||||
RunLoop::RunLoop() :
|
||||
m_time(0) {
|
||||
}
|
||||
|
||||
int RunLoop::numberOfTimers() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Timer * RunLoop::timerAtIndex(int i) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
m_time(0),
|
||||
m_firstTimer(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void RunLoop::run() {
|
||||
@@ -45,11 +38,12 @@ bool RunLoop::step() {
|
||||
|
||||
if (m_time >= Timer::TickDuration) {
|
||||
m_time -= Timer::TickDuration;
|
||||
for (int i=0; i<numberOfTimers(); i++) {
|
||||
Timer * timer = timerAtIndex(i);
|
||||
Timer * timer = m_firstTimer;
|
||||
while (timer) {
|
||||
if (timer->tick()) {
|
||||
dispatchEvent(Ion::Events::TimerFire);
|
||||
}
|
||||
timer = timer->next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +59,7 @@ bool RunLoop::step() {
|
||||
#endif
|
||||
|
||||
if (event != Ion::Events::None) {
|
||||
#if !PLATFORM_DEVICE
|
||||
#if !PLATFORM_DEVICEdidStopAnimation
|
||||
if (event == Ion::Events::ExternalText && !KDFont::CanBeWrittenWithGlyphs(event.text())) {
|
||||
return true;
|
||||
}
|
||||
@@ -75,3 +69,27 @@ bool RunLoop::step() {
|
||||
|
||||
return event != Ion::Events::Termination;
|
||||
}
|
||||
|
||||
void RunLoop::addTimer(Timer * timer) {
|
||||
if (m_firstTimer == nullptr) {
|
||||
m_firstTimer = timer;
|
||||
} else {
|
||||
Timer * actual = m_firstTimer;
|
||||
while (actual->next()) {
|
||||
actual = actual->next();
|
||||
}
|
||||
actual->setNext(timer);
|
||||
}
|
||||
}
|
||||
|
||||
void RunLoop::removeTimer(Timer * timer) {
|
||||
if (m_firstTimer == timer) {
|
||||
m_firstTimer = timer->next();
|
||||
} else {
|
||||
Timer * actual = m_firstTimer;
|
||||
while (actual->next() != timer) {
|
||||
actual = actual->next();
|
||||
}
|
||||
actual->setNext(timer->next());
|
||||
}
|
||||
}
|
||||
|
||||
63
escher/src/slideable_message_text_view.cpp
Normal file
63
escher/src/slideable_message_text_view.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <escher/slideable_message_text_view.h>
|
||||
#include <apps/apps_container.h>
|
||||
|
||||
SlideableMessageTextView::SlideableMessageTextView(const KDFont * font, I18n::Message message, float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor backgroundColor) :
|
||||
MessageTextView(font, message, horizontalAlignment, verticalAlignment, textColor, backgroundColor),
|
||||
m_textOffset(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SlideableMessageTextView::willStartAnimation() {
|
||||
m_textOffset = 0;
|
||||
m_goingLeft = true;
|
||||
m_paused = true;
|
||||
}
|
||||
|
||||
void SlideableMessageTextView::didStopAnimation() {
|
||||
m_textOffset = 0;
|
||||
}
|
||||
|
||||
void SlideableMessageTextView::animate() {
|
||||
if (m_paused) {
|
||||
m_paused = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (text() == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
KDSize textSize = m_font->stringSize(text());
|
||||
|
||||
if (textSize.width() <= bounds().width()) {
|
||||
return;
|
||||
}
|
||||
|
||||
KDCoordinate glyphWidth = m_font->glyphSize().width();
|
||||
m_textOffset += glyphWidth * (m_goingLeft ? -1 : 1);
|
||||
|
||||
if (m_goingLeft && textSize.width() + m_textOffset < bounds().width()) {
|
||||
m_goingLeft = false;
|
||||
m_textOffset = bounds().width() - textSize.width();
|
||||
m_paused = true;
|
||||
} else if (!m_goingLeft && m_textOffset > 0) {
|
||||
m_goingLeft = true;
|
||||
m_textOffset = 0;
|
||||
m_paused = true;
|
||||
}
|
||||
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
void SlideableMessageTextView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
if (text() == nullptr) {
|
||||
return;
|
||||
}
|
||||
KDSize textSize = m_font->stringSize(text());
|
||||
KDPoint origin(
|
||||
m_horizontalAlignment * (m_frame.width() - textSize.width()) + m_textOffset,
|
||||
m_verticalAlignment * (m_frame.height() - textSize.height()));
|
||||
ctx->fillRect(bounds(), m_backgroundColor);
|
||||
ctx->drawString(text(), origin, m_font, m_textColor, m_backgroundColor);
|
||||
}
|
||||
@@ -27,15 +27,16 @@ int Toolbox::reusableCellCount(int type) {
|
||||
void Toolbox::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
ToolboxMessageTree * messageTree = (ToolboxMessageTree *)m_messageTreeModel->childAtIndex(index);
|
||||
if (messageTree->numberOfChildren() == 0) {
|
||||
MessageTableCellWithMessage * myCell = (MessageTableCellWithMessage *)cell;
|
||||
MessageTableCellWithMessage<SlideableMessageTextView> * myCell = (MessageTableCellWithMessage<SlideableMessageTextView> *)cell;
|
||||
myCell->setMessage(messageTree->label());
|
||||
myCell->setAccessoryMessage(messageTree->text());
|
||||
myCell->setAccessoryTextColor(Palette::SecondaryText);
|
||||
return;
|
||||
} else {
|
||||
MessageTableCell<> * myCell = (MessageTableCell<> *)cell;
|
||||
myCell->setMessage(messageTree->label());
|
||||
myCell->reloadCell();
|
||||
}
|
||||
MessageTableCell * myCell = (MessageTableCell *)cell;
|
||||
myCell->setMessage(messageTree->label());
|
||||
myCell->reloadCell();
|
||||
}
|
||||
|
||||
int Toolbox::typeAtLocation(int i, int j) {
|
||||
|
||||
Reference in New Issue
Block a user