Skip to content

Commit

Permalink
Refactor and enhance Keyboard widget
Browse files Browse the repository at this point in the history
Updated the Keyboard widget with various improvements including the addition of placeholder text, improved key detection, and changes to color and layout. Furthermore, old methods have been refactored to make them more efficient and maintainable. This commit also includes changes in lua_gui.cpp, lua_gui.hpp, Keyboard.cpp, and Keyboard.hpp files.
  • Loading branch information
Charles-Mahoudeau committed May 26, 2024
1 parent 247df08 commit 26bf724
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 163 deletions.
390 changes: 243 additions & 147 deletions lib/gui/src/elements/Keyboard.cpp

Large diffs are not rendered by default.

46 changes: 34 additions & 12 deletions lib/gui/src/elements/Keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../ElementBase.hpp"
#include "Box.hpp"
#include "Image.hpp"
#include "Label.hpp"

namespace gui::elements
{
Expand All @@ -18,21 +19,32 @@ namespace gui::elements
~Keyboard() override;

void render() override;
void onReleased() override;
void widgetUpdate() override;

/**
* Returns the content of the keyboard's input AND CLEARS IT.
* @return the content of the keyboard's input
*/
std::string getText();

bool quitting() {return quit;}
/**
* @deprecated Please use "hasExitKeyBeenPressed()"
*/
[[nodiscard]] bool quitting() const {return m_exit;}

[[nodiscard]] bool hasExitKeyBeenPressed() const;

void setPlaceholder(const std::string& placeholder);

private:
std::string m_buffer;
bool quit = false;
std::string m_placeholder;

Label* m_label;

char **m_currentLayout;
bool m_exit = false;

uint8_t m_currentLayout;

char **m_layoutLowercase;
char **m_layoutUppercase;
Expand All @@ -43,28 +55,38 @@ namespace gui::elements
Image* m_capsIcon0;
Image* m_capsIcon1;
Image* m_capsIcon2;

Image* m_backspaceIcon;
Image* m_layoutIcon0;
Image* m_layoutIcon1;
Image* m_exitIcon;
Image* m_confirmIcon;

Box* m_capsBox;
Box* m_layoutBox;
Box* m_backspaceBox;
Box* m_exitBox;
Box* m_confirmBox;

void drawKeys() const;
void drawKeyRow(int16_t y, uint8_t count, const char* keys) const;
void drawKey(int16_t x, int16_t y, uint16_t w, char key) const;

void drawKeys();
void drawKeyRow(int16_t y, uint8_t count, char* keys);
void drawKey(int16_t x, int16_t y, uint16_t w, char key);
void drawLastRow(int16_t x, int16_t y) const;

void drawLastRow(int16_t x, int16_t y);
char getKey(int16_t x, int16_t y) const;

char getKey(int16_t x, int16_t y);
uint8_t getKeyCol(int16_t x, uint8_t keyCount);
static uint8_t getKeyCol(int16_t x, uint8_t keyCount);

void processKey(char key);

void drawInputBox();
void drawInputBox() const;

void markDirty();

void updateCapsIcon() const;
void updateLayoutIcon() const;

char** getLayoutCharMap() const;
};
} // gui::elements

Expand Down
6 changes: 3 additions & 3 deletions lib/lua/src/lua_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ void LuaGui::update()
}
}

std::string LuaGui::keyboard(std::string placeholder)
std::string LuaGui::keyboard(const std::string& placeholder)
{
gui::elements::Window win;

graphics::setScreenOrientation(graphics::LANDSCAPE);
Keyboard key;


Keyboard key;
key.setPlaceholder(placeholder);

while (!hardware::getHomeButton() && !key.quitting())
{
Expand Down
2 changes: 1 addition & 1 deletion lib/lua/src/lua_gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LuaGui
LuaRadio* radio(LuaWidget* parent, int x, int y);
LuaWindow* window();

std::string keyboard(std::string placeholder);
std::string keyboard(const std::string& placeholder);

void del(LuaWidget* widget);

Expand Down
Binary file added storage/system/keyboard/confirm_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added storage/system/keyboard/exit_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added storage/system/keyboard/layout_icon_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added storage/system/keyboard/layout_icon_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 26bf724

Please sign in to comment.