Disable window drawing if the terminal is resized too small.

This commit is contained in:
casey 2016-07-18 01:34:06 -07:00
parent e7a7df22c3
commit c1b10a8d7c
5 changed files with 47 additions and 13 deletions

View File

@ -35,6 +35,7 @@
#include "stdafx.h"
#include <cursespp/App.h>
#include <cursespp/Screen.h>
#include <app/layout/ConsoleLayout.h>
#include <app/layout/LibraryLayout.h>
@ -58,6 +59,9 @@ using namespace musik::core::audio;
using namespace musik::box;
using namespace cursespp;
#define MIN_WIDTH 60
#define MIN_HEIGHT 14
#ifdef WIN32
int _main(int argc, _TCHAR* argv[]);
@ -79,7 +83,7 @@ int main(int argc, char* argv[])
#endif
#ifdef __PDCURSES__
PDC_set_resize_limits(12, 60, 60, 250);
PDC_set_resize_limits(MIN_HEIGHT, MIN_WIDTH, 60, 250);
resize_term(26, 100); /* must be before app init */
#endif
@ -124,7 +128,15 @@ int main(int argc, char* argv[])
});
app.SetResizeHandler([&]() {
mainLayout->Layout();
int cx = Screen::GetWidth();
int cy = Screen::GetHeight();
if (cx <= MIN_WIDTH || cy <= MIN_HEIGHT) {
Window::Freeze();
}
else {
Window::Unfreeze();
mainLayout->Layout();
}
});
app.Run(mainLayout);

View File

@ -113,17 +113,19 @@ void MainLayout::SetMainLayout(std::shared_ptr<cursespp::LayoutBase> layout) {
}
this->layout = layout;
this->topLevelLayout = dynamic_cast<ITopLevelLayout*>(layout.get());
this->shortcuts->RemoveAll();
if (this->topLevelLayout) {
this->topLevelLayout->SetShortcutsWindow(this->shortcuts.get());
}
this->AddWindow(layout);
this->layout->SetFocusOrder(0);
this->Show();
this->Layout();
if (this->layout) {
this->topLevelLayout = dynamic_cast<ITopLevelLayout*>(layout.get());
if (this->topLevelLayout) {
this->topLevelLayout->SetShortcutsWindow(this->shortcuts.get());
}
this->AddWindow(layout);
this->layout->SetFocusOrder(0);
this->Show();
this->Layout();
}
}
}

View File

@ -173,7 +173,10 @@ void App::Run(ILayoutPtr layout) {
resizeAt = App::Now() + REDRAW_DEBOUNCE_MS;
}
/* order: focused input, global key handler, then layout. */
else if (!this->state.input || !this->state.input->Write(kn)) {
else if (!this->state.input ||
!this->state.focused->IsVisible() ||
!this->state.input->Write(kn))
{
if (!keyHandler || !keyHandler(kn)) {
if (!this->state.keyHandler || !this->state.keyHandler->KeyPress(kn)) {
this->state.layout->KeyPress(kn);

View File

@ -44,9 +44,10 @@ using namespace cursespp;
static int NEXT_ID = 0;
static bool drawPending = false;
static bool freeze = false;
void Window::WriteToScreen(IInput* input) {
if (drawPending) {
if (drawPending && !freeze) {
drawPending = false;
update_panels();
@ -72,6 +73,20 @@ void Window::Invalidate() {
drawPending = true;
}
void Window::Freeze() {
if (!freeze) {
freeze = true;
Window::Invalidate();
}
}
void Window::Unfreeze() {
if (freeze) {
freeze = false;
Window::Invalidate();
}
}
Window::Window(IWindow *parent) {
this->frame = this->content = 0;
this->framePanel = this->contentPanel = 0;

View File

@ -88,6 +88,8 @@ namespace cursespp {
static void WriteToScreen(IInput* input);
static void Invalidate();
static void Freeze();
static void Unfreeze();
protected:
IWindow* GetParent() const;