kNCurses/VerticalTilingWindowManager.cpp
Christian Burger a801752620 added class HorizontalTilingWindowManager
Just some minor changes to
`VerticalTilingWindowManager`. Not part of the
demo, yet.
2022-05-08 21:12:06 +02:00

52 lines
1.5 KiB
C++

/**
* @author Christian Burger (christian@krikkel.de)
*/
#include <kNCurses/VerticalTilingWindowManager.hpp>
#include <kNCurses/Window.hpp>
#include <ncursesw/ncurses.h>
#include <algorithm>
namespace krikkel::NCurses
{
using std::list;
using std::recursive_mutex;
using std::scoped_lock;
VerticalTilingWindowManager::VerticalTilingWindowManager(NCursesWindow *rootWindow, std::recursive_mutex *ncursesMutex)
: TilingWindowManager(rootWindow, ncursesMutex)
{}
void VerticalTilingWindowManager::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 windowHeight = availableHeight / stackSize - 1;
if((windowHeight + 1) * stackSize < availableHeight)
++windowHeight;
uint16_t y = 0;
list<Window *>::iterator it = visibleStack.begin();
for(size_t index = 0
; index < visibleStack.size() - 1
; ++index)
{
resizeWindow(*it++, windowHeight, availableWidth, y, 0);
y += windowHeight;
{
rootWindow->move(y++, 0);
rootWindow->hline(availableWidth);
}
}
resizeWindow(*it, availableHeight - y, availableWidth, y, 0);
}
}