Cosmetics

This commit is contained in:
Bertrand Songis
2020-04-20 18:49:02 +02:00
parent 41718815f2
commit 71ccf023b1
27 changed files with 72 additions and 59 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ class BaseNumberEdit : public FormField {
_setValue = handler; _setValue = handler;
} }
int32_t getValue() int32_t getValue() const
{ {
return _getValue(); return _getValue();
} }
+1 -1
View File
@@ -106,7 +106,7 @@ class TransparentBitmapBackground: public TransparentBufferedWindow<Window>
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "TransparentBitmapBackground"; return "TransparentBitmapBackground";
} }
+4 -4
View File
@@ -31,12 +31,12 @@ class Button: public FormField {
public: public:
Button(FormGroup * parent, const rect_t & rect, std::function<uint8_t(void)> pressHandler = nullptr, WindowFlags windowFlags = 0): Button(FormGroup * parent, const rect_t & rect, std::function<uint8_t(void)> pressHandler = nullptr, WindowFlags windowFlags = 0):
FormField(parent, rect, windowFlags), FormField(parent, rect, windowFlags),
pressHandler(pressHandler) pressHandler(std::move(pressHandler))
{ {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "Button"; return "Button";
} }
@@ -112,7 +112,7 @@ class TextButton: public Button {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "TextButton \"" + text + "\""; return "TextButton \"" + text + "\"";
} }
@@ -141,7 +141,7 @@ class IconButton: public Button {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "IconButton(" + std::to_string(icon) + ")"; return "IconButton(" + std::to_string(icon) + ")";
} }
+2
View File
@@ -48,6 +48,7 @@ void CarouselWindow::update()
setInnerWidth(lastPosition); setInnerWidth(lastPosition);
} }
#if defined(HARDWARE_KEYS)
void Carousel::onEvent(event_t event) void Carousel::onEvent(event_t event)
{ {
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
@@ -64,3 +65,4 @@ void Carousel::onEvent(event_t event)
Window::onEvent(event); Window::onEvent(event);
} }
} }
#endif
+2 -2
View File
@@ -91,7 +91,7 @@ class Carousel: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "Carousel"; return "Carousel";
} }
@@ -114,7 +114,7 @@ class Carousel: public Window {
nextButton->enable(index < (int)body->items.size() - 1); nextButton->enable(index < (int)body->items.size() - 1);
} }
int getSelection() int getSelection() const
{ {
return body->selection; return body->selection;
} }
+1 -1
View File
@@ -33,7 +33,7 @@ class CheckBox : public FormField {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "CheckBox"; return "CheckBox";
} }
+1 -1
View File
@@ -57,7 +57,7 @@ class Choice : public ChoiceBase {
void addItems(const char * items[], uint8_t count); void addItems(const char * items[], uint8_t count);
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "Choice"; return "Choice";
} }
+1 -1
View File
@@ -33,7 +33,7 @@ class ColorBox: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "ColorBox"; return "ColorBox";
} }
+1 -1
View File
@@ -27,7 +27,7 @@ class ColorEdit : public FormGroup {
ColorEdit(FormGroup * parent, const rect_t & rect, std::function<uint16_t()> getValue, std::function<void(uint16_t)> setValue = nullptr); ColorEdit(FormGroup * parent, const rect_t & rect, std::function<uint16_t()> getValue, std::function<void(uint16_t)> setValue = nullptr);
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "ColorEdit"; return "ColorEdit";
} }
+1 -1
View File
@@ -37,7 +37,7 @@ class DialogWindowContent: public ModalWindowContent {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "DialogWindowContent"; return "DialogWindowContent";
} }
+2 -2
View File
@@ -29,7 +29,7 @@ class ExpansionPanelHeader: virtual public FormGroup {
explicit ExpansionPanelHeader(ExpansionPanel * parent); explicit ExpansionPanelHeader(ExpansionPanel * parent);
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "ExpansionPanelHeader"; return "ExpansionPanelHeader";
} }
@@ -53,7 +53,7 @@ class ExpansionPanel: public FormGroup {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "ExpansionPanel"; return "ExpansionPanel";
} }
+1 -1
View File
@@ -28,7 +28,7 @@ class FileChoice: public ChoiceBase {
FileChoice(FormGroup * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function<std::string()> getValue, std::function<void(std::string)> setValue); FileChoice(FormGroup * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function<std::string()> getValue, std::function<void(std::string)> setValue);
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "FileChoice"; return "FileChoice";
} }
+2 -2
View File
@@ -94,7 +94,7 @@ class FormGroup: public FormField {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "FormGroup"; return "FormGroup";
} }
@@ -135,7 +135,7 @@ class FormWindow: public FormGroup {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "FormWindow"; return "FormWindow";
} }
+1 -1
View File
@@ -29,7 +29,7 @@ class NumberKeyboard : public Keyboard {
~NumberKeyboard() override; ~NumberKeyboard() override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "NumberKeyboard"; return "NumberKeyboard";
} }
+1 -1
View File
@@ -37,7 +37,7 @@ class TextKeyboard : public Keyboard {
~TextKeyboard() override; ~TextKeyboard() override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "TextKeyboard"; return "TextKeyboard";
} }
+1 -1
View File
@@ -33,7 +33,7 @@ class MainWindow: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "MainWindow"; return "MainWindow";
} }
+3 -2
View File
@@ -73,13 +73,14 @@ bool MenuBody::onTouchEnd(coord_t /*x*/, coord_t y)
void MenuBody::paint(BitmapBuffer * dc) void MenuBody::paint(BitmapBuffer * dc)
{ {
for (auto i = 0; i < (int)lines.size(); i++) { for (unsigned i = 0; i < lines.size(); i++) {
auto & line = lines[i]; auto & line = lines[i];
LcdFlags flags = MENU_COLOR | MENU_FONT; LcdFlags flags = MENU_COLOR | MENU_FONT;
if (selectedIndex == i) { if (selectedIndex == i) {
flags = MENU_HIGHLIGHT_COLOR | MENU_FONT; flags = MENU_HIGHLIGHT_COLOR | MENU_FONT;
if (MENU_HIGHLIGHT_BGCOLOR != MENU_BGCOLOR) if (MENU_HIGHLIGHT_BGCOLOR != MENU_BGCOLOR) {
dc->drawSolidFilledRect(0, i * MENUS_LINE_HEIGHT, width(), MENUS_LINE_HEIGHT, MENU_HIGHLIGHT_BGCOLOR); dc->drawSolidFilledRect(0, i * MENUS_LINE_HEIGHT, width(), MENUS_LINE_HEIGHT, MENU_HIGHLIGHT_BGCOLOR);
}
} }
if (line.drawLine) { if (line.drawLine) {
line.drawLine(dc, 0, i * MENUS_LINE_HEIGHT /*+ (lineHeight - 20) / 2*/, flags); line.drawLine(dc, 0, i * MENUS_LINE_HEIGHT /*+ (lineHeight - 20) / 2*/, flags);
+5 -5
View File
@@ -66,7 +66,7 @@ class MenuBody: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "MenuBody"; return "MenuBody";
} }
@@ -74,12 +74,12 @@ class MenuBody: public Window {
void select(int index); void select(int index);
int selection() int selection() const
{ {
return selectedIndex; return selectedIndex;
} }
int count() int count() const
{ {
return lines.size(); return lines.size();
} }
@@ -112,7 +112,7 @@ class MenuBody: public Window {
void setCancelHandler(std::function<void()> handler) void setCancelHandler(std::function<void()> handler)
{ {
onCancel = handler; onCancel = std::move(handler);
} }
void paint(BitmapBuffer * dc) override; void paint(BitmapBuffer * dc) override;
@@ -139,7 +139,7 @@ class MenuWindowContent: public ModalWindowContent {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "MenuWindowContent"; return "MenuWindowContent";
} }
+2 -2
View File
@@ -28,7 +28,7 @@ class ModalWindow: public Window
explicit ModalWindow(Window * parent); explicit ModalWindow(Window * parent);
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "ModalWindow"; return "ModalWindow";
} }
@@ -77,7 +77,7 @@ class ModalWindowContent: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "ModalWindowContent"; return "ModalWindowContent";
} }
+1 -1
View File
@@ -29,7 +29,7 @@ class NumberEdit : public BaseNumberEdit {
std::function<int32_t()> getValue, std::function<void(int32_t)> setValue = nullptr, WindowFlags windowFlags = 0, LcdFlags textFlags = 0); std::function<int32_t()> getValue, std::function<void(int32_t)> setValue = nullptr, WindowFlags windowFlags = 0, LcdFlags textFlags = 0);
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "NumberEdit(" + std::to_string(getValue()) + ")"; return "NumberEdit(" + std::to_string(getValue()) + ")";
} }
+2 -2
View File
@@ -30,7 +30,7 @@ class Progress : public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "Progress"; return "Progress";
} }
@@ -45,7 +45,7 @@ class Progress : public Window {
void paint(BitmapBuffer * dc) override; void paint(BitmapBuffer * dc) override;
protected: protected:
int value; int value = 0;
}; };
#endif #endif
+1 -1
View File
@@ -34,7 +34,7 @@ class Slider: public FormField {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "Slider"; return "Slider";
} }
+3 -3
View File
@@ -32,7 +32,7 @@ class StaticText: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "StaticText \"" + text + "\""; return "StaticText \"" + text + "\"";
} }
@@ -58,7 +58,7 @@ class Subtitle: public StaticText {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "Subtitle \"" + text + "\""; return "Subtitle \"" + text + "\"";
} }
@@ -100,7 +100,7 @@ class StaticBitmap: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "StaticBitmap"; return "StaticBitmap";
} }
+3 -3
View File
@@ -46,7 +46,7 @@ class Table: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "Table::Header"; return "Table::Header";
} }
@@ -75,7 +75,7 @@ class Table: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "Table::Body"; return "Table::Body";
} }
@@ -134,7 +134,7 @@ class Table: public Window {
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "Table"; return "Table";
} }
+3 -3
View File
@@ -35,7 +35,7 @@ class TextEdit : public FormField {
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() override std::string getName() const override
{ {
return "TextEdit"; return "TextEdit";
} }
@@ -46,12 +46,12 @@ class TextEdit : public FormField {
changeHandler = handler; changeHandler = handler;
} }
uint8_t getMaxLength() uint8_t getMaxLength() const
{ {
return length; return length;
} }
char * getData() char * getData() const
{ {
return value; return value;
} }
+14 -6
View File
@@ -138,7 +138,7 @@ void Window::setFocus(uint8_t flag)
void Window::setScrollPositionX(coord_t value) void Window::setScrollPositionX(coord_t value)
{ {
coord_t newScrollPosition = max<coord_t>(0, min<coord_t>(innerWidth - width(), value)); auto newScrollPosition = max<coord_t>(0, min<coord_t>(innerWidth - width(), value));
if (newScrollPosition != scrollPositionX) { if (newScrollPosition != scrollPositionX) {
scrollPositionX = newScrollPosition; scrollPositionX = newScrollPosition;
invalidate(); invalidate();
@@ -147,7 +147,12 @@ void Window::setScrollPositionX(coord_t value)
void Window::setScrollPositionY(coord_t value) void Window::setScrollPositionY(coord_t value)
{ {
coord_t newScrollPosition = max<coord_t>(0, min<coord_t>(innerHeight - height(), value)); auto newScrollPosition = min<coord_t>(innerHeight - height(), value);
if (newScrollPosition < 0 && innerHeight != INFINITE_HEIGHT) {
newScrollPosition = 0;
}
if (newScrollPosition != scrollPositionY) { if (newScrollPosition != scrollPositionY) {
scrollPositionY = newScrollPosition; scrollPositionY = newScrollPosition;
invalidate(); invalidate();
@@ -192,7 +197,7 @@ void Window::scrollTo(const rect_t & rect)
} }
} }
bool Window::hasOpaqueRect(const rect_t & rect) bool Window::hasOpaqueRect(const rect_t & rect) const
{ {
if (!this->rect.contains(rect)) if (!this->rect.contains(rect))
return false; return false;
@@ -253,12 +258,12 @@ void Window::fullPaint(BitmapBuffer * dc)
} }
} }
bool Window::isChildFullSize(Window * child) bool Window::isChildFullSize(const Window * child) const
{ {
return child->top() == 0 && child->height() == height() && child->left() == 0 && child->width() == width(); return child->top() == 0 && child->height() == height() && child->left() == 0 && child->width() == width();
} }
bool Window::isChildVisible(Window * window) bool Window::isChildVisible(const Window * window) const
{ {
for (auto rit = children.rbegin(); rit != children.rend(); rit++) { for (auto rit = children.rbegin(); rit != children.rend(); rit++) {
auto child = *rit; auto child = *rit;
@@ -333,7 +338,10 @@ void Window::checkEvents()
if (pageHeight) { if (pageHeight) {
coord_t relativeScrollPosition = scrollPositionY % pageHeight; coord_t relativeScrollPosition = scrollPositionY % pageHeight;
if (relativeScrollPosition) { if (relativeScrollPosition) {
setScrollPositionY(getScrollPositionY() - relativeScrollPosition + (relativeScrollPosition > pageHeight / 2 ? pageHeight : 0)); if (relativeScrollPosition > 0)
setScrollPositionY(getScrollPositionY() - relativeScrollPosition + (relativeScrollPosition > pageHeight / 2 ? pageHeight : 0));
else
setScrollPositionY(getScrollPositionY() - relativeScrollPosition - (relativeScrollPosition > -pageHeight / 2 ? 0 : pageHeight));
} }
} }
} }
+12 -10
View File
@@ -39,6 +39,8 @@ typedef uint32_t WindowFlags;
#undef TRANSPARENT #undef TRANSPARENT
#endif #endif
constexpr int INFINITE_HEIGHT = INT32_MAX;
constexpr WindowFlags OPAQUE = 1u << 0u; constexpr WindowFlags OPAQUE = 1u << 0u;
constexpr WindowFlags TRANSPARENT = 1u << 1u; constexpr WindowFlags TRANSPARENT = 1u << 1u;
constexpr WindowFlags NO_SCROLLBAR = 1u << 2u; constexpr WindowFlags NO_SCROLLBAR = 1u << 2u;
@@ -65,19 +67,19 @@ class Window {
virtual ~Window(); virtual ~Window();
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
virtual std::string getName() virtual std::string getName() const
{ {
return "Window"; return "Window";
} }
std::string getRectString() std::string getRectString() const
{ {
char result[32]; char result[32];
sprintf(result, "[%d, %d, %d, %d]", left(), top(), width(), height()); sprintf(result, "[%d, %d, %d, %d]", left(), top(), width(), height());
return result; return result;
} }
std::string getIndentString() std::string getIndentString() const
{ {
std::string result; std::string result;
auto tmp = parent; auto tmp = parent;
@@ -88,7 +90,7 @@ class Window {
return result; return result;
} }
std::string getWindowDebugString(const char * name = nullptr) std::string getWindowDebugString(const char * name = nullptr) const
{ {
return getName() + (name ? std::string(" [") + name + "] " : " ") + getRectString(); return getName() + (name ? std::string(" [") + name + "] " : " ") + getRectString();
} }
@@ -252,7 +254,7 @@ class Window {
pageHeight = h; pageHeight = h;
} }
uint8_t getPageCount() uint8_t getPageCount() const
{ {
if (pageWidth) if (pageWidth)
return innerWidth / pageWidth; return innerWidth / pageWidth;
@@ -262,7 +264,7 @@ class Window {
return 1; return 1;
} }
uint8_t getPageIndex() uint8_t getPageIndex() const
{ {
if (pageWidth) if (pageWidth)
return (getScrollPositionX() + (pageWidth / 2)) / pageWidth; return (getScrollPositionX() + (pageWidth / 2)) / pageWidth;
@@ -305,11 +307,11 @@ class Window {
void setScrollPositionY(coord_t value); void setScrollPositionY(coord_t value);
bool isChildVisible(Window * window); bool isChildVisible(const Window * window) const;
bool isChildFullSize(Window * window); bool isChildFullSize(const Window * window) const;
bool isVisible() bool isVisible() const
{ {
return parent && parent->isChildVisible(this); return parent && parent->isChildVisible(this);
} }
@@ -400,7 +402,7 @@ class Window {
bool forwardTouchEnd(coord_t x, coord_t y); bool forwardTouchEnd(coord_t x, coord_t y);
bool hasOpaqueRect(const rect_t & rect); bool hasOpaqueRect(const rect_t & rect) const;
}; };
#endif // _WINDOW_H_ #endif // _WINDOW_H_