git-svn-id: svn://db.shs.com.ru/pip@266 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2016-09-17 22:05:54 +00:00
parent 362c6bf505
commit be6aaf26a4
7 changed files with 54 additions and 12 deletions

View File

@@ -60,6 +60,7 @@ int main (int argc, char * argv[]) {
if (argc > 1) screen = new PIScreen(); if (argc > 1) screen = new PIScreen();
PITerminal term; PITerminal term;
TileTerminal tt(&term); TileTerminal tt(&term);
TileScrollBar * s = new TileScrollBar();
if (screen) { if (screen) {
screen->rootTile()->addTile(&tt); screen->rootTile()->addTile(&tt);
screen->rootTile()->addTile(&cout_tile); screen->rootTile()->addTile(&cout_tile);
@@ -74,6 +75,14 @@ int main (int argc, char * argv[]) {
if (screen) { if (screen) {
screen->start(); screen->start();
piMSleep(100); piMSleep(100);
piMSleep(200);
s->setValue(20);
piMSleep(200);
s->setValue(50);
piMSleep(200);
s->setValue(100);
//piCout << tt.width() << tt.height(); //piCout << tt.width() << tt.height();
term.resize(tt.width(), tt.height()); term.resize(tt.width(), tt.height());
screen->waitForFinish(); screen->waitForFinish();

View File

@@ -163,7 +163,7 @@ void PIScreenTile::layout() {
for (int i = 0; i < tiles.size_s(); ++i) { for (int i = 0; i < tiles.size_s(); ++i) {
PIScreenTile * t(tiles[i]); PIScreenTile * t(tiles[i]);
int cw(0), ch(0), cs(0); int cw(0), ch(0), cs(0);
if (t->visible) { if (t->visible && t->needLayout()) {
t->sizeHint(cw, ch); t->sizeHint(cw, ch);
cw = piClampi(cw, t->minimumWidth, t->maximumWidth); cw = piClampi(cw, t->minimumWidth, t->maximumWidth);
ch = piClampi(ch, t->minimumHeight, t->maximumHeight); ch = piClampi(ch, t->minimumHeight, t->maximumHeight);
@@ -190,7 +190,7 @@ void PIScreenTile::layout() {
asizes.fill(add_s); asizes.fill(add_s);
PISet<int> max_tl; PISet<int> max_tl;
for (int i = 0; i < tiles.size_s(); ++i) { 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; float maxs = (direction == Horizontal) ? tiles[i]->maximumWidth : tiles[i]->maximumHeight;
if (hints[i] + asizes[i] > maxs) { if (hints[i] + asizes[i] > maxs) {
max_tl << i; max_tl << i;
@@ -202,7 +202,7 @@ void PIScreenTile::layout() {
for (int j = 0; j < tiles.size_s(); ++j) { for (int j = 0; j < tiles.size_s(); ++j) {
if (i == j) continue; if (i == j) continue;
if (max_tl[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; asizes[j] += pas;
} }
} }
@@ -210,7 +210,7 @@ void PIScreenTile::layout() {
} }
} }
for (int i = 0; i < tiles.size_s(); ++i) { 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); int a = piRound(asizes[i] + add_da);
add_da += asizes[i] - a; add_da += asizes[i] - a;
hints[i] += a; hints[i] += a;
@@ -221,7 +221,7 @@ void PIScreenTile::layout() {
int cx = x_ + marginLeft, cy = y_ + marginTop; int cx = x_ + marginLeft, cy = y_ + marginTop;
for (int i = 0; i < tiles.size_s(); ++i) { for (int i = 0; i < tiles.size_s(); ++i) {
PIScreenTile * t(tiles[i]); PIScreenTile * t(tiles[i]);
if (!t->visible) continue; if (!t->visible || !t->needLayout()) continue;
t->x_ = cx; t->x_ = cx;
t->y_ = cy; t->y_ = cy;
if (direction == Horizontal) { if (direction == Horizontal) {

View File

@@ -82,6 +82,7 @@ protected:
void deleteChildren(); void deleteChildren();
void drawEventInternal(PIScreenDrawer * d); void drawEventInternal(PIScreenDrawer * d);
void layout(); void layout();
bool needLayout() {return size_policy != PIScreenTypes::Ignore;}
PIVector<PIScreenTile * > tiles; PIVector<PIScreenTile * > tiles;
PIScreenTile * parent; PIScreenTile * parent;

View File

@@ -105,8 +105,15 @@ void TileScrollBar::sizeHint(int & w, int & h) const {
void TileScrollBar::drawEvent(PIScreenDrawer * d) { void TileScrollBar::drawEvent(PIScreenDrawer * d) {
line_char = d->artChar(direction == Vertical ? PIScreenDrawer::LineVertical : PIScreenDrawer::LineHorizontal); line_char = d->artChar(direction == Vertical ? PIScreenDrawer::LineVertical : PIScreenDrawer::LineHorizontal);
d->fillRect(x_, y_, x_ + width_, y_ + height_, line_char, Green); d->fillRect(x_, y_, x_ + width_, y_ + height_, line_char, Green);
if () if (value_ >= minimum_ && value_ <= maximum_) {
d->drawPixel(cx, y_ + piRound(float(cur) / (content.size_s() - 1) * (lhei - 1)) + 1, ' ', Green, Green); 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; focus_flags = CanHasFocus | NextByArrowsHorizontal | NextByTab;
lhei = offset = cur = 0; lhei = offset = cur = 0;
selection_mode = NoSelection; 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) { void TileList::drawEvent(PIScreenDrawer * d) {
lhei = height_ - 2; lhei = height_ - 2;
//int osp = piMini(3, lhei / 4); //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); 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); d->drawLine(cx, y_ + 1, cx, y_ + height_ - 2, vert_line, Green);
if (content.size_s() > 1) if (content.size_s() > 1)
d->drawPixel(cx, y_ + piRound(float(cur) / (content.size_s() - 1) * (lhei - 1)) + 1, ' ', Green, Green); 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);*/
} }

View File

@@ -39,7 +39,10 @@ protected:
}; };
class TileList;
class PIP_EXPORT TileScrollBar: public PIScreenTile { class PIP_EXPORT TileScrollBar: public PIScreenTile {
friend class TileList;
public: public:
TileScrollBar(const PIString & n = PIString()); TileScrollBar(const PIString & n = PIString());
void setMinimum(int v); void setMinimum(int v);
@@ -61,6 +64,7 @@ protected:
class PIP_EXPORT TileList: public PIScreenTile { class PIP_EXPORT TileList: public PIScreenTile {
public: public:
TileList(const PIString & n = PIString()); TileList(const PIString & n = PIString());
~TileList();
enum SelectionMode { enum SelectionMode {
NoSelection, NoSelection,
SingleSelection, SingleSelection,
@@ -75,12 +79,13 @@ public:
PIScreenTypes::Alignment alignment; PIScreenTypes::Alignment alignment;
SelectionMode selection_mode; SelectionMode selection_mode;
PISet<int> selected; PISet<int> selected;
int cur, offset; int lhei, cur, offset;
protected: protected:
void sizeHint(int & w, int & h) const; void sizeHint(int & w, int & h) const;
void resizeEvent(int w, int h);
void drawEvent(PIScreenDrawer * d); void drawEvent(PIScreenDrawer * d);
bool keyEvent(PIKbdListener::KeyEvent key); bool keyEvent(PIKbdListener::KeyEvent key);
int lhei; TileScrollBar * scroll;
}; };

View File

@@ -62,7 +62,8 @@ namespace PIScreenTypes {
enum SizePolicy { enum SizePolicy {
Fixed /** Fixed size */ , Fixed /** Fixed size */ ,
Preferred /** Preferred size */ , Preferred /** Preferred size */ ,
Expanding /** Maximum available size */ Expanding /** Maximum available size */ ,
Ignore /** Ignore layout logic */
}; };
//! Direction //! Direction

View File

@@ -219,6 +219,7 @@ void FileManager::TileDir::resizeEvent(int w, int h) {
resized = true; resized = true;
buildNames(); buildNames();
resized = false; resized = false;
TileList::resizeEvent(w, h);
} }