changes to the menu map

This commit is contained in:
2026-06-08 00:01:43 -06:00
parent d5841c264d
commit da7c9ef3db
2 changed files with 18 additions and 16 deletions
+13 -10
View File
@@ -5,7 +5,10 @@
namespace ckitty::terminal { namespace ckitty::terminal {
MenuMap::MenuMap(int width, int height) 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) { void MenuMap::set(int x, int y, int id) {
@@ -40,7 +43,7 @@ namespace ckitty::terminal {
return { get(_cursorX, _cursorY), _cursorX, _cursorY }; return { get(_cursorX, _cursorY), _cursorX, _cursorY };
} }
std::optional<MenuMap::Result> MenuMap::findNext(int dx, int dy) { void MenuMap::findNext(int dx, int dy) {
int startX = _cursorX; int startX = _cursorX;
int startY = _cursorY; int startY = _cursorY;
int curX = _cursorX; int curX = _cursorX;
@@ -54,28 +57,28 @@ namespace ckitty::terminal {
if (_wrapX) { if (_wrapX) {
if (curX < 0) curX = _w - 1; if (curX < 0) curX = _w - 1;
else if (curX >= _w) curX = 0; 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 (_wrapY) {
if (curY < 0) curY = _h - 1; if (curY < 0) curY = _h - 1;
else if (curY >= _h) curY = 0; 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) // 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); int val = get(curX, curY);
if (val != 0 && val != get(startX, startY)) { if (val != 0 && val != get(startX, startY)) {
_cursorX = curX; _cursorX = curX;
_cursorY = curY; _cursorY = curY;
return Result{ val, curX, curY }; return;
} }
} }
} }
std::optional<MenuMap::Result> MenuMap::moveUp() { return findNext(0, -1); } void MenuMap::moveUp() { findNext(0, -1); }
std::optional<MenuMap::Result> MenuMap::moveDown() { return findNext(0, 1); } void MenuMap::moveDown() { findNext(0, 1); }
std::optional<MenuMap::Result> MenuMap::moveLeft() { return findNext(-1, 0); } void MenuMap::moveLeft() { findNext(-1, 0); }
std::optional<MenuMap::Result> MenuMap::moveRight() { return findNext(1, 0); } void MenuMap::moveRight() { findNext(1, 0); }
} }
+5 -6
View File
@@ -34,19 +34,18 @@ namespace ckitty::terminal {
void setWrap(bool x, bool y); void setWrap(bool x, bool y);
// Navigation - Returns the new ID if movement was successful // Navigation - Returns the new ID if movement was successful
std::optional<Result> moveUp(); void moveUp();
std::optional<Result> moveDown(); void moveDown();
std::optional<Result> moveLeft(); void moveLeft();
std::optional<Result> moveRight(); void moveRight();
// Cursor Management // Cursor Management
void setCursor(int x, int y); void setCursor(int x, int y);
Result getCursor() const; Result getCursor() const;
private: private:
// The core search engine // The core search engine
std::optional<Result> findNext(int dx, int dy); void findNext(int dx, int dy);
}; };
} }