Skip to content

Commit

Permalink
Merge pull request #108 from pymuzard/calendar
Browse files Browse the repository at this point in the history
gestion Liste avec autoSelect
  • Loading branch information
paxo-rch authored Sep 11, 2024
2 parents ff66ce5 + 540c611 commit ac2562b
Show file tree
Hide file tree
Showing 39 changed files with 2,014 additions and 90 deletions.
10 changes: 5 additions & 5 deletions lib/applications/src/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void applications::launcher::init() {
}

void applications::launcher::update() {
std::cout << "Launcher update" << std::endl;
// std::cout << "Launcher update" << std::endl;

if (dirty) {
// If dirty, free to force redraw it
Expand All @@ -102,7 +102,7 @@ void applications::launcher::update() {
if (!allocated) {
// If launcher has been freed, redraw it
draw();
std::cout << "Launcher redraw" << std::endl;
//std::cout << "Launcher redraw" << std::endl;
}

// Update dynamic elements
Expand Down Expand Up @@ -225,7 +225,7 @@ void applications::launcher::draw() {
launcherWindow = std::make_shared<Window>();
}

std::cout << "launcher::update 1.1" << std::endl;
//std::cout << "launcher::update 1.1" << std::endl;

StandbyMode::triggerPower();

Expand All @@ -238,7 +238,7 @@ void applications::launcher::draw() {
launcherWindow->addChild(clockLabel);


std::cout << "launcher::update 1.2" << std::endl;
//std::cout << "launcher::update 1.2" << std::endl;

// Date
dateLabel = new Label(55, 89, 210, 18);
Expand All @@ -249,7 +249,7 @@ void applications::launcher::draw() {
launcherWindow->addChild(dateLabel);


std::cout << "launcher::update 1.3" << std::endl;
// std::cout << "launcher::update 1.3" << std::endl;

// Battery icon
const auto batteryIconDarkPath = storage::Path("system/icons/dark/" + getBatteryIconFilename() + "_64px.png");
Expand Down
4 changes: 2 additions & 2 deletions lib/gsm/src/gsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ namespace GSM

int getNetworkStatus()
{
std::cout << "networkQuality: " << networkQuality << std::endl;
// std::cout << "networkQuality: " << networkQuality << std::endl;
return networkQuality;
}

Expand All @@ -1125,7 +1125,7 @@ namespace GSM
{
networkQuality = atoi(o.substr(o.find("+CSQ: ") + 5, o.find(",") - o.find("+CSQ: ") - 5).c_str());
}
std::cout << "networkQuality: " << networkQuality << std::endl;
//std::cout << "networkQuality: " << networkQuality << std::endl;
}

void getNetworkQuality()
Expand Down
10 changes: 10 additions & 0 deletions lib/gui/src/ElementBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,13 @@ std::shared_ptr<graphics::Surface> gui::ElementBase::getSurface() {
void gui::ElementBase::forceUpdate() {
localGraphicalUpdate();
}


gui::ElementBase *gui::ElementBase::getElementAt(int index) {

if (index >=0 && index < m_children.size()) {
return m_children[index];
}
return nullptr;

}
2 changes: 2 additions & 0 deletions lib/gui/src/ElementBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ namespace gui
ElementBase *getParent() const;
void addChild(ElementBase *child);

ElementBase *getElementAt(int index);

ElementBase *m_parent;
std::vector<ElementBase *> m_children;
static int16_t touchX, touchY;
Expand Down
9 changes: 9 additions & 0 deletions lib/gui/src/elements/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,13 @@ namespace gui::elements
m_surface = gui::ImagesList::loadImage(this->m_path, this->m_width, this->m_height, background);
localGraphicalUpdate();
}

void Image::setTransparentColor(color_t color){
if ( ! m_surface) {
//std::cout << "[Image] m_surface is null";
load(color);
}
m_surface->setTransparentColor(color);
m_surface->setTransparency(true);
}
}
1 change: 1 addition & 0 deletions lib/gui/src/elements/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace gui::elements
void render() override;

void load(color_t background = COLOR_WHITE);
void setTransparentColor(color_t color);

private:
storage::Path m_path;
Expand Down
70 changes: 63 additions & 7 deletions lib/gui/src/elements/List.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace gui::elements
m_lineSpace = 25;
m_verticalScrollEnabled = true;
m_hasEvents = true;
m_selectionFocus == SelectionFocus::UP;
m_selectionFocus = SelectionFocus::UP;
m_selectionColor = COLOR_LIGHT_GREY;
m_autoSelect = false;
}

VerticalList::~VerticalList() = default;
Expand Down Expand Up @@ -41,21 +43,65 @@ namespace gui::elements
void VerticalList::setIndex(int index)
{
if(m_focusedIndex >= 0 && m_focusedIndex < m_children.size())
{
if (m_autoSelect) {
select(index);
}
else {
m_focusedIndex = index;
updateFocusedIndex();
}
}

}

void VerticalList::setIsSelected(bool selected) {
isSelected = selected;
}

bool VerticalList::getIsSelected() {
return isSelected;
}


void VerticalList::select(int index)
{
if(index >= 0 && index < m_children.size())
{
m_focusedIndex = index;
ElementBase *oldSelection = this->getElementAt(m_oldFocusedIndex);
if (oldSelection != nullptr)
oldSelection->setBackgroundColor(m_backgroundColor);

ElementBase *selection = this->getElementAt(index);
if (selection != nullptr)
selection->setBackgroundColor(m_selectionColor);

m_oldFocusedIndex = m_focusedIndex;
setIsSelected(true);

updateFocusedIndex();
}
}

void VerticalList::setSelectionColor(color_t color){
m_selectionColor = color;
}

void VerticalList::setSpaceLine(uint16_t y)
{
m_lineSpace = y;
}

void VerticalList::setAutoSelect(bool autoSelect) {
m_autoSelect = autoSelect;
}


void VerticalList::updateFocusedIndex()
{
eventHandlerApp.setTimeout(new Callback<>([&](){
std::cout << "updateFocusedIndex" << std::endl;
//std::cout << "updateFocusedIndex" << std::endl;
if(m_children.size() == 0)
{
m_focusedIndex = 0;
Expand All @@ -67,7 +113,7 @@ namespace gui::elements
m_verticalScroll = m_verticalScroll - getHeight() / 2 + m_children[m_focusedIndex]->getHeight() / 2;

localGraphicalUpdate();
std::cout << "updateFocusedIndex end: " << m_selectionFocus << std::endl;
//std::cout << "updateFocusedIndex end: " << m_selectionFocus << std::endl;

// for (int i = 0; i < m_children.size(); i++)
// {
Expand All @@ -83,17 +129,27 @@ namespace gui::elements
{
if(m_focusedIndex != 0)
{
m_focusedIndex--;
updateFocusedIndex();
if (m_autoSelect) {
select(m_focusedIndex - 1);
}
else {
m_focusedIndex--;
updateFocusedIndex();
}
}
}

void VerticalList::onScrollDown()
{
if(m_focusedIndex+1 != m_children.size())
{
m_focusedIndex++;
updateFocusedIndex();
if (m_autoSelect) {
select(m_focusedIndex + 1);
}
else {
m_focusedIndex++;
updateFocusedIndex();
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions lib/gui/src/elements/List.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,25 @@ namespace gui::elements

void setSelectionFocus(SelectionFocus focus);
int getFocusedElement();
void select(int index);
void setSelectionColor(color_t color);
void setAutoSelect(bool autoSelect);
void setIsSelected(bool autoSelect);
bool getIsSelected();

//virtual void onSelect() {}


private:
int16_t m_focusedIndex = 0;
int16_t m_oldFocusedIndex = 0;

uint16_t m_lineSpace = 0;
SelectionFocus m_selectionFocus = SelectionFocus::UP;
color_t m_selectionColor;
bool m_autoSelect;
bool isSelected = false;

};

class HorizontalList final : public ElementBase
Expand Down
66 changes: 54 additions & 12 deletions lib/lua/src/lua_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,21 @@ int custom_panic_handler(lua_State* L) {
std::string tableToString(const sol::table& table) {
std::stringstream ss;
ss << "{";
bool first = true;

int size = 0;
for (const auto& pair : table) { size++;}

int i=0;
for (const auto& pair : table) {
if (pair.first.is<std::string>()) {
ss << "[\"" << pair.first.as<std::string>() << "\"]";
} else { // Assuming it's an identifier
ss << pair.first.as<std::string>();
} else if(pair.first.is<int>()) {
ss << "[" <<pair.first.as<int>()<< "]";
}

else { // Assuming it's an identifier
ss << "[\"" << pair.first.as<std::string>() << "\"]";
}
i++;
ss << "=";

// Handle different value types carefully
Expand All @@ -143,7 +149,8 @@ std::string tableToString(const sol::table& table) {

//std::cout << std::endl;

ss << ", ";
// if (size != i)
ss << ", ";
}

ss << "}";
Expand All @@ -163,8 +170,19 @@ void save_lua_table(sol::state& lua, const std::string& path, sol::table table)
}

std::cout << tableToString(table) << std::endl;

file << tableToString(table);
try{
file << tableToString(table);
}
catch (const sol::error& e) {
// Handle Solidity specific errors
std::cerr << "Sol error: " << e.what() << std::endl;
} catch (const std::exception& e) {
// Handle other standard exceptions
std::cerr << "Standard error: " << e.what() << std::endl;
} catch (...) {
// Handle any other unknown exceptions
std::cerr << "Unknown error" << std::endl;
}
file.close();
}

Expand All @@ -179,13 +197,25 @@ sol::table load_lua_table(sol::state& lua, const std::string& path) {
std::stringstream content;
content << file.rdbuf();

lua.script("returntable=" + content.str());
sol::table resultTable;
try {
lua.script("returntable=" + content.str());
std::string tableName = "returntable"; // Adjust if your table has a different name
// Retrieve the created table from the Lua state
resultTable= lua[tableName];
}
catch (const sol::error& e) {
// Handle Solidity specific errors
std::cerr << "Sol error on table serialisation" << e.what() << std::endl;
} catch (const std::exception& e) {
// Handle other standard exceptions
std::cerr << "Error: " << e.what() << std::endl;
} catch (...) {
// Handle any other unknown exceptions
std::cerr << "Unknown error" << std::endl;
}

// Get the global table name (assuming the string defines a table named 'resultTable')
std::string tableName = "returntable"; // Adjust if your table has a different name

// Retrieve the created table from the Lua state
sol::table resultTable = lua[tableName];

return resultTable;
}
Expand Down Expand Up @@ -304,6 +334,7 @@ void LuaFile::load()
"get_int", &LuaJson::get_int,
"get_double", &LuaJson::get_double,
"get_bool", &LuaJson::get_bool,
"get_string", &LuaJson::get_string,
"set_int", &LuaJson::set_int,
"set_double", &LuaJson::set_double,
"set_bool", &LuaJson::set_bool,
Expand Down Expand Up @@ -348,6 +379,7 @@ void LuaFile::load()
"checkbox", &LuaGui::checkbox,
"del", &LuaGui::del,
"setWindow", &LuaGui::setMainWindow,
"getWindow", &LuaGui::getMainWindow,
"keyboard", &LuaGui::keyboard,
"showInfoMessage", &LuaGui::showInfoMessage,
"showWarningMessage", &LuaGui::showWarningMessage,
Expand Down Expand Up @@ -408,6 +440,8 @@ void LuaFile::load()
sol::base_classes, sol::bases<LuaWidget>());

lua.new_usertype<LuaImage>("LuaImage",
"setTransparentColor", &LuaImage::setTransparentColor,

sol::base_classes, sol::bases<LuaWidget>());

lua.new_usertype<LuaLabel>("LuaLabel",
Expand Down Expand Up @@ -456,12 +490,20 @@ void LuaFile::load()
"setSpaceLine", &LuaVerticalList::setSpaceLine,
"setSelectionFocus", &LuaVerticalList::setFocus,
"getSelected", &LuaVerticalList::getSelected,
"select", &LuaVerticalList::select,
"setSelectionColor", &LuaVerticalList::setSelectionColor,
"setAutoSelect", &LuaVerticalList::setAutoSelect,
"onSelect", &LuaVerticalList::onSelect,
sol::base_classes, sol::bases<LuaWidget>());

lua.new_usertype<LuaHorizontalList>("LuaHList",
//"add", &LuaHorizontalList::add,
"setSpaceLine", &LuaHorizontalList::setSpaceLine,
sol::base_classes, sol::bases<LuaWidget>());

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

lua.set("LEFT_ALIGNMENT", Label::Alignement::LEFT);
lua.set("RIGHT_ALIGNMENT", Label::Alignement::RIGHT);
lua.set("CENTER_ALIGNMENT", Label::Alignement::CENTER);
Expand Down
Loading

0 comments on commit ac2562b

Please sign in to comment.