Browse Source

More SequentialLayout features

pull/1639/head
Andrew Belt 7 years ago
parent
commit
23b96118a4
3 changed files with 33 additions and 30 deletions
  1. +4
    -1
      include/ui.hpp
  2. +25
    -26
      src/app/ModuleBrowser.cpp
  3. +4
    -3
      src/ui/layouts.cpp

+ 4
- 1
include/ui.hpp View File

@@ -6,7 +6,7 @@
namespace rack {

////////////////////
// Layouts
// Layouts (layouts.cpp)
////////////////////

/** Positions children in a row/column based on their widths/heights */
@@ -22,7 +22,10 @@ struct SequentialLayout : virtual Widget {
RIGHT_ALIGNMENT,
};
Alignment alignment = LEFT_ALIGNMENT;
/** Space outside elements */
float margin = 0.0;
/** Space between adjacent elements */
float padding = 0.0;
void step() override;
};



+ 25
- 26
src/app/ModuleBrowser.cpp View File

@@ -49,7 +49,7 @@ struct BrowserListItem : OpaqueWidget {
bool selected = false;

BrowserListItem() {
box.size.y = 3 * BND_WIDGET_HEIGHT;
box.size.y = 2 * BND_WIDGET_HEIGHT + 7;
}

void draw(NVGcontext *vg) override {
@@ -80,43 +80,42 @@ struct BrowserListItem : OpaqueWidget {

struct ModelItem : BrowserListItem {
Model *model;
FavoriteRadioButton *favoriteButton;
Label *nameLabel;
Label *manufacturerLabel;
Label *tagsLabel;

ModelItem() {
favoriteButton = new FavoriteRadioButton();
favoriteButton->box.pos = Vec(7, BND_WIDGET_HEIGHT);
favoriteButton->box.size.x = 20;
favoriteButton->label = "★";
addChild(favoriteButton);
void setModel(Model *model) {
assert(model);
this->model = model;

nameLabel = Widget::create<Label>(Vec(0, 0));
Label *nameLabel = Widget::create<Label>(Vec(0, 0));
nameLabel->text = model->name;
addChild(nameLabel);

manufacturerLabel = Widget::create<Label>(Vec(0, 0));
manufacturerLabel->alignment = Label::RIGHT_ALIGNMENT;
manufacturerLabel->text = model->manufacturer;
addChild(manufacturerLabel);
tagsLabel = Widget::create<Label>(Vec(26, BND_WIDGET_HEIGHT));
addChild(tagsLabel);
}

void setModel(Model *model) {
assert(model);
this->model = model;
SequentialLayout *layout2 = Widget::create<SequentialLayout>(Vec(0, BND_WIDGET_HEIGHT));
layout2->margin = 7;
layout2->padding = 10;
addChild(layout2);

FavoriteRadioButton *favoriteButton = new FavoriteRadioButton();
favoriteButton->box.size.x = 20;
favoriteButton->label = "★";
layout2->addChild(favoriteButton);

auto it = sFavoriteModels.find(model);
if (it != sFavoriteModels.end())
favoriteButton->setValue(1);
favoriteButton->model = model;

nameLabel->text = model->name;
manufacturerLabel->text = model->manufacturer;
int i = 0;
for (ModelTag tag : model->tags) {
if (i++ > 0)
tagsLabel->text += ", ";
tagsLabel->text += gTagNames[tag];
}
// for (ModelTag tag : model->tags) {
// Button *tagButton = new Button();
// tagButton->box.size.x = 120;
// tagButton->text = gTagNames[tag];
// layout2->addChild(tagButton);
// }
}

void step() override {
@@ -290,7 +289,7 @@ struct ModuleBrowser : OpaqueWidget {

void step() override {
box.pos = parent->box.size.minus(box.size).div(2).round();
box.pos.y = 40;
box.pos.y = 60;
box.size.y = parent->box.size.y - 2 * box.pos.y;

moduleScroll->box.size.y = box.size.y - moduleScroll->box.pos.y;


+ 4
- 3
src/ui/layouts.cpp View File

@@ -7,7 +7,7 @@ namespace rack {
void SequentialLayout::step() {
Widget::step();

float offset = 0.0;
float offset = margin;
for (Widget *child : children) {
if (!child->visible)
continue;
@@ -15,7 +15,7 @@ void SequentialLayout::step() {
(orientation == HORIZONTAL_ORIENTATION ? child->box.pos.x : child->box.pos.y) = offset;
// Increment by size
offset += (orientation == HORIZONTAL_ORIENTATION ? child->box.size.x : child->box.size.y);
offset += margin;
offset += padding;
}

// We're done if left aligned
@@ -23,7 +23,8 @@ void SequentialLayout::step() {
return;

// Adjust positions based on width of the layout itself
offset -= margin;
offset -= padding;
offset += margin;
if (alignment == RIGHT_ALIGNMENT)
offset -= (orientation == HORIZONTAL_ORIENTATION ? box.size.x : box.size.y);
else if (alignment == CENTER_ALIGNMENT)


Loading…
Cancel
Save