From a80175262022c4081351f87b6a762193b9db2b6d Mon Sep 17 00:00:00 2001 From: Christian Burger Date: Sun, 8 May 2022 21:12:06 +0200 Subject: [PATCH] added class `HorizontalTilingWindowManager` Just some minor changes to `VerticalTilingWindowManager`. Not part of the demo, yet. --- HorizontalTilingWindowManager.cpp | 52 +++++++++++++++++++ VerticalTilingWindowManager.cpp | 1 - .../HorizontalTilingWindowManager.hpp | 25 +++++++++ .../kNCurses/VerticalTilingWindowManager.hpp | 3 +- 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 HorizontalTilingWindowManager.cpp create mode 100644 include/kNCurses/HorizontalTilingWindowManager.hpp diff --git a/HorizontalTilingWindowManager.cpp b/HorizontalTilingWindowManager.cpp new file mode 100644 index 0000000..e055c73 --- /dev/null +++ b/HorizontalTilingWindowManager.cpp @@ -0,0 +1,52 @@ +/** + * @author Christian Burger (christian@krikkel.de) + */ + +#include +#include +#include +#include + +namespace krikkel::NCurses +{ + using std::list; + using std::recursive_mutex; + using std::scoped_lock; + + HorizontalTilingWindowManager::HorizontalTilingWindowManager(NCursesWindow *rootWindow, std::recursive_mutex *ncursesMutex) + : TilingWindowManager(rootWindow, ncursesMutex) + {} + + void HorizontalTilingWindowManager::updateLayout() + { + size_t stackSize = visibleStack.size(); + if(stackSize == 0) + { + rootWindow->clear(); + return; + } + + scoped_lock lock(*ncursesMutex); + int availableWidth = rootWindow->width(); + int availableHeight = rootWindow->height(); + int windowWidth = availableWidth / stackSize - 1; + + if((windowWidth + 1) * stackSize < availableWidth) + ++windowWidth; + + uint16_t x = 0; + list::iterator it = visibleStack.begin(); + for(size_t index = 0 + ; index < visibleStack.size() - 1 + ; ++index) + { + resizeWindow(*it++, availableHeight, windowWidth, 0, x); + x += windowWidth; + { + rootWindow->move(0, x++); + rootWindow->vline(availableHeight); + } + } + resizeWindow(*it, availableHeight, availableWidth - x, 0, x); + } +} \ No newline at end of file diff --git a/VerticalTilingWindowManager.cpp b/VerticalTilingWindowManager.cpp index abbd6fd..53a1348 100644 --- a/VerticalTilingWindowManager.cpp +++ b/VerticalTilingWindowManager.cpp @@ -12,7 +12,6 @@ namespace krikkel::NCurses using std::list; using std::recursive_mutex; using std::scoped_lock; - using std::find; VerticalTilingWindowManager::VerticalTilingWindowManager(NCursesWindow *rootWindow, std::recursive_mutex *ncursesMutex) : TilingWindowManager(rootWindow, ncursesMutex) diff --git a/include/kNCurses/HorizontalTilingWindowManager.hpp b/include/kNCurses/HorizontalTilingWindowManager.hpp new file mode 100644 index 0000000..739b0bb --- /dev/null +++ b/include/kNCurses/HorizontalTilingWindowManager.hpp @@ -0,0 +1,25 @@ +/** + * @brief Window manager + * @author Christian Burger (christian@krikkel.de) + */ + +#ifndef B7BCF793_2FAB_49CC_9E00_CDEA370D38F9 +#define B7BCF793_2FAB_49CC_9E00_CDEA370D38F9 + +#include "TilingWindowManager.hpp" + +namespace krikkel::NCurses +{ + class Window; + class SingleUserInput; + + class HorizontalTilingWindowManager : public TilingWindowManager + { + public: + HorizontalTilingWindowManager(NCursesWindow *rootWindow, std::recursive_mutex *ncursesMutex); + void updateLayout() override; + }; +} + + +#endif /* B7BCF793_2FAB_49CC_9E00_CDEA370D38F9 */ diff --git a/include/kNCurses/VerticalTilingWindowManager.hpp b/include/kNCurses/VerticalTilingWindowManager.hpp index f101b71..cb47abb 100644 --- a/include/kNCurses/VerticalTilingWindowManager.hpp +++ b/include/kNCurses/VerticalTilingWindowManager.hpp @@ -6,14 +6,13 @@ #ifndef C10F5DF3_1DB4_4714_A84D_115F492F5CDC #define C10F5DF3_1DB4_4714_A84D_115F492F5CDC -#include +#include "TilingWindowManager.hpp" namespace krikkel::NCurses { class Window; class SingleUserInput; - class VerticalTilingWindowManager : public TilingWindowManager { public: