2022-05-03 11:23:32 +02:00
|
|
|
/**
|
|
|
|
* @author Christian Burger (christian@krikkel.de)
|
|
|
|
*/
|
|
|
|
|
2022-05-06 22:42:09 +02:00
|
|
|
#include <kNCurses/VerticalTilingWindowManager.hpp>
|
|
|
|
#include <kNCurses/Window.hpp>
|
2022-05-03 11:23:32 +02:00
|
|
|
#include <ncursesw/ncurses.h>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace krikkel::NCurses
|
|
|
|
{
|
|
|
|
using std::list;
|
2022-05-06 14:02:18 +02:00
|
|
|
using std::recursive_mutex;
|
2022-05-06 18:37:48 +02:00
|
|
|
using std::scoped_lock;
|
2022-05-03 11:23:32 +02:00
|
|
|
|
2022-05-08 20:57:48 +02:00
|
|
|
VerticalTilingWindowManager::VerticalTilingWindowManager(NCursesWindow *rootWindow, std::recursive_mutex *ncursesMutex)
|
|
|
|
: TilingWindowManager(rootWindow, ncursesMutex)
|
2022-05-03 11:23:32 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
void VerticalTilingWindowManager::updateLayout()
|
|
|
|
{
|
2022-05-06 22:15:34 +02:00
|
|
|
size_t stackSize = visibleStack.size();
|
|
|
|
if(stackSize == 0)
|
|
|
|
{
|
|
|
|
rootWindow->clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-06 18:37:48 +02:00
|
|
|
scoped_lock lock(*ncursesMutex);
|
2022-05-03 11:23:32 +02:00
|
|
|
int availableWidth = rootWindow->width();
|
|
|
|
int availableHeight = rootWindow->height();
|
2022-05-06 14:02:18 +02:00
|
|
|
int windowHeight = availableHeight / stackSize - 1;
|
|
|
|
|
|
|
|
if((windowHeight + 1) * stackSize < availableHeight)
|
2022-05-03 11:23:32 +02:00
|
|
|
++windowHeight;
|
|
|
|
|
|
|
|
uint16_t y = 0;
|
2022-05-06 14:02:18 +02:00
|
|
|
list<Window *>::iterator it = visibleStack.begin();
|
2022-05-03 11:23:32 +02:00
|
|
|
for(size_t index = 0
|
2022-05-06 14:02:18 +02:00
|
|
|
; index < visibleStack.size() - 1
|
2022-05-03 11:23:32 +02:00
|
|
|
; ++index)
|
|
|
|
{
|
2022-05-08 20:57:48 +02:00
|
|
|
resizeWindow(*it++, windowHeight, availableWidth, y, 0);
|
2022-05-03 11:23:32 +02:00
|
|
|
y += windowHeight;
|
|
|
|
{
|
|
|
|
rootWindow->move(y++, 0);
|
|
|
|
rootWindow->hline(availableWidth);
|
|
|
|
}
|
|
|
|
}
|
2022-05-08 20:57:48 +02:00
|
|
|
resizeWindow(*it, availableHeight - y, availableWidth, y, 0);
|
2022-05-03 11:23:32 +02:00
|
|
|
}
|
|
|
|
}
|