kNCurses/HorizontalTilingWindowManager.cpp

52 lines
1.5 KiB
C++
Raw Normal View History

/**
* @author Christian Burger (christian@krikkel.de)
*/
#include <kNCurses/HorizontalTilingWindowManager.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;
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<Window *>::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);
}
}