<commit_before>#include "widgets.hpp"


namespace rack {


#define BND_LABEL_FONT_SIZE 13


void MenuItem::draw(NVGcontext *vg) {
	// Get state
	BNDwidgetState state = (gHoveredWidget == this) ? BND_HOVER : BND_DEFAULT;
	Menu *parentMenu = dynamic_cast<Menu*>(parent);
	if (parentMenu && parentMenu->activeEntry == this) {
		state = BND_ACTIVE;
	}

	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(EventMouseEnter &e) {
	Menu *parentMenu = dynamic_cast<Menu*>(parent);
	if (!parentMenu)
		return;

	parentMenu->activeEntry = NULL;

	// Try to create child menu
	Menu *childMenu = createChildMenu();
	if (childMenu) {
		parentMenu->activeEntry = this;
		childMenu->box.pos = parent->box.pos.plus(box.getTopRight());
	}
	parentMenu->setChildMenu(childMenu);
}

void MenuItem::onDragDrop(EventDragDrop &e) {
	if (e.origin != this)
		return;

	EventAction eAction;
	onAction(eAction);
	// deletes `this`
	gScene->setOverlay(NULL);
}


} // namespace rack<commit_msg>Don't close Menu if onAction() event is not consumed<commit_after>#include "widgets.hpp"


namespace rack {


#define BND_LABEL_FONT_SIZE 13


void MenuItem::draw(NVGcontext *vg) {
	// Get state
	BNDwidgetState state = (gHoveredWidget == this) ? BND_HOVER : BND_DEFAULT;
	Menu *parentMenu = dynamic_cast<Menu*>(parent);
	if (parentMenu && parentMenu->activeEntry == this) {
		state = BND_ACTIVE;
	}

	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(EventMouseEnter &e) {
	Menu *parentMenu = dynamic_cast<Menu*>(parent);
	if (!parentMenu)
		return;

	parentMenu->activeEntry = NULL;

	// Try to create child menu
	Menu *childMenu = createChildMenu();
	if (childMenu) {
		parentMenu->activeEntry = this;
		childMenu->box.pos = parent->box.pos.plus(box.getTopRight());
	}
	parentMenu->setChildMenu(childMenu);
}

void MenuItem::onDragDrop(EventDragDrop &e) {
	if (e.origin != this)
		return;

	EventAction eAction;
	// TODO Perhaps remove this? It would require all onAction() methods to call this explicitly, which might be too annoying to change.
	eAction.consumed = true;
	onAction(eAction);
	if (eAction.consumed) {
		// deletes `this`
		gScene->setOverlay(NULL);
	}
}


} // namespace rack
{'fraction_non_alphanumeric': 0.14662555669749913, 'fraction_numerical': 0.0075368276807125725, 'mean_word_length': 4.828343313373254, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '482705', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1056, 'n_words': 230}