diff --git a/include/about_tab.hpp b/include/about_tab.hpp index f9aaf7f..9e569b4 100644 --- a/include/about_tab.hpp +++ b/include/about_tab.hpp @@ -25,18 +25,18 @@ #define __ABOUT_TAB_HPP__ #include +#include "focusable_item.hpp" namespace nxdt::views { - /* Extended class to display a focusable (but unhighlightable) label. */ - class AboutTabLabel: public brls::Label + /* Extended class to display a focusable and optionally centered (but unhighlightable) label. */ + class AboutTabLabel: public FocusableLabel { - protected: - brls::View* getDefaultFocus(void) override; - void onFocusGained(void) override; - public: - AboutTabLabel(brls::LabelStyle labelStyle, std::string text, bool center = false); + AboutTabLabel(brls::LabelStyle labelStyle, std::string text, bool center = false) : FocusableLabel(false, labelStyle, text, true) + { + if (center) this->setHorizontalAlign(NVG_ALIGN_CENTER); + } }; class AboutTab: public brls::List diff --git a/include/focusable_item.hpp b/include/focusable_item.hpp new file mode 100644 index 0000000..80bd1d4 --- /dev/null +++ b/include/focusable_item.hpp @@ -0,0 +1,73 @@ +/* + * focusable_item.hpp + * + * Copyright (c) 2020-2021, DarkMatterCore . + * + * This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool). + * + * nxdumptool is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * nxdumptool is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#ifndef __FOCUSABLE_ITEM_HPP__ +#define __FOCUSABLE_ITEM_HPP__ + +#include + +namespace nxdt::views +{ + template + class FocusableItem: public ViewType + { + private: + bool highlight_view; + + protected: + brls::View* getDefaultFocus(void) override + { + return this; + } + + void onFocusGained(void) override; + + public: + template + FocusableItem(bool highlight_view, Types... args) : ViewType(args...) + { + this->highlight_view = highlight_view; + } + }; + + template + void FocusableItem::onFocusGained(void) + { + if (this->highlight_view) + { + /* Focus and highlight view. */ + brls::View::onFocusGained(); + } else { + /* Focus view without highlighting it. */ + this->focused = true; + this->focusEvent.fire(this); + if (this->hasParent()) this->getParent()->onChildFocusGained(this); + } + } + + /* Instantiate templates for the focusable item classes we're gonna use. */ + typedef FocusableItem FocusableLabel; + typedef FocusableItem FocusableTable; +} + +#endif /* __FOCUSABLE_ITEM_HPP__ */ diff --git a/include/gamecard_tab.hpp b/include/gamecard_tab.hpp index ba6f859..e9ed92a 100644 --- a/include/gamecard_tab.hpp +++ b/include/gamecard_tab.hpp @@ -26,20 +26,10 @@ #include "tasks.hpp" #include "error_layer_view.hpp" +#include "focusable_item.hpp" namespace nxdt::views { - /* Extended class to display a focusable (but unhighlightable) table. */ - class GameCardTable: public brls::Table - { - protected: - brls::View* getDefaultFocus(void) override; - void onFocusGained(void) override; - - public: - GameCardTable(void); - }; - /* Instantiate the template for our class. */ typedef ErrorLayerView GameCardErrorLayerView; @@ -50,7 +40,7 @@ namespace nxdt::views private: GameCardStatus gc_status = GameCardStatus_NotInserted; - GameCardTable *properties_table = nullptr; + FocusableTable *properties_table = nullptr; brls::TableRow *capacity = nullptr; brls::TableRow *total_size = nullptr; brls::TableRow *trimmed_size = nullptr; diff --git a/source/about_tab.cpp b/source/about_tab.cpp index ea3e774..5476cc9 100644 --- a/source/about_tab.cpp +++ b/source/about_tab.cpp @@ -29,23 +29,6 @@ using namespace i18n::literals; /* For _i18n. */ namespace nxdt::views { - AboutTabLabel::AboutTabLabel(brls::LabelStyle labelStyle, std::string text, bool center) : brls::Label(labelStyle, text, true) - { - if (center) this->setHorizontalAlign(NVG_ALIGN_CENTER); - } - - brls::View* AboutTabLabel::getDefaultFocus(void) - { - return this; - } - - void AboutTabLabel::onFocusGained(void) - { - this->focused = true; - this->focusEvent.fire(this); - if (this->hasParent()) this->getParent()->onChildFocusGained(this); - } - AboutTab::AboutTab(void) : brls::List() { /* Set custom spacing. */ diff --git a/source/gamecard_tab.cpp b/source/gamecard_tab.cpp index 6d6e52a..cafbf22 100644 --- a/source/gamecard_tab.cpp +++ b/source/gamecard_tab.cpp @@ -41,20 +41,6 @@ namespace nxdt::views [GameCardCompatibilityType_Terra] = "Terra" }; - GameCardTable::GameCardTable(void) : brls::Table() { } - - brls::View* GameCardTable::getDefaultFocus(void) - { - return this; - } - - void GameCardTable::onFocusGained(void) - { - this->focused = true; - this->focusEvent.fire(this); - if (this->hasParent()) this->getParent()->onChildFocusGained(this); - } - GameCardTab::GameCardTab(nxdt::tasks::GameCardTask *gc_status_task) : GameCardErrorLayerView(gc_status_task) { /* Error frame. */ @@ -63,7 +49,7 @@ namespace nxdt::views /* Gamecard properties table. */ this->AddListView(new brls::Header("gamecard_tab/list/properties_table/header"_i18n)); - this->properties_table = new GameCardTable(); + this->properties_table = new FocusableTable(false); this->capacity = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/capacity"_i18n); this->total_size = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/total_size"_i18n); this->trimmed_size = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/trimmed_size"_i18n);