mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-15 19:16:40 +01:00
remove Kiwi constraint-based packing code from canvas library and users (library version)
This commit is contained in:
parent
a9adc3c5c6
commit
0f0c5c7039
28 changed files with 0 additions and 5235 deletions
|
|
@ -1,131 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <gtkmm/adjustment.h>
|
||||
#include <gtkmm/main.h>
|
||||
#include <gtkmm/window.h>
|
||||
|
||||
#include "gtkmm2ext/colors.h"
|
||||
|
||||
#include "canvas/box.h"
|
||||
#include "canvas/canvas.h"
|
||||
#include "canvas/circle.h"
|
||||
#include "canvas/constrained_item.h"
|
||||
#include "canvas/constraint_packer.h"
|
||||
#include "canvas/rectangle.h"
|
||||
#include "canvas/text.h"
|
||||
|
||||
using namespace ArdourCanvas;
|
||||
using namespace Gtk;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
int
|
||||
main (int argc, char* argv[])
|
||||
{
|
||||
Gtk::Main app (&argc, &argv);
|
||||
|
||||
Gtk::Window win;
|
||||
Gtk::Adjustment hadj (0, 0, 1000, 1, 10);
|
||||
Gtk::Adjustment vadj (0, 0, 1000, 1, 10);
|
||||
GtkCanvasViewport cview (hadj, vadj);
|
||||
Canvas* c = cview.canvas ();
|
||||
|
||||
c->set_background_color (0xffffffff);
|
||||
|
||||
// cview.set_size_request (100, 100);
|
||||
|
||||
win.add (cview);
|
||||
|
||||
Rectangle* r1 = new Rectangle (c);
|
||||
Rectangle* r2 = new Rectangle (c);
|
||||
Rectangle* r3 = new Rectangle (c);
|
||||
|
||||
r1->set_fill_color (Gtkmm2ext::random_color());
|
||||
r2->set_fill_color (Gtkmm2ext::random_color());
|
||||
r3->set_fill_color (Gtkmm2ext::random_color());
|
||||
|
||||
r1->name = "r1";
|
||||
r2->name = "r2";
|
||||
r3->name = "r3";
|
||||
|
||||
//r1->set_size_request (20, 20);
|
||||
//r2->set_size_request (30, 30);
|
||||
//r3->set_size_request (40, 40);
|
||||
|
||||
ConstraintPacker* vbox = new ConstraintPacker (c->root(), Vertical);
|
||||
vbox->name = "vbox";
|
||||
vbox->set_fill (true);
|
||||
vbox->set_fill_color (0xff0000ff);
|
||||
vbox->set_margin (20);
|
||||
|
||||
vbox->pack_start (r1, PackOptions(PackExpand|PackFill));
|
||||
vbox->pack_start (r2, PackOptions(PackExpand|PackFill));
|
||||
vbox->pack_start (r3, PackOptions(PackExpand|PackFill));
|
||||
|
||||
ConstraintPacker* hbox1 = new ConstraintPacker (c, Horizontal);
|
||||
hbox1->name = "hbox1";
|
||||
hbox1->set_fill (true);
|
||||
hbox1->set_fill_color (0x00ff00ff);
|
||||
|
||||
hbox1->set_margin (10);
|
||||
|
||||
Rectangle* r4 = new Rectangle (c);
|
||||
Rectangle* r5 = new Rectangle (c);
|
||||
Rectangle* r6 = new Rectangle (c);
|
||||
|
||||
r4->set_fill_color (Gtkmm2ext::random_color());
|
||||
r5->set_fill_color (Gtkmm2ext::random_color());
|
||||
r6->set_fill_color (Gtkmm2ext::random_color());
|
||||
|
||||
r4->name = "r4";
|
||||
r5->name = "r5";
|
||||
r6->name = "r6";
|
||||
|
||||
ConstrainedItem* ci4 = hbox1->pack_start (r4, PackOptions(PackExpand|PackFill));
|
||||
hbox1->pack_start (r5, PackOptions(PackExpand|PackFill));
|
||||
hbox1->pack_start (r6, PackOptions(PackExpand|PackFill));
|
||||
|
||||
BoxConstrainedItem* hb1;
|
||||
BoxConstrainedItem* ci;
|
||||
|
||||
hb1 = vbox->pack_start (hbox1, PackOptions (PackExpand|PackFill));
|
||||
|
||||
ci4->add_constraint (ci4->width() == hb1->width() / 2.);
|
||||
|
||||
Circle* circle = new Circle (c);
|
||||
circle->name = "circle";
|
||||
//circle->set_radius (30);
|
||||
circle->set_fill_color (Gtkmm2ext::random_color());
|
||||
circle->set_outline_color (Gtkmm2ext::random_color());
|
||||
|
||||
ci = vbox->pack_start (circle, PackOptions (PackExpand|PackFill));
|
||||
ci->add_constraint (ci->height() == 0.5 * hb1->height());
|
||||
ci->add_constraint (ci->center_x() == ci4->center_x());
|
||||
ci->add_constraint (ci->top_padding() == 10);
|
||||
ci->add_constraint (ci->bottom_padding() == 10);
|
||||
|
||||
ConstraintPacker* hbox2 = new ConstraintPacker (c, Horizontal);
|
||||
hbox2->name = "hbox2";
|
||||
hbox2->set_fill (true);
|
||||
hbox2->set_fill_color (Gtkmm2ext::random_color());
|
||||
hbox2->set_outline (true);
|
||||
|
||||
Text* txt = new Text (c);
|
||||
txt->name = "text";
|
||||
|
||||
Pango::FontDescription font ("Sans");
|
||||
|
||||
txt->set_font_description (font);
|
||||
txt->set ("hello world");
|
||||
|
||||
ConstrainedItem* hb2 = vbox->pack_start (hbox2, PackOptions (PackExpand|PackFill));
|
||||
ConstrainedItem* ti = hbox2->pack_start (txt, PackOptions (PackExpand), PackOptions (0));
|
||||
|
||||
ti->add_constraint (ti->center_x() == hb2->center_x());
|
||||
ti->add_constraint (ti->center_y() == hb2->center_y());
|
||||
|
||||
win.show_all ();
|
||||
app.run ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,184 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <gtkmm/adjustment.h>
|
||||
#include <gtkmm/main.h>
|
||||
#include <gtkmm/window.h>
|
||||
|
||||
#include "pbd/compose.h"
|
||||
|
||||
#include "gtkmm2ext/colors.h"
|
||||
|
||||
#include "canvas/box.h"
|
||||
#include "canvas/canvas.h"
|
||||
#include "canvas/circle.h"
|
||||
#include "canvas/constrained_item.h"
|
||||
#include "canvas/constraint_packer.h"
|
||||
#include "canvas/rectangle.h"
|
||||
#include "canvas/text.h"
|
||||
|
||||
using namespace ArdourCanvas;
|
||||
using namespace Gtk;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
#define SQUARED 16
|
||||
|
||||
struct Column {
|
||||
Column (Canvas* c, uint32_t num) : number (num) {
|
||||
box = new ConstraintPacker (c, Vertical);
|
||||
box->name = string_compose ("col%1", num);
|
||||
box->set_spacing (12);
|
||||
|
||||
Pango::FontDescription font ("Sans");
|
||||
|
||||
for (int i = 0; i < SQUARED; ++i) {
|
||||
rects[i] = new Rectangle (c);
|
||||
rects[i]->name = string_compose ("r%1-%2", number, i);
|
||||
rects[i]->set_size_request (8, 12);
|
||||
rects[i]->set_outline_color (0xff0000ff);
|
||||
rects[i]->set_fill_color (Gtkmm2ext::random_color());
|
||||
|
||||
BoxConstrainedItem* b = box->pack_start (rects[i], PackOptions (PackExpand|PackFill));
|
||||
|
||||
labels[i] = new Text (c);
|
||||
labels[i]->name = string_compose ("t%1-%2", number, i);
|
||||
labels[i]->set_font_description (font);
|
||||
labels[i]->set (labels[i]->name);
|
||||
labels[i]->set_fill_color (0x000000ff);
|
||||
|
||||
ConstrainedItem* l = box->add_constrained (labels[i]);
|
||||
|
||||
/* Note: the use of labels[i].width() here is
|
||||
* equivalent to using a constant. This is not the same
|
||||
* as l->width(), which is a constraint-solved
|
||||
* variable. labels[i].width() is the pixel width of
|
||||
* 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());
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
ConstraintPacker* box;
|
||||
Rectangle* rects[SQUARED];
|
||||
Text* labels[SQUARED];
|
||||
uint32_t number;
|
||||
};
|
||||
|
||||
int
|
||||
main (int argc, char* argv[])
|
||||
{
|
||||
Gtk::Main app (&argc, &argv);
|
||||
|
||||
Gtk::Window win;
|
||||
Gtk::Adjustment hadj (0, 0, 1000, 1, 10);
|
||||
Gtk::Adjustment vadj (0, 0, 1000, 1, 10);
|
||||
GtkCanvasViewport cview (hadj, vadj);
|
||||
Canvas* c = cview.canvas ();
|
||||
|
||||
c->set_background_color (0xffffffff);
|
||||
|
||||
// cview.set_size_request (100, 100);
|
||||
|
||||
win.add (cview);
|
||||
|
||||
ConstraintPacker* main_hbox = new ConstraintPacker (c->root(), Horizontal);
|
||||
main_hbox->name = "main";
|
||||
main_hbox->set_spacing (12);
|
||||
main_hbox->set_margin (24);
|
||||
|
||||
Column* cols[SQUARED];
|
||||
|
||||
for (size_t i = 0; i < SQUARED; ++i) {
|
||||
cols[i] = new Column (c, i);
|
||||
main_hbox->pack_start (cols[i]->box, PackOptions (PackExpand|PackFill));
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
Circle* circle = new Circle (c);
|
||||
circle->name = "circle";
|
||||
//circle->set_radius (30);
|
||||
circle->set_fill_color (Gtkmm2ext::random_color());
|
||||
circle->set_outline_color (Gtkmm2ext::random_color());
|
||||
|
||||
ci = vbox->pack_start (circle, PackOptions (PackExpand|PackFill));
|
||||
ci->add_constraint (ci->height() == 0.5 * hb1->height());
|
||||
|
||||
ConstraintPacker* hbox2 = new ConstraintPacker (c, Horizontal);
|
||||
hbox2->name = "hbox2";
|
||||
hbox2->set_fill (true);
|
||||
hbox2->set_fill_color (Gtkmm2ext::random_color());
|
||||
|
||||
Text* txt = new Text (c);
|
||||
txt->name = "text";
|
||||
|
||||
Pango::FontDescription font ("Sans");
|
||||
|
||||
txt->set_font_description (font);
|
||||
txt->set ("hello, world");
|
||||
|
||||
ConstrainedItem* ti = hbox2->pack_start (txt, PackExpand);
|
||||
ti->add_constraint (ti->left() == 25);
|
||||
|
||||
vbox->pack_start (hbox2, PackOptions (PackExpand|PackFill));
|
||||
#endif
|
||||
|
||||
|
||||
win.show_all ();
|
||||
app.run ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
/* code test arbitrary constraint layout */
|
||||
|
||||
ConstraintPacker* packer = new ConstraintPacker (c->root());
|
||||
|
||||
ConstrainedItem* left = packer->add_constrained (r1);
|
||||
ConstrainedItem* right = packer->add_constrained (r2);
|
||||
ConstrainedItem* center = packer->add_constrained (r3);
|
||||
|
||||
/* x-axis */
|
||||
|
||||
packer->constrain (left->left() == 0);
|
||||
packer->constrain (center->left() == left->right());
|
||||
packer->constrain (right->left() == center->right());
|
||||
|
||||
packer->constrain (left->width() == packer->width * 0.4);
|
||||
packer->constrain (center->width() == packer->width * 0.1);
|
||||
packer->constrain (left->width() + right->width() + center->width() == packer->width);
|
||||
|
||||
packer->constrain (left->right() == left->left() + left->width());
|
||||
packer->constrain (right->right() == right->left() + right->width());
|
||||
packer->constrain (center->right() == center->left() + center->width());
|
||||
|
||||
/* y-axis */
|
||||
|
||||
packer->constrain (left->top() == 0);
|
||||
packer->constrain (right->top() == left->top());
|
||||
packer->constrain (center->top() == left->top());
|
||||
|
||||
packer->constrain (left->height() == packer->height);
|
||||
packer->constrain (right->height() == left->height());
|
||||
packer->constrain (center->height() == left->height());
|
||||
|
||||
packer->constrain (left->bottom() == left->top() + left->height());
|
||||
packer->constrain (center->bottom() == center->top() + center->height());
|
||||
packer->constrain (right->bottom() == right->top() + right->height());
|
||||
#endif
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <gtkmm/adjustment.h>
|
||||
#include <gtkmm/main.h>
|
||||
#include <gtkmm/window.h>
|
||||
|
||||
#include "gtkmm2ext/colors.h"
|
||||
|
||||
#include "canvas/box.h"
|
||||
#include "canvas/canvas.h"
|
||||
#include "canvas/circle.h"
|
||||
#include "canvas/constrained_item.h"
|
||||
#include "canvas/constraint_packer.h"
|
||||
#include "canvas/rectangle.h"
|
||||
#include "canvas/text.h"
|
||||
|
||||
using namespace ArdourCanvas;
|
||||
using namespace Gtk;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
int
|
||||
main (int argc, char* argv[])
|
||||
{
|
||||
Gtk::Main app (&argc, &argv);
|
||||
|
||||
Gtk::Window win;
|
||||
Gtk::Adjustment hadj (0, 0, 1000, 1, 10);
|
||||
Gtk::Adjustment vadj (0, 0, 1000, 1, 10);
|
||||
GtkCanvasViewport cview (hadj, vadj);
|
||||
Canvas* c = cview.canvas ();
|
||||
|
||||
c->set_background_color (0xffffffff);
|
||||
|
||||
cview.set_size_request (100, 100);
|
||||
|
||||
win.add (cview);
|
||||
|
||||
Rectangle* r1 = new Rectangle (c);
|
||||
Rectangle* r2 = new Rectangle (c);
|
||||
Rectangle* r3 = new Rectangle (c);
|
||||
|
||||
r1->set_fill_color (Gtkmm2ext::random_color());
|
||||
r2->set_fill_color (Gtkmm2ext::random_color());
|
||||
r3->set_fill_color (Gtkmm2ext::random_color());
|
||||
|
||||
r1->name = "r1";
|
||||
r2->name = "r2";
|
||||
r3->name = "r3";
|
||||
|
||||
r1->set_size_request (20, 20);
|
||||
r2->set_size_request (30, 30);
|
||||
r3->set_size_request (40, 40);
|
||||
|
||||
ConstraintPacker* packer = new ConstraintPacker (c->root());
|
||||
|
||||
ConstrainedItem* left = packer->add_constrained (r1);
|
||||
ConstrainedItem* right = packer->add_constrained (r2);
|
||||
ConstrainedItem* center = packer->add_constrained (r3);
|
||||
|
||||
/* x-axis */
|
||||
|
||||
packer->constrain (left->left() == 0);
|
||||
packer->constrain (center->left() == left->right());
|
||||
packer->constrain (right->left() == center->right());
|
||||
|
||||
packer->constrain (left->width() == packer->width * 0.4);
|
||||
packer->constrain (center->width() == packer->width * 0.1);
|
||||
packer->constrain (left->width() + right->width() + center->width() == packer->width);
|
||||
|
||||
packer->constrain (left->right() == left->left() + left->width());
|
||||
packer->constrain (right->right() == right->left() + right->width());
|
||||
packer->constrain (center->right() == center->left() + center->width());
|
||||
|
||||
/* y-axis */
|
||||
|
||||
packer->constrain (left->top() == 0);
|
||||
packer->constrain (right->top() == left->top());
|
||||
packer->constrain (center->top() == left->top());
|
||||
|
||||
packer->constrain (left->height() == packer->height);
|
||||
packer->constrain (right->height() == left->height());
|
||||
packer->constrain (center->height() == left->height());
|
||||
|
||||
packer->constrain (left->bottom() == left->top() + left->height());
|
||||
packer->constrain (center->bottom() == center->top() + center->height());
|
||||
packer->constrain (right->bottom() == right->top() + right->height());
|
||||
|
||||
win.show_all ();
|
||||
app.run ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <gtkmm/adjustment.h>
|
||||
#include <gtkmm/main.h>
|
||||
#include <gtkmm/window.h>
|
||||
|
||||
#include "gtkmm2ext/colors.h"
|
||||
|
||||
#include "canvas/box.h"
|
||||
#include "canvas/canvas.h"
|
||||
#include "canvas/circle.h"
|
||||
#include "canvas/constrained_item.h"
|
||||
#include "canvas/constraint_packer.h"
|
||||
#include "canvas/rectangle.h"
|
||||
#include "canvas/text.h"
|
||||
|
||||
using namespace ArdourCanvas;
|
||||
using namespace Gtk;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
int
|
||||
main (int argc, char* argv[])
|
||||
{
|
||||
Gtk::Main app (&argc, &argv);
|
||||
|
||||
Gtk::Window win;
|
||||
Gtk::Adjustment hadj (0, 0, 1000, 1, 10);
|
||||
Gtk::Adjustment vadj (0, 0, 1000, 1, 10);
|
||||
GtkCanvasViewport cview (hadj, vadj);
|
||||
Canvas* c = cview.canvas ();
|
||||
|
||||
c->set_background_color (0xffffffff);
|
||||
|
||||
win.add (cview);
|
||||
|
||||
/* Make some items */
|
||||
|
||||
Rectangle* r1 = new Rectangle (c);
|
||||
Rectangle* r2 = new Rectangle (c);
|
||||
Rectangle* r3 = new Rectangle (c);
|
||||
|
||||
r1->set_fill_color (Gtkmm2ext::random_color());
|
||||
r2->set_fill_color (Gtkmm2ext::random_color());
|
||||
r3->set_fill_color (Gtkmm2ext::random_color());
|
||||
|
||||
r1->name = "L";
|
||||
r2->name = "R";
|
||||
r3->name = "C";
|
||||
|
||||
r1->set_size_request (20, 20);
|
||||
r2->set_size_request (30, 30);
|
||||
r3->set_size_request (40, 40);
|
||||
|
||||
Text* txt = new Text (c);
|
||||
txt->name = "text";
|
||||
Pango::FontDescription font ("Sans");
|
||||
txt->set_font_description (font);
|
||||
txt->set ("hello world");
|
||||
|
||||
Rectangle* bb = new Rectangle (c);
|
||||
bb->set_fill_color (Gtkmm2ext::random_color());
|
||||
|
||||
Circle* circ = new Circle (c);
|
||||
circ->name = "circle";
|
||||
circ->set_fill_color (Gtkmm2ext::random_color());
|
||||
circ->set_outline_color (Gtkmm2ext::random_color());
|
||||
|
||||
/* create a container */
|
||||
|
||||
ConstraintPacker* packer = new ConstraintPacker (c->root());
|
||||
|
||||
/* give it a minimum size */
|
||||
|
||||
packer->set_size_request (100, 100);
|
||||
|
||||
/* add stuff */
|
||||
|
||||
ConstrainedItem* left = packer->add_constrained (r1);
|
||||
ConstrainedItem* right = packer->add_constrained (r2);
|
||||
ConstrainedItem* center = packer->add_constrained (r3);
|
||||
ConstrainedItem* text = packer->add_constrained (txt);
|
||||
ConstrainedItem* bens_box = packer->add_constrained (bb);
|
||||
ConstrainedItem* circle = packer->add_constrained (circ);
|
||||
|
||||
/* first, constraints that connect an item dimension to the container dimensions or a constant */
|
||||
packer->constrain (left->left() == 0);
|
||||
packer->constrain (left->height() == packer->height);
|
||||
packer->constrain (left->top() == 0);
|
||||
packer->constrain (left->width() == 0.5 * packer->width);
|
||||
packer->constrain (right->right() == packer->width);
|
||||
packer->constrain (center->height() == 0.5 * packer->height);
|
||||
|
||||
/* second, constraints that connect an item dimension to other items */
|
||||
center->right_of (*left, 50);
|
||||
right->right_of (*center);
|
||||
center->same_width_as (*right);
|
||||
right->same_width_as (*center);
|
||||
right->same_height_as (*left);
|
||||
center->top_aligned_with (*left);
|
||||
right->top_aligned_with (*center);
|
||||
|
||||
/* XXX this needs to somehow move into ConstraintPacker but I currently
|
||||
* see no way to build a constraint from a container of
|
||||
* ConstrainedItems
|
||||
*/
|
||||
|
||||
packer->constrain (left->width() + right->width() + center->width() +
|
||||
left->left_padding() + left->right_padding() +
|
||||
center->left_padding() + center->right_padding() +
|
||||
right->left_padding() + right->right_padding()
|
||||
== packer->width);
|
||||
|
||||
/* Text at a fixed position */
|
||||
text->at (Duple (150, 50));
|
||||
/* Rectangle of fixed position and size */
|
||||
bens_box->box (Rect (40, 40, 80, 80));
|
||||
|
||||
/* a circle sized and centered */
|
||||
circle->size (Duple (30, 30));
|
||||
circle->centered_on (*center);
|
||||
|
||||
win.show_all ();
|
||||
app.run ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue