diff --git a/src/desktoplib/terminal/ui/MenuMap.cpp b/src/desktoplib/terminal/ui/MenuMap.cpp index 9dddb41..5ab2404 100644 --- a/src/desktoplib/terminal/ui/MenuMap.cpp +++ b/src/desktoplib/terminal/ui/MenuMap.cpp @@ -5,7 +5,10 @@ namespace ckitty::terminal { MenuMap::MenuMap(int width, int height) - : _w(width), _h(height), _grid(size_t(width * height), 0) { + : _w(width), _h(height), + _cursorX(0), _cursorY(0), + _wrapX(false), _wrapY(false), + _grid(size_t(width * height), 0) { } void MenuMap::set(int x, int y, int id) { @@ -40,7 +43,7 @@ namespace ckitty::terminal { return { get(_cursorX, _cursorY), _cursorX, _cursorY }; } - std::optional MenuMap::findNext(int dx, int dy) { + void MenuMap::findNext(int dx, int dy) { int startX = _cursorX; int startY = _cursorY; int curX = _cursorX; @@ -54,28 +57,28 @@ namespace ckitty::terminal { if (_wrapX) { if (curX < 0) curX = _w - 1; else if (curX >= _w) curX = 0; - } else if (curX < 0 || curX >= _w) return std::nullopt; + } else if (curX < 0 || curX >= _w) return; if (_wrapY) { if (curY < 0) curY = _h - 1; else if (curY >= _h) curY = 0; - } else if (curY < 0 || curY >= _h) return std::nullopt; + } else if (curY < 0 || curY >= _h) return; // Check if we looped back to start (fail condition for wrap) - if (curX == startX && curY == startY) return std::nullopt; + if (curX == startX && curY == startY) return; int val = get(curX, curY); if (val != 0 && val != get(startX, startY)) { _cursorX = curX; _cursorY = curY; - return Result{ val, curX, curY }; + return; } } } - std::optional MenuMap::moveUp() { return findNext(0, -1); } - std::optional MenuMap::moveDown() { return findNext(0, 1); } - std::optional MenuMap::moveLeft() { return findNext(-1, 0); } - std::optional MenuMap::moveRight() { return findNext(1, 0); } + void MenuMap::moveUp() { findNext(0, -1); } + void MenuMap::moveDown() { findNext(0, 1); } + void MenuMap::moveLeft() { findNext(-1, 0); } + void MenuMap::moveRight() { findNext(1, 0); } } \ No newline at end of file diff --git a/src/desktoplib/terminal/ui/MenuMap.hpp b/src/desktoplib/terminal/ui/MenuMap.hpp index 67173f0..8e393e0 100644 --- a/src/desktoplib/terminal/ui/MenuMap.hpp +++ b/src/desktoplib/terminal/ui/MenuMap.hpp @@ -34,19 +34,18 @@ namespace ckitty::terminal { void setWrap(bool x, bool y); // Navigation - Returns the new ID if movement was successful - std::optional moveUp(); - std::optional moveDown(); - std::optional moveLeft(); - std::optional moveRight(); + void moveUp(); + void moveDown(); + void moveLeft(); + void moveRight(); // Cursor Management void setCursor(int x, int y); Result getCursor() const; private: - // The core search engine - std::optional findNext(int dx, int dy); + void findNext(int dx, int dy); }; } \ No newline at end of file