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.
This commit is contained in:
parent
9ddb769cb4
commit
0a086ff604
13
DemoApp.cpp
13
DemoApp.cpp
|
@ -35,18 +35,19 @@ namespace krikkel::NCurses
|
|||
{
|
||||
windowManager
|
||||
= new VerticalTilingWindowManager(Root_Window, &ncursesMutex);
|
||||
topWindowManager
|
||||
= new HorizontalTilingWindowManager(new Window(), &ncursesMutex);
|
||||
|
||||
dummyWindowTop = new Window(windowManager);
|
||||
windowManager->addWindow(topWindowManager);
|
||||
ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0);
|
||||
windowManager->addWindow(ptyWindow);
|
||||
dummyWindowBottom = new Window(windowManager);
|
||||
windowManager->updateLayout();
|
||||
windowManager->refresh();
|
||||
|
||||
topWindowManager
|
||||
= new HorizontalTilingWindowManager(dummyWindowTop, &ncursesMutex);
|
||||
dummyWindowTopLeft = new Window(topWindowManager);
|
||||
dummyWindowTopRight = new Window(topWindowManager);
|
||||
|
||||
topWindowManager->updateLayout();
|
||||
topWindowManager->refresh();
|
||||
}
|
||||
|
@ -93,10 +94,10 @@ namespace krikkel::NCurses
|
|||
windowManager->updateLayout();
|
||||
break;
|
||||
case KEY_F(1):
|
||||
if(dummyWindowTop->isHidden())
|
||||
windowManager->showWindow(dummyWindowTop);
|
||||
if(topWindowManager->isHidden())
|
||||
windowManager->showWindow(topWindowManager);
|
||||
else
|
||||
windowManager->hideWindow(dummyWindowTop);
|
||||
windowManager->hideWindow(topWindowManager);
|
||||
windowManager->updateLayout();
|
||||
windowManager->refresh();
|
||||
break;
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace krikkel::NCurses
|
|||
private:
|
||||
VerticalTilingWindowManager *windowManager;
|
||||
HorizontalTilingWindowManager *topWindowManager;
|
||||
Window *dummyWindowTop, *dummyWindowBottom, *dummyWindowTopLeft,
|
||||
Window *dummyWindowBottom, *dummyWindowTopLeft,
|
||||
*dummyWindowTopRight;
|
||||
PtyWindow *ptyWindow;
|
||||
std::recursive_mutex ncursesMutex;
|
||||
|
|
|
@ -19,16 +19,17 @@ namespace krikkel::NCurses
|
|||
|
||||
void HorizontalTilingWindowManager::updateLayout()
|
||||
{
|
||||
scoped_lock lock(*ncursesMutex);
|
||||
|
||||
size_t stackSize = visibleStack.size();
|
||||
if(stackSize == 0)
|
||||
{
|
||||
rootWindow->clear();
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
scoped_lock lock(*ncursesMutex);
|
||||
int availableWidth = rootWindow->width();
|
||||
int availableHeight = rootWindow->height();
|
||||
int availableWidth = width();
|
||||
int availableHeight = height();
|
||||
int windowWidth = availableWidth / stackSize - 1;
|
||||
|
||||
if((windowWidth + 1) * stackSize < availableWidth)
|
||||
|
@ -43,8 +44,8 @@ namespace krikkel::NCurses
|
|||
resizeWindow(*it++, availableHeight, windowWidth, 0, x);
|
||||
x += windowWidth;
|
||||
{
|
||||
rootWindow->move(0, x++);
|
||||
rootWindow->vline(availableHeight);
|
||||
move(0, x++);
|
||||
vline(availableHeight);
|
||||
}
|
||||
}
|
||||
resizeWindow(*it, availableHeight, availableWidth - x, 0, x);
|
||||
|
|
|
@ -12,10 +12,9 @@ namespace krikkel::NCurses
|
|||
using std::list;
|
||||
using std::recursive_mutex;
|
||||
using std::scoped_lock;
|
||||
using std::find;
|
||||
|
||||
TilingWindowManager::TilingWindowManager(NCursesWindow *rootWindow, recursive_mutex *ncursesMutex)
|
||||
: rootWindow(new Window(*rootWindow)), ncursesMutex(ncursesMutex)
|
||||
: Window(*rootWindow), ncursesMutex(ncursesMutex)
|
||||
{}
|
||||
|
||||
void TilingWindowManager::addWindow(Window *window)
|
||||
|
@ -50,18 +49,29 @@ namespace krikkel::NCurses
|
|||
}
|
||||
}
|
||||
|
||||
void TilingWindowManager::refresh()
|
||||
int TilingWindowManager::resize(int rows, int cols)
|
||||
{
|
||||
int result = Window::resize(rows, cols);
|
||||
updateLayout();
|
||||
return result;
|
||||
}
|
||||
|
||||
int TilingWindowManager::refresh()
|
||||
{
|
||||
scoped_lock lock(*ncursesMutex);
|
||||
|
||||
rootWindow->refresh();
|
||||
int result = Window::refresh();
|
||||
|
||||
for(Window *window : visibleStack)
|
||||
// @todo there are return values; compound them?
|
||||
window->refresh();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
SingleUserInput TilingWindowManager::readSingleUserInput()
|
||||
{
|
||||
return rootWindow->readSingleUserInput();
|
||||
return Window::readSingleUserInput();
|
||||
}
|
||||
|
||||
void TilingWindowManager::resizeWindow(Window *window, uint16_t height, uint16_t width, uint16_t y, uint16_t x)
|
||||
|
|
|
@ -19,16 +19,17 @@ namespace krikkel::NCurses
|
|||
|
||||
void VerticalTilingWindowManager::updateLayout()
|
||||
{
|
||||
scoped_lock lock(*ncursesMutex);
|
||||
|
||||
size_t stackSize = visibleStack.size();
|
||||
if(stackSize == 0)
|
||||
{
|
||||
rootWindow->clear();
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
scoped_lock lock(*ncursesMutex);
|
||||
int availableWidth = rootWindow->width();
|
||||
int availableHeight = rootWindow->height();
|
||||
int availableWidth = width();
|
||||
int availableHeight = height();
|
||||
int windowHeight = availableHeight / stackSize - 1;
|
||||
|
||||
if((windowHeight + 1) * stackSize < availableHeight)
|
||||
|
@ -43,8 +44,8 @@ namespace krikkel::NCurses
|
|||
resizeWindow(*it++, windowHeight, availableWidth, y, 0);
|
||||
y += windowHeight;
|
||||
{
|
||||
rootWindow->move(y++, 0);
|
||||
rootWindow->hline(availableWidth);
|
||||
move(y++, 0);
|
||||
hline(availableWidth);
|
||||
}
|
||||
}
|
||||
resizeWindow(*it, availableHeight - y, availableWidth, y, 0);
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
namespace krikkel::NCurses
|
||||
{
|
||||
Window::Window() : NCursesWindow(0, 0, 0, 0)
|
||||
{}
|
||||
|
||||
Window::Window(TilingWindowManager *windowManager)
|
||||
: NCursesWindow(0, 0, 0, 0)
|
||||
{
|
||||
|
|
|
@ -6,21 +6,21 @@
|
|||
#ifndef C51BA18F_0915_43B9_BD5D_129F0CDBC1CD
|
||||
#define C51BA18F_0915_43B9_BD5D_129F0CDBC1CD
|
||||
|
||||
#include <ncursesw/cursesw.h>
|
||||
#include "Window.hpp"
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
|
||||
namespace krikkel::NCurses
|
||||
{
|
||||
class Window;
|
||||
class SingleUserInput;
|
||||
|
||||
class TilingWindowManager
|
||||
class TilingWindowManager : public Window
|
||||
{
|
||||
public:
|
||||
TilingWindowManager(NCursesWindow *rootWindow, std::recursive_mutex *ncursesMutex);
|
||||
void addWindow(Window *window);
|
||||
void refresh();
|
||||
int resize(int rows, int cols) override;
|
||||
int refresh() override;
|
||||
virtual void updateLayout() = 0;
|
||||
|
||||
void hideWindow(Window *window);
|
||||
|
@ -28,7 +28,6 @@ namespace krikkel::NCurses
|
|||
SingleUserInput readSingleUserInput();
|
||||
|
||||
protected:
|
||||
Window *rootWindow;
|
||||
std::recursive_mutex *ncursesMutex;
|
||||
std::list<Window *> stack, visibleStack;
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace krikkel::NCurses
|
|||
friend class TilingWindowManager;
|
||||
|
||||
public:
|
||||
Window();
|
||||
Window(TilingWindowManager *windowManager);
|
||||
Window(const NCursesWindow &window);
|
||||
Window(int lines, int columns, int y, int x);
|
||||
|
|
Loading…
Reference in a new issue