From 59c8b99feec78b080b91c084e6ec44c9e3b1c01d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 17 Sep 2021 12:51:26 -0600 Subject: [PATCH] canvastable: remove rows/cols members, reuse ::compute() for ::size_request() --- libs/canvas/canvas/table.h | 2 -- libs/canvas/table.cc | 62 ++++++-------------------------------- 2 files changed, 10 insertions(+), 54 deletions(-) diff --git a/libs/canvas/canvas/table.h b/libs/canvas/canvas/table.h index f612b8cb85..8a52b70308 100644 --- a/libs/canvas/canvas/table.h +++ b/libs/canvas/canvas/table.h @@ -82,8 +82,6 @@ public: Distance left_margin; Distance row_spacing; Distance col_spacing; - uint32_t rows; - uint32_t cols; bool collapse_on_hide; bool homogenous; bool draw_hgrid; diff --git a/libs/canvas/table.cc b/libs/canvas/table.cc index 09d392fb6c..050e5950a7 100644 --- a/libs/canvas/table.cc +++ b/libs/canvas/table.cc @@ -33,8 +33,6 @@ using std::endl; Table::Table (Canvas* canvas) : Rectangle (canvas) - , rows (0) - , cols (0) , collapse_on_hide (false) , homogenous (true) , draw_hgrid (false) @@ -45,8 +43,6 @@ Table::Table (Canvas* canvas) Table::Table (Item* item) : Rectangle (item) - , rows (0) - , cols (0) , collapse_on_hide (false) , homogenous (true) , draw_hgrid (false) @@ -71,14 +67,12 @@ Table::attach (Item* item, Coord ulx, Coord uly, Coord lrx, Coord lry, PackOptio _add (item); item->size_request (res.first->second.natural_size.x, res.first->second.natural_size.y); - if (lrx > cols) { - cols = lrx; - col_info.resize (cols); + if (lrx > col_info.size()) { + col_info.resize (lrx); } - if (lry > rows) { - rows = lry; - row_info.resize (rows); + if (lry > row_info.size()) { + row_info.resize (lry); } } @@ -145,49 +139,10 @@ Table::set_col_size (uint32_t col, Distance size) void Table::size_request (Distance& w, Distance& h) const { - uint32_t rowmax = 0; - uint32_t colmax = 0; + Duple d = const_cast(this)->compute (Rect()); - for (auto& ci : cells) { - CellInfo const & c (ci.second); - - if (c.lower_right.x > rowmax) { - rowmax = c.lower_right.x; - } - - if (c.lower_right.y > colmax) { - colmax = c.lower_right.y; - } - } - - AxisInfos rinfo; - AxisInfos cinfo; - - rinfo.resize (rowmax+1); - cinfo.resize (colmax+1); - - for (auto& ci : cells) { - - Distance cw; - Distance ch; - - CellInfo const & c (ci.second); - c.content->size_request (cw, ch); - - rinfo[c.upper_left.x].natural_size += cw; - cinfo[c.upper_left.y].natural_size += ch; - } - - w = 0; - h = 0; - - for (auto& ai : rinfo) { - w = std::max (w, ai.natural_size); - } - - for (auto& ai : cinfo) { - h = std::max (h, ai.natural_size); - } + w = d.x; + h = d.y; } void @@ -208,6 +163,9 @@ Table::compute (Rect const & within) { DEBUG_TRACE (DEBUG::CanvasTable, string_compose ("\n\nCompute table within rect: %1\n", within)); + uint32_t rows = row_info.size(); + uint32_t cols = col_info.size(); + for (auto & ai : row_info) { ai.reset (); }