13
0

some initial bits of work on canvas allocation

This commit is contained in:
Paul Davis 2017-01-30 14:46:14 +01:00
parent e75c713e5e
commit 52718b3411
3 changed files with 122 additions and 41 deletions

View File

@ -23,6 +23,8 @@
#include "canvas/canvas.h" #include "canvas/canvas.h"
#include "canvas/container.h" #include "canvas/container.h"
#include "canvas/colors.h" #include "canvas/colors.h"
#include "canvas/debug.h"
#include "canvas/grid.h"
#include "canvas/scroll_group.h" #include "canvas/scroll_group.h"
#include "canvas/text.h" #include "canvas/text.h"
#include "canvas/widget.h" #include "canvas/widget.h"
@ -110,6 +112,7 @@ private:
ArdourCanvas::GtkCanvas* canvas; ArdourCanvas::GtkCanvas* canvas;
ArdourCanvas::Container* group; ArdourCanvas::Container* group;
ArdourCanvas::Grid* grid;
ArdourButton test_button; ArdourButton test_button;
}; };
@ -163,12 +166,60 @@ ArdourCanvas::Container*
CANVAS_UI::initialize_canvas (ArdourCanvas::Canvas& canvas) CANVAS_UI::initialize_canvas (ArdourCanvas::Canvas& canvas)
{ {
using namespace ArdourCanvas; using namespace ArdourCanvas;
canvas.set_background_color (rgba_to_color (0.0, 0.0, 1.0, 1.0)); canvas.set_background_color (rgba_to_color (0.0, 0.0, 0.4, 1.0));
ScrollGroup* scroll_group = new ScrollGroup (canvas.root(), ScrollGroup* scroll_group = new ScrollGroup (canvas.root(),
ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally)); ScrollGroup::ScrollSensitivity (ScrollGroup::ScrollsVertically|ScrollGroup::ScrollsHorizontally));
ArdourCanvas::Widget* w = new ArdourCanvas::Widget (scroll_group, test_button); grid = new ArdourCanvas::Grid (scroll_group);
grid->set_padding (10.0);
grid->set_margin (20.0);
grid->set_outline_width (3.0);
grid->set_outline_color (Color (0x3daec1ff));
grid->set_outline (true);
ArdourCanvas::Text* text1 = new ArdourCanvas::Text (&canvas);
text1->set ("hello, world");
text1->set_color (Color (0xff0000ff));
ArdourCanvas::Text* text2 = new ArdourCanvas::Text (&canvas);
text2->set ("goodbye, cruel world");
text2->set_color (Color (0x00ff00ff));
ArdourCanvas::Text* text3 = new ArdourCanvas::Text (&canvas);
text3->set ("I am the third");
text3->set_color (Color (0xff00ffff));
ArdourCanvas::Text* text4 = new ArdourCanvas::Text (&canvas);
text4->set ("I am fourth");
text4->set_color (Color (0xffff00ff));
#if 0
grid->place (text1, ArdourCanvas::Duple (0, 0));
grid->place (text2, ArdourCanvas::Duple (1, 0));
grid->place (text3, ArdourCanvas::Duple (0, 1));
grid->place (text4, ArdourCanvas::Duple (1, 1));
#endif
ArdourButton* button1 = new ArdourButton ("auto-return");
ArdourButton* button2 = new ArdourButton ("auto-play");
ArdourButton* button3 = new ArdourButton ("follow range");
ArdourButton* button4 = new ArdourButton ("auto-input");
ArdourCanvas::Widget* w1 = new ArdourCanvas::Widget (&canvas, *button1);
CANVAS_DEBUG_NAME (w1, "w1");
grid->place (w1, ArdourCanvas::Duple (3, 0));
ArdourCanvas::Widget* w2 = new ArdourCanvas::Widget (&canvas, *button2);
CANVAS_DEBUG_NAME (w2, "w2");
grid->place (w2, ArdourCanvas::Duple (4, 0));
ArdourCanvas::Widget* w3 = new ArdourCanvas::Widget (&canvas, *button3);
CANVAS_DEBUG_NAME (w3, "w3");
grid->place (w3, ArdourCanvas::Duple (3, 1));
ArdourCanvas::Widget* w4 = new ArdourCanvas::Widget (&canvas, *button4);
CANVAS_DEBUG_NAME (w4, "w4");
grid->place (w4, ArdourCanvas::Duple (4, 1));
//ArdourCanvas::Widget* w = new ArdourCanvas::Widget (scroll_group, test_button);
//CANVAS_DEBUG_NAME (w, "TheW");
return new ArdourCanvas::Container (scroll_group); return new ArdourCanvas::Container (scroll_group);
} }

View File

@ -165,6 +165,7 @@ Box::reposition_children ()
Duple previous_edge (0, 0); Duple previous_edge (0, 0);
Distance largest_width = 0; Distance largest_width = 0;
Distance largest_height = 0; Distance largest_height = 0;
Rect uniform_size;
if (homogenous) { if (homogenous) {
@ -175,33 +176,35 @@ Box::reposition_children ()
largest_width = std::max (largest_width, bb.width()); largest_width = std::max (largest_width, bb.width());
} }
} }
uniform_size = Rect (0, 0, largest_width, largest_height);
} }
for (std::list<Item*>::iterator i = _items.begin(); ++i != _items.end(); ++i) { for (std::list<Item*>::iterator i = _items.begin(); ++i != _items.end(); ++i) {
(*i)->set_position (previous_edge); (*i)->set_position (previous_edge);
if (homogenous) {
(*i)->size_allocate (uniform_size);
}
if (orientation == Vertical) { if (orientation == Vertical) {
Distance shift = 0; Distance shift = 0;
if (homogenous) { Rect bb = (*i)->bounding_box();
shift = largest_height;
} else {
Rect bb = (*i)->bounding_box();
if (!(*i)->visible()) { if (!(*i)->visible()) {
/* invisible child */ /* invisible child */
if (!collapse_on_hide) { if (!collapse_on_hide) {
/* still add in its size */ /* still add in its size */
if (bb) {
shift += bb.height();
}
}
} else {
if (bb) { if (bb) {
shift += bb.height(); shift += bb.height();
} }
}
} else {
if (bb) {
shift += bb.height();
} }
} }
@ -210,23 +213,18 @@ Box::reposition_children ()
} else { } else {
Distance shift = 0; Distance shift = 0;
Rect bb = (*i)->bounding_box();
if (homogenous) { if (!(*i)->visible()) {
shift = largest_width; if (!collapse_on_hide) {
} else {
Rect bb = (*i)->bounding_box();
if (!(*i)->visible()) {
if (!collapse_on_hide) {
if (bb) {
shift += bb.width();
}
}
} else {
if (bb) { if (bb) {
shift += bb.width(); shift += bb.width();
} }
} }
} else {
if (bb) {
shift += bb.width();
}
} }
previous_edge = previous_edge.translate (Duple (spacing + shift, 0)); previous_edge = previous_edge.translate (Duple (spacing + shift, 0));

View File

@ -33,7 +33,7 @@ Grid::Grid (Canvas* canvas)
, spacing (0) , spacing (0)
, top_padding (0), right_padding (0), bottom_padding (0), left_padding (0) , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0)
, top_margin (0), right_margin (0), bottom_margin (0), left_margin (0) , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0)
, homogenous (false) , homogenous (true)
{ {
self = new Rectangle (this); self = new Rectangle (this);
self->set_outline (false); self->set_outline (false);
@ -45,7 +45,7 @@ Grid::Grid (Item* parent)
, spacing (0) , spacing (0)
, top_padding (0), right_padding (0), bottom_padding (0), left_padding (0) , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0)
, top_margin (0), right_margin (0), bottom_margin (0), left_margin (0) , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0)
, homogenous (false) , homogenous (true)
{ {
self = new Rectangle (this); self = new Rectangle (this);
self->set_outline (false); self->set_outline (false);
@ -57,7 +57,7 @@ Grid::Grid (Item* parent, Duple const & p)
, spacing (0) , spacing (0)
, top_padding (0), right_padding (0), bottom_padding (0), left_padding (0) , top_padding (0), right_padding (0), bottom_padding (0), left_padding (0)
, top_margin (0), right_margin (0), bottom_margin (0), left_margin (0) , top_margin (0), right_margin (0), bottom_margin (0), left_margin (0)
, homogenous (false) , homogenous (true)
{ {
self = new Rectangle (this); self = new Rectangle (this);
self->set_outline (false); self->set_outline (false);
@ -188,23 +188,55 @@ Grid::reposition_children ()
row_dimens.assign (max_row, 0); row_dimens.assign (max_row, 0);
col_dimens.assign (max_col, 0); col_dimens.assign (max_col, 0);
for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) { Rect uniform_size;
if (*i == self) { if (homogenous) {
/* self-rect is not a normal child */ for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
continue;
Rect bb = (*i)->bounding_box();
if (!bb) {
continue;
}
cerr << "\tbb is " << bb << endl;
uniform_size.y1 = max (uniform_size.y1, bb.height());
uniform_size.x1 = max (uniform_size.x1, bb.width());
} }
Rect bb = (*i)->bounding_box(); cerr << "Uniform size will be " << uniform_size << endl;
if (!bb) { for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
continue; if (*i == self) {
/* self-rect is not a normal child */
continue;
}
(*i)->size_allocate (uniform_size);
for (uint32_t n = 0; n < max_row; ++n) {
col_dimens[n] = uniform_size.width();
}
for (uint32_t n = 0; n < max_col; ++n) {
row_dimens[n] = uniform_size.height();
}
} }
} else {
for (std::list<Item*>::iterator i = _items.begin(); i != _items.end(); ++i) {
CoordsByItem::const_iterator c = coords_by_item.find (*i); if (*i == self) {
/* self-rect is not a normal child */
continue;
}
row_dimens[c->second.y] = max (row_dimens[c->second.y], bb.height()); Rect bb = (*i)->bounding_box();
col_dimens[c->second.x] = max (col_dimens[c->second.x] , bb.width());
if (!bb) {
continue;
}
CoordsByItem::const_iterator c = coords_by_item.find (*i);
row_dimens[c->second.y] = max (row_dimens[c->second.y], bb.height());
col_dimens[c->second.x] = max (col_dimens[c->second.x] , bb.width());
}
} }
/* now sum the row and column widths, so that row_dimens is transformed /* now sum the row and column widths, so that row_dimens is transformed