Skip to content

Commit

Permalink
fixed the bug in the menu
Browse files Browse the repository at this point in the history
fixed the bug in the menu where when you move your cursor past the limit of the max numbers of menu items displayed on one window, the program would crash
also fixed the checkbox element
  • Loading branch information
shaoxiongduan authored May 11, 2023
1 parent 8857444 commit 20d8b50
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
3 changes: 3 additions & 0 deletions firmware/calculator firmware v2.2/Checkbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ Checkbox::Checkbox(std::string name) {
this -> state = false;
this -> linkBool = nullptr;
this -> checkboxAni = 0;
this -> doTransition = false;
}

Checkbox::Checkbox(std::string name, bool* linkBool) {
this -> name = name;
this -> state = false;
this -> linkBool = linkBool;
this -> checkboxAni = 0;
this -> doTransition = false;
}

Checkbox::Checkbox(std::string name, int x, int y, bool* linkBool) {
Expand All @@ -21,6 +23,7 @@ Checkbox::Checkbox(std::string name, int x, int y, bool* linkBool) {
this -> state = false;
this -> linkBool = linkBool;
this -> checkboxAni = 0;
this -> doTransition = false;
}

void Checkbox::init() {
Expand Down
44 changes: 27 additions & 17 deletions firmware/calculator firmware v2.2/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void Menu::init() {

//this -> cursor.setX(this -> x);
//this -> cursor.setY(this -> y + 12);
for (int i = this -> menuPos, cnt = 0; cnt < int(this -> subElements.size()); i++, cnt++) {
for (int i = this -> menuPos, cnt = 0; cnt < int(this -> subElements.size()) && i < int(this -> subElements.size()); i++, cnt++) {
subElements[i] -> setX(this -> x);
subElements[i] -> setY(this -> targetY + cnt * 12 + 12);
this -> subElements[i] -> init();
Expand Down Expand Up @@ -82,6 +82,7 @@ void Menu::deactivate() {
void Menu::aniIn() {
Serial.println("anijoijiojonhohiiojoijooiohoughin");
insertAnimation(new Animation(this, INDENT, this -> activeX, this -> activeY, 500));
insertAnimation(new Animation(&(this -> scrollBar), INDENT, this -> targetX + this -> width - 6, this -> targetY + 5 + (float(getMenuPos()) / float(this -> getSize()) * (this -> height - 10)), 500));
//insertAnimation(new Animation(this -> scrollBar, this -> targetX + this -> width - 6, ));
for (int cnt = 0; cnt < int(this -> subElements.size()); cnt++) {
insertAnimation(new Animation(subElements[cnt], INDENT, this -> targetX + 5, this -> targetY + (cnt - this -> menuPos) * 12 + 12, 500));
Expand All @@ -101,6 +102,8 @@ void Menu::aniOut() {
if (this -> getSize() != 0) {
this -> cursor.changeTarget(subElements[this -> cursorPos + this -> menuPos], 500);
}
insertAnimation(new Animation(&(this -> scrollBar), INDENTINV, this -> targetX + this -> width - 6, this -> targetY + 5 + (float(getMenuPos()) / float(this -> getSize()) * (this -> height - 10)), 500));
insertTmpAnimationPointer(&(this -> scrollBar));
}

void Menu::insertElement(UIElement* targetElement, UIElement* linkElement) {
Expand Down Expand Up @@ -184,8 +187,7 @@ int Menu::getMenuPos() {

void Menu::drawScrollBar() {
u8g2.drawLine(constrain(this -> x + this -> width - 5, 0, WIDTH), constrain(this -> y + 4, 0, HEIGHT), constrain(this -> x + this -> width - 5, 0, WIDTH), constrain(this -> y + this -> height - 4, 0, HEIGHT));
this -> scrollBar.setX(this -> x + this -> width - 6);
this -> scrollBar.setY(this -> y + 5 + (float(getMenuPos()) / float(this -> getSize()) * (this -> height - 10)));
//this -> scrollBar.setX(this -> x + this -> width - 6);
this -> scrollBar.draw();
//u8g2.drawBox(this -> x + this -> width - 6, this -> y + 5 + (float(getMenuPos()) / float(this -> getSize()) * (this -> height - 10)), 3, ((this -> height - 10) / this -> getSize()));
//insertAnimation(new Animation(&(this -> scrollBar), SMOOTH, this -> targetX + this -> width - 6, this -> y + 5 + (float(getMenuPos()) / float(this -> getSize()) * (this -> height - 10)), 100));
Expand Down Expand Up @@ -213,24 +215,30 @@ void Menu::clear() {
void Menu::enter() {
if (this -> linkElements[this -> menuPos + this -> cursorPos] != nullptr && this -> linkElements[this -> menuPos + this -> cursorPos] != this) {

aniOut();
while (!tmpAnimationUI.empty()) {
u8g2.clearBuffer();
Serial.println("fdidfiongernooie");
//kb.update();
//drawSidebar();
//kb.printKeys();
//macroPad.update();
currentElement -> draw();
updateTmp();
//Serial.println("hello");
//displayTime();
u8g2.sendBuffer();
animateAll();
if (this -> linkElements[this -> menuPos + this -> cursorPos] -> isTransition()) {
aniOut();
while (!tmpAnimationUI.empty()) {
u8g2.clearBuffer();
Serial.println("fdidfiongernooie");
//kb.update();
//drawSidebar();
//kb.printKeys();
//macroPad.update();
currentElement -> draw();
updateTmp();
//Serial.println("hello");
//displayTime();
u8g2.sendBuffer();
animateAll();
}
}
Serial.println("enterrrrr");
this -> deactivate();
Serial.println("enterrrrr");
this -> linkElements[this -> menuPos + this -> cursorPos] -> init();
Serial.println("enterrrrr");
this -> linkElements[this -> menuPos + this -> cursorPos] -> activate();
Serial.println("enterrrrr");
}
}

Expand Down Expand Up @@ -269,7 +277,9 @@ void Menu::update() {
}
if (kb.getRisingEdgeKey() == std::make_pair(0, 0) && this -> parentElement != this && this -> parentElement != nullptr) {
aniOut();

while (!tmpAnimationUI.empty()) {
this -> scrollBar.setY(this -> y + 5 + (float(getMenuPos()) / float(this -> getSize()) * (this -> height - 10)));
u8g2.clearBuffer();
currentElement -> draw();
updateTmp();
Expand Down
10 changes: 10 additions & 0 deletions firmware/calculator firmware v2.2/StopwatchUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ StopwatchUI::StopwatchUI(int x, int y, int width, int height, Menu* lapMenu) : U

void StopwatchUI::init() {
this -> lapMenu -> init();
this -> lapMenu -> activate();
}

void StopwatchUI::activate() {
Expand Down Expand Up @@ -60,6 +61,15 @@ void StopwatchUI::update() {
}
}
if (kb.getRisingEdgeKey() == std::make_pair(0, 0)) {
this -> lapMenu -> aniOut();
Serial.println("goback2");
while (!tmpAnimationUI.empty()) {
u8g2.clearBuffer();
currentElement -> draw();
updateTmp();
u8g2.sendBuffer();
animateAll();
}
goBack();
}
}
15 changes: 15 additions & 0 deletions firmware/calculator firmware v2.2/UIElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ UIElement::UIElement() {
this -> height = this -> targetHeight = 0;
this -> parentElement = nullptr;
this -> drawParent = false;
this -> doTransition = true;
}

UIElement::UIElement(int x, int y) {
Expand All @@ -16,6 +17,7 @@ UIElement::UIElement(int x, int y) {
this -> height = this -> targetHeight = 0;
this -> parentElement = nullptr;
this -> drawParent = false;
this -> doTransition = true;
}

UIElement::UIElement(int x, int y, int width, int height) {
Expand All @@ -25,6 +27,7 @@ UIElement::UIElement(int x, int y, int width, int height) {
this -> height = this -> targetHeight = height;
this -> parentElement = nullptr;
this -> drawParent = false;
this -> doTransition = true;
}

UIElement::UIElement(int x, int y, int width, int height, std::vector <UIElement*> subElements) {
Expand All @@ -35,6 +38,7 @@ UIElement::UIElement(int x, int y, int width, int height, std::vector <UIElement
this -> subElements = subElements;
this -> parentElement = nullptr;
this -> drawParent = false;
this -> doTransition = true;
}

UIElement::UIElement(int x, int y, bool drawParent) {
Expand All @@ -44,6 +48,7 @@ UIElement::UIElement(int x, int y, bool drawParent) {
this -> height = this -> targetHeight = 0;
this -> parentElement = nullptr;
this -> drawParent = drawParent;
this -> doTransition = true;
}

UIElement::UIElement(int x, int y, int width, int height, bool drawParent) {
Expand All @@ -53,6 +58,7 @@ UIElement::UIElement(int x, int y, int width, int height, bool drawParent) {
this -> height = this -> targetHeight = height;
this -> parentElement = nullptr;
this -> drawParent = drawParent;
this -> doTransition = true;
}

UIElement::UIElement(int x, int y, int width, int height, std::vector <UIElement*> subElements, bool drawParent) {
Expand All @@ -63,6 +69,7 @@ UIElement::UIElement(int x, int y, int width, int height, std::vector <UIElement
this -> subElements = subElements;
this -> parentElement = nullptr;
this -> drawParent = drawParent;
this -> doTransition = true;
}

void UIElement::init() {
Expand Down Expand Up @@ -113,6 +120,14 @@ int UIElement::getHeight() {
return this -> height;
}

bool UIElement::getDrawParent() {
return this -> drawParent;
}

bool UIElement::isTransition() {
return this -> doTransition;
}

int UIElement::getTargetWidth() {
return this -> targetWidth;
}
Expand Down
6 changes: 5 additions & 1 deletion firmware/calculator firmware v2.2/UIElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class UIElement {

int getHeight();

bool getDrawParent();

bool isTransition();

int getTargetWidth();

int getTargetHeight();
Expand Down Expand Up @@ -83,7 +87,7 @@ class UIElement {
int width, height, targetWidth, targetHeight;
std::vector <UIElement*> subElements;
UIElement* parentElement;
bool drawParent;
bool drawParent, doTransition;
};

extern UIElement* currentElement;
Expand Down

0 comments on commit 20d8b50

Please sign in to comment.