diff --git a/main.cpp b/main.cpp index 82be5c80..dd14b835 100644 --- a/main.cpp +++ b/main.cpp @@ -60,6 +60,7 @@ int main (int argc, char * argv[]) { if (argc > 1) screen = new PIScreen(); PITerminal term; TileTerminal tt(&term); + TileScrollBar * s = new TileScrollBar(); if (screen) { screen->rootTile()->addTile(&tt); screen->rootTile()->addTile(&cout_tile); @@ -74,6 +75,14 @@ int main (int argc, char * argv[]) { if (screen) { screen->start(); piMSleep(100); + + piMSleep(200); + s->setValue(20); + piMSleep(200); + s->setValue(50); + piMSleep(200); + s->setValue(100); + //piCout << tt.width() << tt.height(); term.resize(tt.width(), tt.height()); screen->waitForFinish(); diff --git a/src/console/piscreentile.cpp b/src/console/piscreentile.cpp index c0e697cd..203dafc0 100644 --- a/src/console/piscreentile.cpp +++ b/src/console/piscreentile.cpp @@ -163,7 +163,7 @@ void PIScreenTile::layout() { for (int i = 0; i < tiles.size_s(); ++i) { PIScreenTile * t(tiles[i]); int cw(0), ch(0), cs(0); - if (t->visible) { + if (t->visible && t->needLayout()) { t->sizeHint(cw, ch); cw = piClampi(cw, t->minimumWidth, t->maximumWidth); ch = piClampi(ch, t->minimumHeight, t->maximumHeight); @@ -190,7 +190,7 @@ void PIScreenTile::layout() { asizes.fill(add_s); PISet max_tl; for (int i = 0; i < tiles.size_s(); ++i) { - if (tiles[i]->size_policy == pol && tiles[i]->visible) { + if (tiles[i]->size_policy == pol && tiles[i]->visible && tiles[i]->needLayout()) { float maxs = (direction == Horizontal) ? tiles[i]->maximumWidth : tiles[i]->maximumHeight; if (hints[i] + asizes[i] > maxs) { max_tl << i; @@ -202,7 +202,7 @@ void PIScreenTile::layout() { for (int j = 0; j < tiles.size_s(); ++j) { if (i == j) continue; if (max_tl[j]) continue; - if (tiles[j]->size_policy == pol && tiles[j]->visible) + if (tiles[j]->size_policy == pol && tiles[j]->visible && tiles[j]->needLayout()) asizes[j] += pas; } } @@ -210,7 +210,7 @@ void PIScreenTile::layout() { } } for (int i = 0; i < tiles.size_s(); ++i) { - if (tiles[i]->size_policy == pol && tiles[i]->visible) { + if (tiles[i]->size_policy == pol && tiles[i]->visible && tiles[i]->needLayout()) { int a = piRound(asizes[i] + add_da); add_da += asizes[i] - a; hints[i] += a; @@ -221,7 +221,7 @@ void PIScreenTile::layout() { int cx = x_ + marginLeft, cy = y_ + marginTop; for (int i = 0; i < tiles.size_s(); ++i) { PIScreenTile * t(tiles[i]); - if (!t->visible) continue; + if (!t->visible || !t->needLayout()) continue; t->x_ = cx; t->y_ = cy; if (direction == Horizontal) { diff --git a/src/console/piscreentile.h b/src/console/piscreentile.h index 29421fe5..d33f3abe 100644 --- a/src/console/piscreentile.h +++ b/src/console/piscreentile.h @@ -82,6 +82,7 @@ protected: void deleteChildren(); void drawEventInternal(PIScreenDrawer * d); void layout(); + bool needLayout() {return size_policy != PIScreenTypes::Ignore;} PIVector tiles; PIScreenTile * parent; diff --git a/src/console/piscreentiles.cpp b/src/console/piscreentiles.cpp index bee4c78d..9b956283 100644 --- a/src/console/piscreentiles.cpp +++ b/src/console/piscreentiles.cpp @@ -105,8 +105,15 @@ void TileScrollBar::sizeHint(int & w, int & h) const { void TileScrollBar::drawEvent(PIScreenDrawer * d) { line_char = d->artChar(direction == Vertical ? PIScreenDrawer::LineVertical : PIScreenDrawer::LineHorizontal); d->fillRect(x_, y_, x_ + width_, y_ + height_, line_char, Green); - if () - d->drawPixel(cx, y_ + piRound(float(cur) / (content.size_s() - 1) * (lhei - 1)) + 1, ' ', Green, Green); + if (value_ >= minimum_ && value_ <= maximum_) { + if (direction == Vertical) { + int c = piRoundf((float(value_ - minimum_) / (maximum_ - minimum_)) * (height_ - 1)); + d->drawLine(x_, y_ + c, x_ + width_ - 1, y_ + c, ' ', Green, Green); + } else { + int c = piRoundf((float(value_ - minimum_) / (maximum_ - minimum_)) * (width_ - 1)); + d->drawLine(x_ + c, y_, x_ + c, y_ + height_ - 1, ' ', Green, Green); + } + } } @@ -117,6 +124,14 @@ TileList::TileList(const PIString & n): PIScreenTile(n) { focus_flags = CanHasFocus | NextByArrowsHorizontal | NextByTab; lhei = offset = cur = 0; selection_mode = NoSelection; + scroll = new TileScrollBar(); + scroll->size_policy = Ignore; + addTile(scroll); +} + + +TileList::~TileList() { + delete scroll; } @@ -128,6 +143,14 @@ void TileList::sizeHint(int & w, int & h) const { } +void TileList::resizeEvent(int w, int h) { + scroll->x_ = x_ + width_ - 1; + scroll->y_ = y_; + scroll->width_ = 1; + scroll->height_ = height_; +} + + void TileList::drawEvent(PIScreenDrawer * d) { lhei = height_ - 2; //int osp = piMini(3, lhei / 4); @@ -155,11 +178,13 @@ void TileList::drawEvent(PIScreenDrawer * d) { } d->drawText(rx, y_ + i - is + 1, r.first, cc, sel ? Blue : Default, cf); } - int cx = x_ + width_ - 1; + scroll->setMaximum(piMaxi(0, content.size_s() - 1)); + scroll->setValue(cur); + /*int cx = x_ + width_ - 1; d->drawLine(cx, y_ + 1, cx, y_ + height_ - 2, vert_line, Green); if (content.size_s() > 1) d->drawPixel(cx, y_ + piRound(float(cur) / (content.size_s() - 1) * (lhei - 1)) + 1, ' ', Green, Green); - if (ie < content.size_s()) d->drawText(x_, y_ + height_ - 1, PIString(" \\/ ").repeat(width_ / 4), Green, Default, Bold); + if (ie < content.size_s()) d->drawText(x_, y_ + height_ - 1, PIString(" \\/ ").repeat(width_ / 4), Green, Default, Bold);*/ } diff --git a/src/console/piscreentiles.h b/src/console/piscreentiles.h index ac90672a..6f0766ff 100644 --- a/src/console/piscreentiles.h +++ b/src/console/piscreentiles.h @@ -39,7 +39,10 @@ protected: }; +class TileList; + class PIP_EXPORT TileScrollBar: public PIScreenTile { + friend class TileList; public: TileScrollBar(const PIString & n = PIString()); void setMinimum(int v); @@ -61,6 +64,7 @@ protected: class PIP_EXPORT TileList: public PIScreenTile { public: TileList(const PIString & n = PIString()); + ~TileList(); enum SelectionMode { NoSelection, SingleSelection, @@ -75,12 +79,13 @@ public: PIScreenTypes::Alignment alignment; SelectionMode selection_mode; PISet selected; - int cur, offset; + int lhei, cur, offset; protected: void sizeHint(int & w, int & h) const; + void resizeEvent(int w, int h); void drawEvent(PIScreenDrawer * d); bool keyEvent(PIKbdListener::KeyEvent key); - int lhei; + TileScrollBar * scroll; }; diff --git a/src/console/piscreentypes.h b/src/console/piscreentypes.h index e2e878c2..eca3e573 100644 --- a/src/console/piscreentypes.h +++ b/src/console/piscreentypes.h @@ -62,7 +62,8 @@ namespace PIScreenTypes { enum SizePolicy { Fixed /** Fixed size */ , Preferred /** Preferred size */ , - Expanding /** Maximum available size */ + Expanding /** Maximum available size */ , + Ignore /** Ignore layout logic */ }; //! Direction diff --git a/utils/system_daemon/file_manager.cpp b/utils/system_daemon/file_manager.cpp index da3a9a20..8516b6ea 100644 --- a/utils/system_daemon/file_manager.cpp +++ b/utils/system_daemon/file_manager.cpp @@ -219,6 +219,7 @@ void FileManager::TileDir::resizeEvent(int w, int h) { resized = true; buildNames(); resized = false; + TileList::resizeEvent(w, h); }