From 1d96bad59f485b547a44e26c0fa3fb6b6b6ba3dd Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 10 Jul 2020 20:21:47 -0600 Subject: [PATCH] Canvas: remove cBox (API fully merged into ConstraintPacker) --- libs/canvas/canvas/cbox.h | 53 -------------------------------- libs/canvas/cbox.cc | 51 ------------------------------ libs/canvas/constraint_packer.cc | 18 +++++------ libs/canvas/constraint_test.cc | 7 ++--- libs/canvas/constraint_test2.cc | 15 ++++++--- libs/canvas/constraint_test3.cc | 1 - libs/canvas/constraint_test4.cc | 1 - libs/canvas/wscript | 1 - 8 files changed, 22 insertions(+), 125 deletions(-) delete mode 100644 libs/canvas/canvas/cbox.h delete mode 100644 libs/canvas/cbox.cc diff --git a/libs/canvas/canvas/cbox.h b/libs/canvas/canvas/cbox.h deleted file mode 100644 index e5c56bedcd..0000000000 --- a/libs/canvas/canvas/cbox.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2012 Carl Hetherington - * Copyright (C) 2016 Paul Davis - * Copyright (C) 2017 Robin Gareus - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef __CANVAS_CBOX_H__ -#define __CANVAS_CBOX_H__ - -#include - -#include "canvas/constraint_packer.h" - -namespace ArdourCanvas -{ - -class Rectangle; -class BoxConstrainedItem; - -class LIBCANVAS_API cBox : public ConstraintPacker -{ -public: - cBox (Canvas *, Orientation); - cBox (Item *, Orientation); - - void set_collapse_on_hide (bool); - void set_homogenous (bool); - - protected: - void child_changed (bool bbox_changed); - - private: - bool collapse_on_hide; - bool homogenous; -}; - -} - -#endif /* __CANVAS_CBOX_H__ */ diff --git a/libs/canvas/cbox.cc b/libs/canvas/cbox.cc deleted file mode 100644 index 09bff1b756..0000000000 --- a/libs/canvas/cbox.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2020 Paul Davis - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include - -#include "pbd/unwind.h" - -#include "canvas/canvas.h" -#include "canvas/cbox.h" -#include "canvas/constrained_item.h" - -using namespace ArdourCanvas; -using namespace kiwi; -using std::cerr; -using std::endl; - -cBox::cBox (Canvas* c, Orientation o) - : ConstraintPacker (c) - , collapse_on_hide (false) - , homogenous (true) -{ -} - -cBox::cBox (Item* i, Orientation o) - : ConstraintPacker (i) - , collapse_on_hide (false) - , homogenous (true) -{ -} - -void -cBox::child_changed (bool bbox_changed) -{ -} - - diff --git a/libs/canvas/constraint_packer.cc b/libs/canvas/constraint_packer.cc index e8e193dcef..d4cb5748aa 100644 --- a/libs/canvas/constraint_packer.cc +++ b/libs/canvas/constraint_packer.cc @@ -256,20 +256,21 @@ ConstraintPacker::non_const_preferred_size (Duple& minimum, Duple& natural) We may have no intrinsic dimensions at all. This is the tricky one. */ - if (_intrinsic_width == 0 && _intrinsic_height == 0) { - + if (packed.size() == constrained_map.size()) { + /* All child items were packed using ::pack() */ Duple m, n; - - /* we can use the size of things packed using the box - interface - */ - box_preferred_size (m, n); natural = Duple (std::min (100.0, n.x), std::min (100.0, n.y)); minimum = natural; return; } + if (_intrinsic_width == 0 && _intrinsic_height == 0) { + natural = Duple (100.0, 100.0); + minimum = natural; + return; + } + if (_need_constraint_update) { const_cast(this)->update_constraints (); } @@ -297,8 +298,6 @@ ConstraintPacker::non_const_preferred_size (Duple& minimum, Duple& natural) _solver.reset (); _need_constraint_update = true; - - cerr << "CP min " << minimum << " pref " << natural << endl; } void @@ -494,6 +493,7 @@ ConstraintPacker::update_constraints () for (ConstrainedItemMap::iterator x = constrained_map.begin(); x != constrained_map.end(); ++x) { if (std::find (packed.begin(), packed.end(), x->second) != packed.end()) { + add_constraints (_solver, x->second); continue; } diff --git a/libs/canvas/constraint_test.cc b/libs/canvas/constraint_test.cc index ed28c235ed..46fad8a840 100644 --- a/libs/canvas/constraint_test.cc +++ b/libs/canvas/constraint_test.cc @@ -8,7 +8,6 @@ #include "canvas/box.h" #include "canvas/canvas.h" -#include "canvas/cbox.h" #include "canvas/circle.h" #include "canvas/constrained_item.h" #include "canvas/constraint_packer.h" @@ -55,7 +54,7 @@ main (int argc, char* argv[]) //r2->set_intrinsic_size (30, 30); //r3->set_intrinsic_size (40, 40); - cBox* vbox = new cBox (c->root(), Vertical); + ConstraintPacker* vbox = new ConstraintPacker (c->root(), Vertical); vbox->name = "vbox"; vbox->set_fill (true); vbox->set_fill_color (0xff0000ff); @@ -65,7 +64,7 @@ main (int argc, char* argv[]) vbox->pack_start (r2, PackOptions(PackExpand|PackFill)); vbox->pack_start (r3, PackOptions(PackExpand|PackFill)); - cBox* hbox1 = new cBox (c, Horizontal); + ConstraintPacker* hbox1 = new ConstraintPacker (c, Horizontal); hbox1->name = "hbox1"; hbox1->set_fill (true); hbox1->set_fill_color (0x00ff00ff); @@ -107,7 +106,7 @@ main (int argc, char* argv[]) ci->add_constraint (ci->top_padding() == 10); ci->add_constraint (ci->bottom_padding() == 10); - cBox* hbox2 = new cBox (c, Horizontal); + ConstraintPacker* hbox2 = new ConstraintPacker (c, Horizontal); hbox2->name = "hbox2"; hbox2->set_fill (true); hbox2->set_fill_color (Gtkmm2ext::random_color()); diff --git a/libs/canvas/constraint_test2.cc b/libs/canvas/constraint_test2.cc index f8c15fa735..b98725056b 100644 --- a/libs/canvas/constraint_test2.cc +++ b/libs/canvas/constraint_test2.cc @@ -10,7 +10,6 @@ #include "canvas/box.h" #include "canvas/canvas.h" -#include "canvas/cbox.h" #include "canvas/circle.h" #include "canvas/constrained_item.h" #include "canvas/constraint_packer.h" @@ -26,7 +25,7 @@ using std::endl; struct Column { Column (Canvas* c, uint32_t num) : number (num) { - box = new cBox (c, Vertical); + box = new ConstraintPacker (c, Vertical); box->name = string_compose ("col%1", num); box->set_spacing (12); @@ -56,6 +55,11 @@ using std::endl; * the current text contents of labels[i]. */ + l->centered_on (*b); + l->add_constraint (l->width() == labels[i]->width()); + l->add_constraint (l->height() == labels[i]->height()); + +#if 0 l->add_constraint (l->left() == b->center_x() - (labels[i]->width() / 2.)); l->add_constraint (l->width() == labels[i]->width()); l->add_constraint (l->right() == l->left() + labels[i]->width()); @@ -63,10 +67,11 @@ using std::endl; l->add_constraint (l->top() == b->center_y() - (labels[i]->height() / 2)); l->add_constraint (l->height() == labels[i]->height()); l->add_constraint (l->bottom() == l->top() + l->height()); +#endif } } - cBox* box; + ConstraintPacker* box; Rectangle* rects[SQUARED]; Text* labels[SQUARED]; uint32_t number; @@ -91,7 +96,7 @@ main (int argc, char* argv[]) win.add (cview); - cBox* main_hbox = new cBox (c->root(), Horizontal); + ConstraintPacker* main_hbox = new ConstraintPacker (c->root(), Horizontal); main_hbox->name = "main"; main_hbox->set_spacing (12); main_hbox->set_margin (24); @@ -114,7 +119,7 @@ main (int argc, char* argv[]) ci = vbox->pack_start (circle, PackOptions (PackExpand|PackFill)); ci->add_constraint (ci->height() == 0.5 * hb1->height()); - cBox* hbox2 = new cBox (c, Horizontal); + ConstraintPacker* hbox2 = new ConstraintPacker (c, Horizontal); hbox2->name = "hbox2"; hbox2->set_fill (true); hbox2->set_fill_color (Gtkmm2ext::random_color()); diff --git a/libs/canvas/constraint_test3.cc b/libs/canvas/constraint_test3.cc index 0ddb7ff7c7..d097c24bf6 100644 --- a/libs/canvas/constraint_test3.cc +++ b/libs/canvas/constraint_test3.cc @@ -8,7 +8,6 @@ #include "canvas/box.h" #include "canvas/canvas.h" -#include "canvas/cbox.h" #include "canvas/circle.h" #include "canvas/constrained_item.h" #include "canvas/constraint_packer.h" diff --git a/libs/canvas/constraint_test4.cc b/libs/canvas/constraint_test4.cc index b583a9ec26..e461062501 100644 --- a/libs/canvas/constraint_test4.cc +++ b/libs/canvas/constraint_test4.cc @@ -8,7 +8,6 @@ #include "canvas/box.h" #include "canvas/canvas.h" -#include "canvas/cbox.h" #include "canvas/circle.h" #include "canvas/constrained_item.h" #include "canvas/constraint_packer.h" diff --git a/libs/canvas/wscript b/libs/canvas/wscript index b258c79e40..b8375f5a90 100644 --- a/libs/canvas/wscript +++ b/libs/canvas/wscript @@ -32,7 +32,6 @@ canvas_sources = [ 'arrow.cc', 'box.cc', 'canvas.cc', - 'cbox.cc', 'circle.cc', 'container.cc', 'constrained_item.cc',