mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-22 18:26:39 +00:00
Added templated FocusableItem class.
This commit is contained in:
parent
e621b0473f
commit
7af87f50f3
5 changed files with 83 additions and 51 deletions
|
@ -25,18 +25,18 @@
|
|||
#define __ABOUT_TAB_HPP__
|
||||
|
||||
#include <borealis.hpp>
|
||||
#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
|
||||
|
|
73
include/focusable_item.hpp
Normal file
73
include/focusable_item.hpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* focusable_item.hpp
|
||||
*
|
||||
* Copyright (c) 2020-2021, DarkMatterCore <pabloacurielz@gmail.com>.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __FOCUSABLE_ITEM_HPP__
|
||||
#define __FOCUSABLE_ITEM_HPP__
|
||||
|
||||
#include <borealis.hpp>
|
||||
|
||||
namespace nxdt::views
|
||||
{
|
||||
template<typename ViewType>
|
||||
class FocusableItem: public ViewType
|
||||
{
|
||||
private:
|
||||
bool highlight_view;
|
||||
|
||||
protected:
|
||||
brls::View* getDefaultFocus(void) override
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void onFocusGained(void) override;
|
||||
|
||||
public:
|
||||
template<typename... Types>
|
||||
FocusableItem(bool highlight_view, Types... args) : ViewType(args...)
|
||||
{
|
||||
this->highlight_view = highlight_view;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ViewType>
|
||||
void FocusableItem<ViewType>::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<brls::Label> FocusableLabel;
|
||||
typedef FocusableItem<brls::Table> FocusableTable;
|
||||
}
|
||||
|
||||
#endif /* __FOCUSABLE_ITEM_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<nxdt::tasks::GameCardTask, nxdt::tasks::GameCardStatusEvent> 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;
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue