kNCurses/VerticalTilingWindowManager.cpp
Christian Burger 0a086ff604 horizontal window manager now resizes correctly
Window managers are now descendants of windows instead of owning the
window in which they exist. This makes a clean window hierarchy.
2022-05-08 22:52:23 +02:00

53 lines
1.4 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()
{
scoped_lock lock(*ncursesMutex);
size_t stackSize = visibleStack.size();
if(stackSize == 0)
{
clear();
return;
}
int availableWidth = width();
int availableHeight = 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;
{
move(y++, 0);
hline(availableWidth);
}
}
resizeWindow(*it, availableHeight - y, availableWidth, y, 0);
}
}