Browse Source

Add active flag to MenuItem. Make author and tag list items active when selected. Add ClearItem to ModuleBrowser.

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
509d61c69a
6 changed files with 47 additions and 9 deletions
  1. +1
    -0
      include/ui/MenuItem.hpp
  2. +1
    -1
      include/widget/FramebufferWidget.hpp
  3. +38
    -2
      src/app/ModuleBrowser.cpp
  4. +1
    -2
      src/ui/Menu.cpp
  5. +3
    -0
      src/ui/MenuItem.cpp
  6. +3
    -4
      src/ui/TextField.cpp

+ 1
- 0
include/ui/MenuItem.hpp View File

@@ -13,6 +13,7 @@ struct MenuItem : MenuEntry {
std::string text; std::string text;
std::string rightText; std::string rightText;
bool disabled = false; bool disabled = false;
bool active = false;


void draw(const DrawArgs &args) override; void draw(const DrawArgs &args) override;
void step() override; void step() override;


+ 1
- 1
include/widget/FramebufferWidget.hpp View File

@@ -7,7 +7,7 @@ namespace widget {




/** Caches a widget's draw() result to a framebuffer so it is called less frequently. /** Caches a widget's draw() result to a framebuffer so it is called less frequently.
When `dirty` is true, its children will be re-rendered on the next call to step() override.
When `dirty` is true, its children will be re-rendered on the next call to step().
Events are not passed to the underlying scene. Events are not passed to the underlying scene.
*/ */
struct FramebufferWidget : Widget { struct FramebufferWidget : Widget {


+ 38
- 2
src/app/ModuleBrowser.cpp View File

@@ -266,11 +266,13 @@ struct ModelBox : widget::OpaqueWidget {


struct AuthorItem : ui::MenuItem { struct AuthorItem : ui::MenuItem {
void onAction(const event::Action &e) override; void onAction(const event::Action &e) override;
void step() override;
}; };




struct TagItem : ui::MenuItem { struct TagItem : ui::MenuItem {
void onAction(const event::Action &e) override; void onAction(const event::Action &e) override;
void step() override;
}; };




@@ -308,6 +310,11 @@ struct BrowserSearchField : ui::TextField {
}; };




struct ClearButton : ui::Button {
void onAction(const event::Action &e) override;
};


struct ShowFavoritesQuantity : Quantity { struct ShowFavoritesQuantity : Quantity {
widget::Widget *widget; widget::Widget *widget;
std::string getLabel() override { std::string getLabel() override {
@@ -331,6 +338,7 @@ struct ShowFavoritesButton : ui::RadioButton {


struct BrowserSidebar : widget::Widget { struct BrowserSidebar : widget::Widget {
BrowserSearchField *searchField; BrowserSearchField *searchField;
ClearButton *clearButton;
ShowFavoritesButton *favoriteButton; ShowFavoritesButton *favoriteButton;
ui::Label *authorLabel; ui::Label *authorLabel;
ui::List *authorList; ui::List *authorList;
@@ -343,6 +351,10 @@ struct BrowserSidebar : widget::Widget {
searchField = new BrowserSearchField; searchField = new BrowserSearchField;
addChild(searchField); addChild(searchField);


clearButton = new ClearButton;
clearButton->text = "Reset filters";
addChild(clearButton);

favoriteButton = new ShowFavoritesButton; favoriteButton = new ShowFavoritesButton;
dynamic_cast<ShowFavoritesQuantity*>(favoriteButton->quantity)->widget = favoriteButton; dynamic_cast<ShowFavoritesQuantity*>(favoriteButton->quantity)->widget = favoriteButton;
addChild(favoriteButton); addChild(favoriteButton);
@@ -392,9 +404,10 @@ struct BrowserSidebar : widget::Widget {
} }


void step() override { void step() override {

searchField->box.size.x = box.size.x; searchField->box.size.x = box.size.x;
favoriteButton->box.pos = searchField->box.getBottomLeft();
clearButton->box.pos = searchField->box.getBottomLeft();
clearButton->box.size.x = box.size.x;
favoriteButton->box.pos = clearButton->box.getBottomLeft();
favoriteButton->box.size.x = box.size.x; favoriteButton->box.size.x = box.size.x;


float listHeight = (box.size.y - favoriteButton->box.getBottom()) / 2; float listHeight = (box.size.y - favoriteButton->box.getBottom()) / 2;
@@ -606,6 +619,14 @@ struct ModuleBrowser : widget::OpaqueWidget {
} }
sidebar->tagLabel->text = string::f("Tags (%d)", tagsLen); sidebar->tagLabel->text = string::f("Tags (%d)", tagsLen);
} }

void clear() {
search = "";
sidebar->searchField->setText("");
author = "";
tag = "";
refresh();
}
}; };




@@ -648,6 +669,11 @@ inline void AuthorItem::onAction(const event::Action &e) {
browser->refresh(); browser->refresh();
} }


inline void AuthorItem::step() {
MenuItem::step();
ModuleBrowser *browser = getAncestorOfType<ModuleBrowser>();
active = (browser->author == text);
}


inline void TagItem::onAction(const event::Action &e) { inline void TagItem::onAction(const event::Action &e) {
ModuleBrowser *browser = getAncestorOfType<ModuleBrowser>(); ModuleBrowser *browser = getAncestorOfType<ModuleBrowser>();
@@ -658,6 +684,11 @@ inline void TagItem::onAction(const event::Action &e) {
browser->refresh(); browser->refresh();
} }


inline void TagItem::step() {
MenuItem::step();
ModuleBrowser *browser = getAncestorOfType<ModuleBrowser>();
active = (browser->tag == text);
}


inline void BrowserSearchField::onChange(const event::Change &e) { inline void BrowserSearchField::onChange(const event::Change &e) {
ModuleBrowser *browser = getAncestorOfType<ModuleBrowser>(); ModuleBrowser *browser = getAncestorOfType<ModuleBrowser>();
@@ -665,6 +696,11 @@ inline void BrowserSearchField::onChange(const event::Change &e) {
browser->refresh(); browser->refresh();
} }


inline void ClearButton::onAction(const event::Action &e) {
ModuleBrowser *browser = getAncestorOfType<ModuleBrowser>();
browser->clear();
}

inline void ShowFavoritesQuantity::setValue(float value) { inline void ShowFavoritesQuantity::setValue(float value) {
ModuleBrowser *browser = widget->getAncestorOfType<ModuleBrowser>(); ModuleBrowser *browser = widget->getAncestorOfType<ModuleBrowser>();
browser->favorites = (bool) value; browser->favorites = (bool) value;


+ 1
- 2
src/ui/Menu.cpp View File

@@ -14,8 +14,7 @@ Menu::~Menu() {


void Menu::setChildMenu(Menu *menu) { void Menu::setChildMenu(Menu *menu) {
if (childMenu) { if (childMenu) {
if (childMenu->parent)
childMenu->parent->removeChild(childMenu);
childMenu->parent->removeChild(childMenu);
delete childMenu; delete childMenu;
childMenu = NULL; childMenu = NULL;
} }


+ 3
- 0
src/ui/MenuItem.cpp View File

@@ -20,6 +20,9 @@ void MenuItem::draw(const DrawArgs &args) {
if (parentMenu && parentMenu->activeEntry == this) if (parentMenu && parentMenu->activeEntry == this)
state = BND_ACTIVE; state = BND_ACTIVE;


if (active)
state = BND_ACTIVE;

// Main text and background // Main text and background
if (!disabled) if (!disabled)
bndMenuItem(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str()); bndMenuItem(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str());


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

@@ -188,14 +188,13 @@ void TextField::insertText(std::string text) {
} }


void TextField::setText(std::string text) { void TextField::setText(std::string text) {
bool changed = (text != this->text);
this->text = text;
selection = cursor = text.size();
if (changed) {
if (this->text != text) {
this->text = text;
// event::Change // event::Change
event::Change eChange; event::Change eChange;
onChange(eChange); onChange(eChange);
} }
selection = cursor = text.size();
} }


void TextField::selectAll() { void TextField::selectAll() {


Loading…
Cancel
Save