Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard #114

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/graphics/src/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,18 @@ namespace graphics

void Surface::drawTextCentered(std::string &text, const int16_t x, const int16_t y, const uint16_t w, const uint16_t h, const bool horizontallyCentered, const bool verticallyCentered, const std::optional<color_t> color)
{
const uint16_t textWidth = m_sprite.textWidth(text.c_str());
// const uint16_t textWidth = m_sprite.textWidth(text.c_str());
const uint16_t textWidth = getTextWidth(text.c_str());

int16_t textPositionX;
if (horizontallyCentered)
{
if (w == (uint16_t)-1)
if (w == (uint16_t)-1) {
textPositionX = x + (double)this->getWidth() * 0.5 - (double)textWidth * 0.5;
else
}
else {
textPositionX = x + (double)w * 0.5 - (double)textWidth * 0.5;
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion lib/gui/src/elements/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace gui::ImagesList
if (img->surface.use_count() == 1)
{
img = images.erase(img);
std::cout << "[Image] image deleted" << std::endl;
//std::cout << "[Image] image deleted" << std::endl;
}
else
{
Expand Down
880 changes: 880 additions & 0 deletions lib/gui/src/elements/Keyboard2.cpp

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions lib/gui/src/elements/Keyboard2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
//
// Created by Charles on 13/03/2024.
//

#ifndef KEYBOARD2_HPP
#define KEYBOARD2_HPP

#include "../ElementBase.hpp"
#include "Box.hpp"
#include "Canvas.hpp"
#include "Filter.hpp"
#include "Image.hpp"
#include "Label.hpp"

namespace gui::elements {
class Keyboard2 final : public ElementBase {
public:

struct Coord {
int16_t row;
int16_t column;
};

explicit Keyboard2(const std::string &defaultText = "");

~Keyboard2() override;

void render() override;

void widgetUpdate() override;

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

/**
* @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;
std::string m_placeholder;
std::string m_defaultText;

Label *m_label;

bool m_exit = false;

uint8_t m_currentLayout;

char **m_layoutLowercase;
char **m_layoutUppercase;
char **m_layoutNumbers;

uint8_t m_caps;

Canvas *m_keysCanvas;

Image *m_capsIcon0;
Image *m_capsIcon1;
Image *m_capsIcon2;
Image *m_backspaceIcon;
Image *m_layoutIcon0;
Image *m_layoutIcon1;
Image *m_exitIcon;
Image *m_confirmIcon;
Image* m_trackpadActiveIcon;

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

Box* m_boxdKeyPressed_Left10;
Canvas *m_CanevasKeyPressed_Left10;
Box* m_boxdKeyPressed_Center10;
Canvas *m_CanevasKeyPressed_Center10;
Box* m_boxdKeyPressed_Right10;
Canvas *m_CanevasKeyPressed_Right10;
Box* m_boxdKeyPressed_Center9;
Canvas *m_CanevasKeyPressed_Center9;

uint8_t m_trackpadTicks;
int32_t m_trackpadLastDeltaX;

int32_t boxHeight;
int32_t hauteurKeyboard;
int32_t offsetBord;
float keyZoomRatio;
uint8_t hauteurRetourZoom;


uint8_t m_zoomKeyTicks;
Keyboard2::Coord oldCoord;
void drawZoomKeyLeft10 (uint16_t x, uint16_t y,uint16_t keyWidth , char key);
void drawZoomKeyCenter10 (uint16_t x, uint16_t y,uint16_t keyWidth , char key);
void drawZoomKeyRight10 (uint16_t x, uint16_t y,uint16_t keyWidth , char key);
void drawZoomKeyCenter9 (uint16_t x, uint16_t y,uint16_t keyWidth , char key);
Keyboard2::Coord getRowColumn(const int16_t x, const int16_t y) const;
void zoomKeyUpdate();
bool isZoomdActive() const;
void enableKeyZoom(uint16_t row, uint16_t column, char pressedKey);
void disableKeyZoom(uint16_t row, uint16_t column);

void drawKeys() const;

void drawKeyRow(int16_t y, const char *keys) const;

void drawKey(int16_t x, int16_t y, uint16_t w, char key) const;

void drawLastRow(const int16_t y) const;

[[nodiscard]] char getKey(int16_t x, int16_t y) const;

[[nodiscard]] uint8_t getKeyCol(const int16_t x, const uint8_t keyCount) const;


void processKey(char key);

void drawInputBox() const;

void updateCapsIcon() const;

void updateLayoutIcon() const;

[[nodiscard]] char **getLayoutCharMap() const;

void trackpadUpdate();

[[nodiscard]] bool isPointInTrackpad(int16_t x, int16_t y) const;

[[nodiscard]] bool isTrackpadActive() const;

void addChar(char value);

void removeChar();

};
} // gui::elements

#endif //Keyboard2_HPP
1 change: 1 addition & 0 deletions lib/gui/src/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "elements/Button.hpp"
#include "elements/Radio.hpp"
#include "elements/Keyboard.hpp"
#include "elements/Keyboard2.hpp"

#include "GuiManager.hpp"

Expand Down
35 changes: 35 additions & 0 deletions lib/lua/src/lua_file.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* @file lua_file.cpp
* @author your name ([email protected])
* @brief
* @version 0.1
* @date 2024-09-19
*
* @copyright Copyright (c) 2024
*
*/
#include "lua_file.hpp"

#include <gui.hpp>
Expand All @@ -10,6 +20,7 @@
#include <contacts.hpp>
#include <libsystem.hpp>
#include <standby.hpp>
#include <graphics.hpp>

#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -49,6 +60,12 @@ std::shared_ptr<LuaHttpClient> LuaNetwork::createHttpClient()
return std::make_shared<LuaHttpClient>(lua);
}*/

/**
* @brief Construct a new Lua File:: Lua File object
*
* @param filename
* @param manifest
*/
LuaFile::LuaFile(storage::Path filename, storage::Path manifest)
:lua_gui(this),
lua_storage(this),
Expand Down Expand Up @@ -103,6 +120,12 @@ int sol_exception_handler(lua_State* L, sol::optional<const std::exception&> may
return 0;
}

/**
* @brief
*
* @param L
* @return int
*/
int custom_panic_handler(lua_State* L) {
std::shared_ptr<AppManager::App> app = AppManager::get(L);

Expand Down Expand Up @@ -381,6 +404,15 @@ void LuaFile::load()
"setWindow", &LuaGui::setMainWindow,
"getWindow", &LuaGui::getMainWindow,
"keyboard", &LuaGui::keyboard,
"keyboard2", &LuaGui::keyboard2,
/*
"image", sol::overload(
[](LuaGui* gui, LuaWidget* parent, std::string path, int x, int y, int width, int height) -> LuaImage* {
return gui->image(parent, path, x, y, width, height, COLOR_WHITE);
},
&LuaGui::image
),
*/
"showInfoMessage", &LuaGui::showInfoMessage,
"showWarningMessage", &LuaGui::showWarningMessage,
"showErrorMessage", &LuaGui::showErrorMessage
Expand Down Expand Up @@ -502,6 +534,9 @@ void LuaFile::load()
"setSpaceLine", &LuaHorizontalList::setSpaceLine,
sol::base_classes, sol::bases<LuaWidget>());

lua.set("LANDSCAPE",graphics::LANDSCAPE);
lua.set("PORTRAIT",graphics::PORTRAIT);

lua.set("SELECTION_UP", VerticalList::SelectionFocus::UP);
lua.set("SELECTION_CENTER", VerticalList::SelectionFocus::CENTER);

Expand Down
31 changes: 31 additions & 0 deletions lib/lua/src/lua_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ LuaGui::~LuaGui()
}
}




LuaBox* LuaGui::box(LuaWidget* parent, int x, int y, int width, int height)
{
LuaBox* w = new LuaBox(parent, x, y, width, height);
Expand Down Expand Up @@ -176,6 +179,34 @@ std::string LuaGui::keyboard(const std::string& placeholder, const std::string&
return o;
}


std::string LuaGui::keyboard2(const std::string& placeholder, const std::string& defaultText, const int orientation)
{
// set keyboard to LANDSCAPE mode if set
if (orientation == graphics::LANDSCAPE) {
graphics::setScreenOrientation(graphics::LANDSCAPE);
}

auto key = new Keyboard2(defaultText);
key->setPlaceholder(placeholder);

while (!hardware::getHomeButton() && !key->quitting())
{
eventHandlerApp.update();
key->updateAll();
}

// set back to portrait when leaving keyboard
if (graphics::LANDSCAPE) {
graphics::setScreenOrientation(graphics::PORTRAIT);
}


std::string o = key->getText();

delete key;
return o;
}
void LuaGui::setMainWindow(LuaWindow* window) {
this->mainWindow = window;
AppManager::askGui(this->lua);
Expand Down
1 change: 1 addition & 0 deletions lib/lua/src/lua_gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LuaGui
LuaWindow* window();

std::string keyboard(const std::string& placeholder, const std::string& defaultText);
std::string keyboard2(const std::string& placeholder, const std::string& defaultText, const int screenOrientation);

void del(LuaWidget* widget);

Expand Down
2 changes: 1 addition & 1 deletion storage/apps/alarme/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ end

function changeName(label)

local keyboard = gui:keyboard("Placeholder", label:getText())
local keyboard = gui:keyboard2("Placeholder", label:getText(), LANDSCAPE)
label:setText(keyboard)
end

Expand Down
Binary file added storage/system/keyboard2/backspace_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/keyboard2/caps_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/keyboard2/caps_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.
Binary file added storage/system/keyboard2/caps_icon_2.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/keyboard2/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/keyboard2/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/keyboard2/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/keyboard2/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.
Binary file added storage/system/keyboard2/trackpad_active_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading