Skip to content

Commit

Permalink
Develop (#15)
Browse files Browse the repository at this point in the history
* Fix build (add missing include in Widget.h and simpleExample)

* Add PlatformIO project file to simpleExample

* Update m5stack lib (#12)

* Fix DrawBitmap according to new versions of M5Stack lib

* Reduce flickering (#13)

* Do not refresh the whole button when only the texte has changed
* Replace the UpdateFlag logic by a (better) Invalidate logic

* Fix crash when trying to zoom on a NULL widget.

* Removed unused include. (#14)

* Set version to 0.3.0.
  • Loading branch information
JF002 authored Jan 27, 2019
1 parent 346e853 commit 6485195
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 89 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ Then, you just need to include the headers (e.g. #include <Screen.h>) and write

Look at examples if you need some inspiration ;-)

**NOTE : ** This project was built with version 0.1.9 of M5STack. Since then, a little change has been made on method DrawBitmap which is not compatible with this version of cfGUI. Until I write a fix, you should use version 0.1.9 of M5Stack.

Here is an example of `platformio.ini` file:

```
[env:m5stack-core-esp32]
platform = espressif32
board = m5stack-core-esp32
framework = arduino
lib_deps=M5Stack@0.1.9, NTPClient
lib_deps=M5Stack, NTPClient
build_flags=-std=gnu++11
```

Expand All @@ -41,6 +39,11 @@ build_flags=-std=gnu++11
- Better 'focus' management

# Changelog
## 0.3.0
- New redraw() strategy (replace SetUpdatedFlag() by Invalidate(), performances improved and flickering reduced
- Support new version of M5Stack lib
- Fix crash when the center button was pushed with no widget selected

## 0.2.0
- Change default font (looks better)
- New widgets (AppScreen, StatusBar, ButtonInfoBar, UpDownButton)
Expand Down
67 changes: 67 additions & 0 deletions examples/simpleExample/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < https://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < https://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#


#
# Template #1: General project. Test it using existing `platformio.ini`.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run


#
# Template #2: The project is intended to be used as a library with examples.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
16 changes: 16 additions & 0 deletions examples/simpleExample/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:m5stack-core-esp32]
platform = espressif32
board = m5stack-core-esp32
framework = arduino
lib_deps[email protected], NTPClient
build_flags=-std=gnu++11
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <M5Stack.h>

#include <NTPClient.h>
#include <Screen.h>
#include <ButtonInfoBar.h>
#include <StatusBar.h>
Expand All @@ -11,6 +10,8 @@
#include <sys/time.h>
#include <AppScreen.h>
#include <UpDownButton.h>
#include <WiFi.h>


using namespace Codingfield::UI;
AppScreen* screen;
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=cfGUI
version=0.2.0
version=0.3.0
author=Jean-François Milants <[email protected]>
maintainer=Jean-François Milants <[email protected]>
sentence=cfGUI
Expand Down
4 changes: 2 additions & 2 deletions src/Bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ using namespace Codingfield::UI;

void Bar::Draw() {
if(IsHidden()) return;
if(isUpdated)
if(isInvalidated)
M5.Lcd.fillRect(position.x, position.y, size.width, size.height, WHITE);

isUpdated = false;
isInvalidated = false;
}
83 changes: 63 additions & 20 deletions src/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Codingfield::UI::Button::Button(Widget* parent, Point position, Size size) : Wid
}

void Codingfield::UI::Button::SetBackgroundColor(Color c) {
backgroundColorUpdated = true;
this->backgroundColor = c;
}

Expand All @@ -23,50 +24,92 @@ void Codingfield::UI::Button::SetTextColor(Color c) {

void Codingfield::UI::Button::SetSelected(bool s) {
if(isSelected != s) {
wasSelected = isSelected;
isSelected = s;
SetUpdateFlag();
}
}

void Codingfield::UI::Button::SetText(const std::string& t) {
if(text != t) {
if(text.empty())
oldText = t;
else
this->oldText = this->text;
this->text = t;
SetUpdateFlag();
}
}

void Codingfield::UI::Button::SetTitle(const std::string& t) {
if(title != t) {
if(title.empty())
oldTitle = t;
else
oldTitle = title;
title = t;
SetUpdateFlag();
}
}

void Codingfield::UI::Button::Draw() {
if(IsHidden()) return;
if(isUpdated) {
M5.Lcd.setTextColor(textColor);
if(IsHidden()){
return;
}
if(true) {
bool forceUpdate = isInvalidated;
if(forceUpdate) {
Serial.println("FORCEUPDATE");

M5.Lcd.fillRect(position.x, position.y, size.width, size.height, backgroundColor);
M5.Lcd.setTextDatum(MC_DATUM);
M5.Lcd.setTextColor(textColor);
}
int x = position.x + (size.width/2);
int yText;
int yTitle;
if(title.empty()) {
M5.Lcd.setFreeFont(FF22);
M5.Lcd.drawString(text.c_str(), position.x + (size.width/2), position.y + (size.height/2));
M5.Lcd.setFreeFont(FF21);
yText = position.y + (size.height/2);
} else {
yText = position.y + (size.height/3);
yTitle = position.y + ((size.height/3)*2);
}
else {

if(backgroundColorUpdated || forceUpdate) {
M5.Lcd.fillRect(position.x, position.y, size.width, size.height, backgroundColor);
backgroundColorUpdated = false;
forceUpdate = true;
}

if(forceUpdate || (oldText != text)) {
M5.Lcd.setTextDatum(MC_DATUM);
M5.Lcd.setTextColor(backgroundColor);

M5.Lcd.setFreeFont(FF22);
M5.Lcd.drawString(text.c_str(), position.x + (size.width/2), position.y + (size.height/3));
M5.Lcd.drawString(oldText.c_str(), x, yText);

M5.Lcd.setTextColor(textColor);
M5.Lcd.drawString(text.c_str(), x, yText);
oldText = text;
}

if(forceUpdate || (oldTitle != title)) {
M5.Lcd.setTextDatum(MC_DATUM);
M5.Lcd.setTextColor(backgroundColor);

M5.Lcd.setFreeFont(FF21);
M5.Lcd.drawString(title.c_str(), position.x + (size.width/2), position.y + ((size.height/3)*2));
M5.Lcd.drawString(oldTitle.c_str(), x, yTitle);

M5.Lcd.setTextColor(textColor);
M5.Lcd.drawString(title.c_str(), x, yTitle);
oldTitle = title;
}

if(isSelected) {
M5.Lcd.drawRect(position.x, position.y, size.width, size.height, RED);
M5.Lcd.drawRect(position.x+1, position.y+1, size.width-2, size.height-2, RED);
M5.Lcd.drawRect(position.x+2, position.y+2, size.width-4, size.height-4, RED);
if(forceUpdate || (wasSelected != isSelected)) {
if(isSelected) {
M5.Lcd.drawRect(position.x, position.y, size.width, size.height, RED);
M5.Lcd.drawRect(position.x+1, position.y+1, size.width-2, size.height-2, RED);
M5.Lcd.drawRect(position.x+2, position.y+2, size.width-4, size.height-4, RED);
} else {
M5.Lcd.drawRect(position.x, position.y, size.width, size.height, backgroundColor);
M5.Lcd.drawRect(position.x + 1, position.y + 1, size.width - 2, size.height - 2, backgroundColor);
M5.Lcd.drawRect(position.x + 2, position.y + 2, size.width - 4, size.height - 4, backgroundColor);
}
}
}
isUpdated = false;
isInvalidated = false;
}
5 changes: 4 additions & 1 deletion src/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ namespace Codingfield {
void Draw() override;
protected:
Color backgroundColor = BLACK;
bool backgroundColorUpdated = true;
Color textColor = BLACK;
std::string text;
std::string oldText;
std::string title;

std::string oldTitle;
bool wasSelected = false;
};
}
}
33 changes: 25 additions & 8 deletions src/ButtonInfoBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,58 @@ using namespace Codingfield::UI;

void ButtonInfoBar::SetButtonAText(const std::string& t) {
if(btnAText != t) {
oldBtnAText = btnAText;
btnAText = t;
isUpdated = true;
}
}

void ButtonInfoBar::SetButtonBText(const std::string& t) {
if(btnBText != t) {
oldBtnBText = btnBText;
btnBText = t;
isUpdated = true;
}
}

void ButtonInfoBar::SetButtonCText(const std::string& t) {
if(btnCText != t) {
oldBtnCText = btnCText;
btnCText = t;
isUpdated = true;
}
}

void ButtonInfoBar::Draw() {
if(IsHidden()) return;
bool oldIsUpdated = isUpdated;
bool oldIsInvalidated = isInvalidated;
Bar::Draw();

if(oldIsUpdated) {
M5.Lcd.setTextColor(BLACK);

if(oldIsInvalidated || (oldBtnAText != btnAText)) {
M5.Lcd.setTextDatum(TC_DATUM);
M5.Lcd.setTextColor(color);
M5.Lcd.drawString(oldBtnAText.c_str(), (size.width/6), position.y + 5);
M5.Lcd.setTextColor(BLACK);
M5.Lcd.drawString(btnAText.c_str(), (size.width/6), position.y + 5);

oldBtnAText = btnAText;
}

if(oldIsInvalidated || (oldBtnBText != btnBText)) {
M5.Lcd.setTextDatum(TC_DATUM);
M5.Lcd.setTextColor(color);
M5.Lcd.drawString(oldBtnBText.c_str(), size.width/2, position.y + 5);
M5.Lcd.setTextColor(BLACK);
M5.Lcd.drawString(btnBText.c_str(), size.width/2, position.y + 5);

oldBtnBText = btnBText;
}

if(oldIsInvalidated || (oldBtnCText != btnCText)) {
M5.Lcd.setTextDatum(TC_DATUM);
M5.Lcd.setTextColor(color);
M5.Lcd.drawString(oldBtnCText.c_str(), ((size.width/3)*2) + (size.width/6), position.y + 5);
M5.Lcd.setTextColor(BLACK);
M5.Lcd.drawString(btnCText.c_str(), ((size.width/3)*2) + (size.width/6), position.y + 5);

oldBtnCText = btnCText;
}
isUpdated = false;
isInvalidated = false;
}
3 changes: 3 additions & 0 deletions src/ButtonInfoBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ namespace Codingfield {
private:
Color color = WHITE;
std::string btnAText;
std::string oldBtnAText;
std::string btnBText;
std::string oldBtnBText;
std::string btnCText;
std::string oldBtnCText;
};
}
}
4 changes: 2 additions & 2 deletions src/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ void Screen::Draw() {
M5.Lcd.setTextSize(1);

if(IsHidden()) return;
if(isUpdated)
if(isInvalidated)
M5.Lcd.fillScreen(color);

for(Widget* w : children)
w->Draw();

isUpdated = false;
isInvalidated = false;
}
Loading

0 comments on commit 6485195

Please sign in to comment.