63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
/**
|
|
* @author Christian Burger (christian@krikkel.de)
|
|
*/
|
|
|
|
#include <NCurses/VerticalTilingWindowManager.hpp>
|
|
#include <NCurses/Window.hpp>
|
|
#include <ncursesw/ncurses.h>
|
|
#include <algorithm>
|
|
|
|
namespace krikkel::NCurses
|
|
{
|
|
using std::list;
|
|
using std::mutex;
|
|
using std::lock_guard;
|
|
using std::find;
|
|
|
|
VerticalTilingWindowManager::VerticalTilingWindowManager(NCursesWindow *rootWindow, mutex *ncursesMutex)
|
|
: rootWindow(rootWindow), ncursesMutex(ncursesMutex)
|
|
{}
|
|
|
|
void VerticalTilingWindowManager::addWindow(Window *window)
|
|
{
|
|
stack.push_back(window);
|
|
}
|
|
|
|
void VerticalTilingWindowManager::refresh()
|
|
{
|
|
rootWindow->refresh();
|
|
for(Window *window : stack)
|
|
window->refresh();
|
|
}
|
|
|
|
void VerticalTilingWindowManager::updateLayout()
|
|
{
|
|
int availableWidth = rootWindow->width();
|
|
int availableHeight = rootWindow->height();
|
|
int windowHeight = availableHeight / stack.size() - 1;
|
|
if((windowHeight + 1) * stack.size() < availableHeight)
|
|
++windowHeight;
|
|
|
|
list<Window *>::iterator it = stack.begin();
|
|
uint16_t y = 0;
|
|
for(size_t index = 0
|
|
; index < stack.size() - 1
|
|
; ++index)
|
|
{
|
|
resizeWindowInStack(*it++, y, windowHeight, availableWidth);
|
|
y += windowHeight;
|
|
{
|
|
lock_guard lock(*ncursesMutex);
|
|
rootWindow->move(y++, 0);
|
|
rootWindow->hline(availableWidth);
|
|
}
|
|
}
|
|
resizeWindowInStack(*it, y, availableHeight - y, availableWidth);
|
|
}
|
|
|
|
void VerticalTilingWindowManager::resizeWindowInStack(Window *window, uint16_t y, uint16_t height, uint16_t width)
|
|
{
|
|
window->resize(height, width);
|
|
window->mvwin(y, 0);
|
|
}
|
|
} |