From 34ed30fe1a710f6294e23003aa385bd6da6cb326 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 25 Nov 2023 18:20:02 +0100 Subject: Adds `linespacing()` to `Fl_Browser_` and all derived widgets --- src/Fl_Browser.cxx | 16 ++++++++-------- src/Fl_Browser_.cxx | 33 +++++++++++++++++---------------- src/Fl_Check_Browser.cxx | 3 ++- src/Fl_File_Browser.cxx | 28 +++++++++++++--------------- 4 files changed, 40 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/Fl_Browser.cxx b/src/Fl_Browser.cxx index e78ccee30..09f9c2d1c 100644 --- a/src/Fl_Browser.cxx +++ b/src/Fl_Browser.cxx @@ -208,7 +208,7 @@ FL_BLINE* Fl_Browser::_remove(int line) { cacheline = line-1; cache = ttt->prev; lines--; - full_height_ -= item_height(ttt); + full_height_ -= item_height(ttt) + linespacing(); if (ttt->prev) ttt->prev->next = ttt->next; else first = ttt->next; if (ttt->next) ttt->next->prev = ttt->prev; @@ -264,7 +264,7 @@ void Fl_Browser::insert(int line, FL_BLINE* item) { cacheline = line; cache = item; lines++; - full_height_ += item_height(item); + full_height_ += item_height(item) + linespacing(); redraw_line(item); } @@ -489,7 +489,7 @@ int Fl_Browser::full_height() const { incr_height(), full_height() */ int Fl_Browser::incr_height() const { - return textsize()+2; + return textsize() + 2 + linespacing(); } /** @@ -620,9 +620,9 @@ void Fl_Browser::lineposition(int line, Fl_Line_Position pos) { FL_BLINE* l; for (l=first; l && line>1; l = l->next) { - line--; p += item_height(l); + line--; p += item_height(l) + linespacing(); } - if (l && (pos == BOTTOM)) p += item_height (l); + if (l && (pos == BOTTOM)) p += item_height(l) + linespacing(); int final = p, X, Y, W, H; bbox(X, Y, W, H); @@ -670,7 +670,7 @@ void Fl_Browser::textsize(Fl_Fontsize newSize) { full_height_ = 0; if (lines == 0) return; for (FL_BLINE* itm=(FL_BLINE *)item_first(); itm; itm=(FL_BLINE *)item_next(itm)) { - full_height_ += item_height(itm); + full_height_ += item_height(itm) + linespacing(); } } @@ -769,7 +769,7 @@ void Fl_Browser::show(int line) { FL_BLINE* t = find_line(line); if (t->flags & NOTDISPLAYED) { t->flags &= ~NOTDISPLAYED; - full_height_ += item_height(t); + full_height_ += item_height(t) + linespacing(); if (Fl_Browser_::displayed(t)) redraw(); } } @@ -786,7 +786,7 @@ void Fl_Browser::show(int line) { void Fl_Browser::hide(int line) { FL_BLINE* t = find_line(line); if (!(t->flags & NOTDISPLAYED)) { - full_height_ -= item_height(t); + full_height_ -= item_height(t) + linespacing(); t->flags |= NOTDISPLAYED; if (Fl_Browser_::displayed(t)) redraw(); } diff --git a/src/Fl_Browser_.cxx b/src/Fl_Browser_.cxx index 55cab5a73..b05772aea 100644 --- a/src/Fl_Browser_.cxx +++ b/src/Fl_Browser_.cxx @@ -148,13 +148,13 @@ void Fl_Browser_::update_top() { offset_ = 0; real_position_ = 0; } else { - int hh = item_quick_height(l); + int hh = item_quick_height(l) + linespacing(); // step through list until we find line containing this point: while (ly > yy) { void* l1 = item_prev(l); if (!l1) {ly = 0; break;} // hit the top l = l1; - hh = item_quick_height(l); + hh = item_quick_height(l) + linespacing(); ly -= hh; } while ((ly+hh) <= yy) { @@ -162,16 +162,16 @@ void Fl_Browser_::update_top() { if (!l1) {yy = ly+hh-1; break;} l = l1; ly += hh; - hh = item_quick_height(l); + hh = item_quick_height(l) + linespacing(); } // top item must *really* be visible, use slow height: for (;;) { - hh = item_height(l); + hh = item_height(l) + linespacing(); if ((ly+hh) > yy) break; // it is big enough to see // go up to top of previous item: void* l1 = item_prev(l); if (!l1) {ly = yy = 0; break;} // hit the top - l = l1; yy = position_ = ly = ly-item_quick_height(l); + l = l1; yy = position_ = ly = ly-item_quick_height(l) + linespacing(); } // use it: top_ = l; @@ -229,7 +229,7 @@ int Fl_Browser_::displayed(void* item) const { int yy = H+offset_; for (void* l = top_; l && yy > 0; l = item_next(l)) { if (l == item) return 1; - yy -= item_height(l); + yy -= item_height(l) + linespacing(); } return 0; } @@ -257,7 +257,7 @@ void Fl_Browser_::display(void* item) { // 3rd special case - want to display item just above top of browser? void* lp = item_prev(l); - if (lp == item) { vposition(real_position_+Y-item_quick_height(lp)); return; } + if (lp == item) { vposition(real_position_+Y-item_quick_height(lp)-linespacing()); return; } #ifdef DISPLAY_SEARCH_BOTH_WAYS_AT_ONCE // search for item. We search both up and down the list at the same time, @@ -265,7 +265,7 @@ void Fl_Browser_::display(void* item) { // much slower for going up than for going down. while (l || lp) { if (l) { - h1 = item_quick_height(l); + h1 = item_quick_height(l) + linespacing(); if (l == item) { if (Y <= H) { // it is visible or right at bottom Y = Y+h1-H; // find where bottom edge is @@ -279,7 +279,7 @@ void Fl_Browser_::display(void* item) { l = item_next(l); } if (lp) { - h1 = item_quick_height(lp); + h1 = item_quick_height(lp) + linespacing(); Yp -= h1; if (lp == item) { if ((Yp + h1) >= 0) vposition(real_position_+Yp); @@ -294,7 +294,7 @@ void Fl_Browser_::display(void* item) { // search forward for it: l = top_; for (; l; l = item_next(l)) { - h1 = item_quick_height(l); + h1 = item_quick_height(l) + linespacing(); if (l == item) { if (Y <= H) { // it is visible or right at bottom Y = Y+h1-H; // find where bottom edge is @@ -310,7 +310,7 @@ void Fl_Browser_::display(void* item) { l = lp; Y = -offset_; for (; l; l = item_prev(l)) { - h1 = item_quick_height(l); + h1 = item_quick_height(l) + linespacing(); Y -= h1; if (l == item) { if ((Y + h1) >= 0) position(real_position_+Y); @@ -395,7 +395,7 @@ J1: void* l = top(); int yy = -offset_; for (; l && yy < H; l = item_next(l)) { - int hh = item_height(l); + int hh = item_height(l) + linespacing(); if (hh <= 0) continue; if ((damage()&(FL_DAMAGE_SCROLL|FL_DAMAGE_ALL)) || l == redraw1 || l == redraw2) { if (item_selected(l)) { @@ -448,7 +448,7 @@ J1: // update the scrollbars and redraw them: int scrollsize = scrollbar_size_ ? scrollbar_size_ : Fl::scrollbar_size(); - int dy = top_ ? item_quick_height(top_) : 0; if (dy < 10) dy = 10; + int dy = top_ ? item_quick_height(top_) + linespacing() : 0; if (dy < 10) dy = 10; if (scrollbar.visible()) { scrollbar.damage_resize( scrollbar.align()&FL_ALIGN_LEFT ? X-scrollsize : X+W, @@ -585,7 +585,7 @@ void* Fl_Browser_::find_item(int ypos) { int yy = Y-offset_; for (void *l = top_; l; l = item_next(l)) { int hh = item_height(l); if (hh <= 0) continue; - yy += hh; + yy += hh + linespacing(); if (ypos <= yy || yy>=(Y+H)) return l; } return 0; @@ -954,7 +954,8 @@ J1: Fl_Browser_::Fl_Browser_(int X, int Y, int W, int H, const char* L) : Fl_Group(X, Y, W, H, L), scrollbar(0, 0, 0, 0, 0), // they will be resized by draw() - hscrollbar(0, 0, 0, 0, 0) + hscrollbar(0, 0, 0, 0, 0), + linespacing_(0) { box(FL_NO_BOX); align(FL_ALIGN_BOTTOM); @@ -1053,7 +1054,7 @@ int Fl_Browser_::item_quick_height(void* item) const { \returns The average height of items, in pixels. */ int Fl_Browser_::incr_height() const { - return item_quick_height(item_first()); + return item_quick_height(item_first()) + linespacing(); } /** diff --git a/src/Fl_Check_Browser.cxx b/src/Fl_Check_Browser.cxx index d831c3cb2..e1ed61d7f 100644 --- a/src/Fl_Check_Browser.cxx +++ b/src/Fl_Check_Browser.cxx @@ -176,7 +176,8 @@ int Fl_Check_Browser::item_width(void *v) const { return int(fl_width(((cb_item *)v)->text)) + CHECK_SIZE + 8; } -void Fl_Check_Browser::item_draw(void *v, int X, int Y, int, int) const { +void Fl_Check_Browser::item_draw(void *v, int X, int Y, int, int H) const { + Y += (H - item_height(v)) / 2; cb_item *i = (cb_item *)v; char *s = i->text; int tsize = textsize(); diff --git a/src/Fl_File_Browser.cxx b/src/Fl_File_Browser.cxx index e3a70aa3b..c37ea8aa3 100644 --- a/src/Fl_File_Browser.cxx +++ b/src/Fl_File_Browser.cxx @@ -76,7 +76,7 @@ Fl_File_Browser::full_height() const for (i = 0, th = 0; i < size(); i ++) - th += item_height(find_line(i)); + th += item_height(find_line(i)) + linespacing(); return (th); } @@ -234,7 +234,7 @@ Fl_File_Browser::item_draw(void *p, // I - List item data int X, // I - Upper-lefthand X coordinate int Y, // I - Upper-lefthand Y coordinate int W, // I - Width of item - int) const // I - Height of item + int H) const// I - Height of item { int i; // Looping var FL_BLINE *line; // Pointer to line @@ -271,25 +271,23 @@ Fl_File_Browser::item_draw(void *p, // I - List item data { // Draw the icon if it is set... if (line->data) - ((Fl_File_Icon *)line->data)->draw(X, Y, iconsize_, iconsize_, - (line->flags & SELECTED) ? FL_YELLOW : + ((Fl_File_Icon *)line->data)->draw(X, Y + (H - iconsize_) / 2, + iconsize_, iconsize_, + (line->flags & SELECTED) ? FL_YELLOW : FL_LIGHT2, - active_r()); + active_r()); // Draw the text offset to the right... X += iconsize_ + 9; W -= iconsize_ - 10; - - // Center the text vertically... - height = fl_height(); - - for (t = line->txt; *t != '\0'; t ++) - if (*t == '\n') - height += fl_height(); - - if (height < iconsize_) - Y += (iconsize_ - height) / 2; } + // Center the text vertically... + height = fl_height(); + + for (t = line->txt; *t != '\0'; t ++) + if (*t == '\n') + height += fl_height(); + Y += (H - height) / 2; // Draw the text... line = (FL_BLINE *)p; -- cgit v1.2.3