Browse Source

Add right-aligned text to menu

tags/v0.3.2
Andrew Belt 7 years ago
parent
commit
435006cc03
7 changed files with 33 additions and 3 deletions
  1. +8
    -0
      include/gui.hpp
  2. +3
    -1
      include/widgets.hpp
  3. +5
    -1
      src/app/ModuleWidget.cpp
  4. +2
    -1
      src/app/RackWidget.cpp
  5. +1
    -0
      src/widgets/MenuEntry.cpp
  6. +13
    -0
      src/widgets/MenuItem.cpp
  7. +1
    -0
      src/widgets/MenuLabel.cpp

+ 8
- 0
include/gui.hpp View File

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




#ifdef ARCH_MAC
#define MOD_KEY_NAME "Cmd"
#else
#define MOD_KEY_NAME "Ctrl"
#endif



extern GLFWwindow *gWindow; extern GLFWwindow *gWindow;
extern NVGcontext *gVg; extern NVGcontext *gVg;
extern std::shared_ptr<Font> gGuiFont; extern std::shared_ptr<Font> gGuiFont;


+ 3
- 1
include/widgets.hpp View File

@@ -264,10 +264,11 @@ struct Menu : OpaqueWidget {


struct MenuEntry : OpaqueWidget { struct MenuEntry : OpaqueWidget {
std::string text; std::string text;
std::string rightText;
MenuEntry() { MenuEntry() {
box.size = Vec(0, BND_WIDGET_HEIGHT); box.size = Vec(0, BND_WIDGET_HEIGHT);
} }
float computeMinWidth(NVGcontext *vg);
virtual float computeMinWidth(NVGcontext *vg);
}; };


struct MenuLabel : MenuEntry { struct MenuLabel : MenuEntry {
@@ -277,6 +278,7 @@ struct MenuLabel : MenuEntry {
struct MenuItem : MenuEntry { struct MenuItem : MenuEntry {
BNDwidgetState state = BND_DEFAULT; BNDwidgetState state = BND_DEFAULT;


float computeMinWidth(NVGcontext *vg);
void draw(NVGcontext *vg); void draw(NVGcontext *vg);


void onMouseEnter(); void onMouseEnter();


+ 5
- 1
src/app/ModuleWidget.cpp View File

@@ -176,7 +176,7 @@ Widget *ModuleWidget::onHoverKey(Vec pos, int key) {
gRackWidget->cloneModule(this); gRackWidget->cloneModule(this);
break; break;
} }
return NULL;
return this;
} }


void ModuleWidget::onDragStart() { void ModuleWidget::onDragStart() {
@@ -237,11 +237,13 @@ void ModuleWidget::onMouseDown(int button) {


InitializeMenuItem *resetItem = new InitializeMenuItem(); InitializeMenuItem *resetItem = new InitializeMenuItem();
resetItem->text = "Initialize"; resetItem->text = "Initialize";
resetItem->rightText = MOD_KEY_NAME "+I";
resetItem->moduleWidget = this; resetItem->moduleWidget = this;
menu->pushChild(resetItem); menu->pushChild(resetItem);


RandomizeMenuItem *randomizeItem = new RandomizeMenuItem(); RandomizeMenuItem *randomizeItem = new RandomizeMenuItem();
randomizeItem->text = "Randomize"; randomizeItem->text = "Randomize";
randomizeItem->rightText = MOD_KEY_NAME "+R";
randomizeItem->moduleWidget = this; randomizeItem->moduleWidget = this;
menu->pushChild(randomizeItem); menu->pushChild(randomizeItem);


@@ -252,11 +254,13 @@ void ModuleWidget::onMouseDown(int button) {


CloneMenuItem *cloneItem = new CloneMenuItem(); CloneMenuItem *cloneItem = new CloneMenuItem();
cloneItem->text = "Duplicate"; cloneItem->text = "Duplicate";
cloneItem->rightText = MOD_KEY_NAME "+D";
cloneItem->moduleWidget = this; cloneItem->moduleWidget = this;
menu->pushChild(cloneItem); menu->pushChild(cloneItem);


DeleteMenuItem *deleteItem = new DeleteMenuItem(); DeleteMenuItem *deleteItem = new DeleteMenuItem();
deleteItem->text = "Delete"; deleteItem->text = "Delete";
deleteItem->rightText = "Backspace/Delete";
deleteItem->moduleWidget = this; deleteItem->moduleWidget = this;
menu->pushChild(deleteItem); menu->pushChild(deleteItem);
} }


+ 2
- 1
src/app/RackWidget.cpp View File

@@ -337,7 +337,8 @@ void RackWidget::onMouseDown(int button) {
for (Plugin *plugin : gPlugins) { for (Plugin *plugin : gPlugins) {
for (Model *model : plugin->models) { for (Model *model : plugin->models) {
AddModuleMenuItem *item = new AddModuleMenuItem(); AddModuleMenuItem *item = new AddModuleMenuItem();
item->text = model->plugin->name + ": " + model->name;
item->text = model->name;
item->rightText = model->plugin->name;
item->model = model; item->model = model;
item->modulePos = modulePos; item->modulePos = modulePos;
menu->pushChild(item); menu->pushChild(item);


+ 1
- 0
src/widgets/MenuEntry.cpp View File

@@ -3,6 +3,7 @@


namespace rack { namespace rack {



float MenuEntry::computeMinWidth(NVGcontext *vg) { float MenuEntry::computeMinWidth(NVGcontext *vg) {
return bndLabelWidth(vg, -1, text.c_str()); return bndLabelWidth(vg, -1, text.c_str());
} }


+ 13
- 0
src/widgets/MenuItem.cpp View File

@@ -3,8 +3,21 @@


namespace rack { namespace rack {



#define RIGHT_PADDING 10.0
#define BND_LABEL_FONT_SIZE 13

float MenuItem::computeMinWidth(NVGcontext *vg) {
return MenuEntry::computeMinWidth(vg) + RIGHT_PADDING + bndLabelWidth(vg, -1, rightText.c_str());
}

void MenuItem::draw(NVGcontext *vg) { void MenuItem::draw(NVGcontext *vg) {
bndMenuItem(vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str()); bndMenuItem(vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str());

float x = box.size.x - bndLabelWidth(vg, -1, rightText.c_str());
NVGcolor rightColor = (state == BND_DEFAULT) ? bndGetTheme()->menuTheme.textColor : bndGetTheme()->menuTheme.textSelectedColor;
bndIconLabelValue(vg, x, 0.0, box.size.x, box.size.y, -1,
rightColor, BND_LEFT, BND_LABEL_FONT_SIZE, rightText.c_str(), NULL);
} }


void MenuItem::onMouseEnter() { void MenuItem::onMouseEnter() {


+ 1
- 0
src/widgets/MenuLabel.cpp View File

@@ -3,6 +3,7 @@


namespace rack { namespace rack {



void MenuLabel::draw(NVGcontext *vg) { void MenuLabel::draw(NVGcontext *vg) {
bndMenuLabel(vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); bndMenuLabel(vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str());
} }


Loading…
Cancel
Save