Add dark icon property

This commit is contained in:
GenevensiS
2025-12-05 13:36:09 +01:00
parent 039a9c5b34
commit 04a3289755
10 changed files with 118 additions and 84 deletions
+1
View File
@@ -52,6 +52,7 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT_LOCALIZED(caption);
REFLECT_LOCALIZED(description); // FIXME: This field is both unused and uninitialized.
REFLECT_N("icon", icon_filename);
REFLECT_N("dark_icon", dark_icon_filename);
REFLECT(editable);
REFLECT(save_value);
REFLECT(show_statistics);
+1
View File
@@ -48,6 +48,7 @@ public:
LocalizedString caption; ///< Caption for NativeLookEditor
LocalizedString description; ///< Description, used in status bar
String icon_filename; ///< Filename for an icon (for list of fields)
String dark_icon_filename; ///< Filename for an icon (for list of fields) when a variant for dark mode is necessary
bool editable; ///< Can values of this field be edited?
bool save_value; ///< Should values of this field be written to files? Can be false for script generated fields.
bool show_statistics; ///< Should this field appear as a group by choice in the statistics panel?
+11 -4
View File
@@ -37,16 +37,21 @@ IMPLEMENT_REFLECTION(Installer) {
void Installer::validate(Version file_app_version) {
Packaged::validate(file_app_version);
// load icons where possible
FOR_EACH(p,packages) {
if (!p->icon_url.empty() && !starts_with(p->icon_url,_("http:"))) {
FOR_EACH(p,packages) {
String url = p->icon_url;
if (settings.darkMode() && !p->dark_icon_url.empty()) {
url = p->dark_icon_url;
}
if (!url.empty() && !starts_with(url,_("http:"))) {
// TODO: support absolute icon names
try{
String filename = p->name + _("/") + p->icon_url;
auto img_stream = openIn(p->name + _("/") + p->icon_url);
String filename = p->name + _("/") + url;
auto img_stream = openIn(p->name + _("/") + url);
image_load_file(p->icon, *img_stream);
} catch (...) {
// ignore errors, it's just an image
p->icon_url.clear();
p->dark_icon_url.clear();
}
}
}
@@ -202,6 +207,7 @@ PackageDescription::PackageDescription(const Packaged& package)
, short_name(package.short_name)
, full_name(package.full_name)
, icon_url(package.icon_filename)
, dark_icon_url(package.dark_icon_filename)
, installer_group(package.installer_group)
, position_hint(package.position_hint)
//, description(package.description)
@@ -237,6 +243,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(PackageDescription) {
REFLECT(short_name);
REFLECT(full_name);
REFLECT(icon_url);
REFLECT(dark_icon_url);
REFLECT(installer_group);
REFLECT(position_hint);
REFLECT(description);
+11 -10
View File
@@ -60,16 +60,17 @@ public:
PackageDescription();
PackageDescription(const Packaged& package);
String name; ///< Filename of the package
Version version; ///< Version number of this package
String short_name; ///< Short name of this package
String full_name; ///< Name of this package, for menus etc.
String icon_url; ///< Filename or URL of icon to use in package lists
Image icon; ///< Icon for the package
String installer_group; ///< Where to put this package in the installer
int position_hint; ///< A hint for the package list
String description; ///< Changelog/description
vector<PackageDependencyP> dependencies; ///< Dependencies of this package
String name; ///< Filename of the package
Version version; ///< Version number of this package
String short_name; ///< Short name of this package
String full_name; ///< Name of this package, for menus etc.
String icon_url; ///< Filename or URL of icon to use in package lists
String dark_icon_url; ///< Filename or URL of icon to use in package lists
Image icon; ///< Icon for the package
String installer_group; ///< Where to put this package in the installer
int position_hint; ///< A hint for the package list
String description; ///< Changelog/description
vector<PackageDependencyP> dependencies; ///< Dependencies of this package
/// Merge two descriptions a package. This package takes precedence
/** Usually one of the descriptions will refer to the locally installed one, the other to the new one */
+28 -24
View File
@@ -16,23 +16,24 @@ extern ScriptValueP script_primary_choice;
// ----------------------------------------------------------------------------- : Statistics dimension
StatsDimension::StatsDimension()
: automatic (false)
, position_hint(0)
, numeric (false)
, bin_size (0)
, show_empty (false)
, split_list (false)
: automatic (false)
, position_hint (0)
, numeric (false)
, bin_size (0)
, show_empty (false)
, split_list (false)
{}
StatsDimension::StatsDimension(const Field& field)
: automatic (true)
, name (field.name)
, description (field.description)
, position_hint(field.position_hint)
, icon_filename(field.icon_filename)
, numeric (false)
, show_empty (false)
, split_list (false)
: automatic (true)
, name (field.name)
, description (field.description)
, position_hint (field.position_hint)
, icon_filename (field.icon_filename)
, dark_icon_filename (field.dark_icon_filename)
, numeric (false)
, show_empty (false)
, split_list (false)
{
// choice field?
const ChoiceField* choice_field = dynamic_cast<const ChoiceField*>(&field);
@@ -67,6 +68,7 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
REFLECT_LOCALIZED(description);
REFLECT(position_hint);
REFLECT_N("icon", icon_filename);
REFLECT_N("dark_icon", dark_icon_filename);
REFLECT(script);
REFLECT(global_script);
REFLECT(numeric);
@@ -81,19 +83,20 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
// ----------------------------------------------------------------------------- : Statistics category
StatsCategory::StatsCategory()
: automatic(false)
, position_hint(0)
, type(GRAPH_TYPE_BAR)
: automatic (false)
, position_hint (0)
, type (GRAPH_TYPE_BAR)
{}
StatsCategory::StatsCategory(const StatsDimensionP& dim)
: automatic(true)
, name (dim->name)
, description (dim->description)
, position_hint(dim->position_hint)
, icon_filename(dim->icon_filename)
, dimensions(1, dim)
, type(GRAPH_TYPE_BAR)
: automatic (true)
, name (dim->name)
, description (dim->description)
, position_hint (dim->position_hint)
, icon_filename (dim->icon_filename)
, dark_icon_filename (dim->dark_icon_filename)
, dimensions (1, dim)
, type (GRAPH_TYPE_BAR)
{}
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) {
@@ -102,6 +105,7 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) {
REFLECT_LOCALIZED(description);
REFLECT(position_hint);
REFLECT_N("icon", icon_filename);
REFLECT_N("dark_icon", dark_icon_filename);
REFLECT(type);
REFLECT_N("dimensions", dimension_names);
}
+25 -23
View File
@@ -27,20 +27,21 @@ public:
StatsDimension();
StatsDimension(const Field&);
const bool automatic; ///< Based on a card field?
String name; ///< Name of this dimension
LocalizedString description; ///< Description, used in status bar
int position_hint; ///< Hint for the ordering
String icon_filename; ///< Icon for lists
Bitmap icon; ///< The loaded icon (optional of course)
OptionalScript script; ///< Script that determines the value(s), ran on each card
OptionalScript global_script; ///< Script that determines the value(s), ran only once at the start
bool numeric; ///< Are the values numeric? If so, they require special sorting
double bin_size; ///< Bin adjecent numbers?
bool show_empty; ///< Should "" be shown?
bool split_list; ///< Split values into multiple ones separated by commas
map<String,Color> colors; ///< Colors for the categories
vector<String> groups; ///< Order of the items
const bool automatic; ///< Based on a card field?
String name; ///< Name of this dimension
LocalizedString description; ///< Description, used in status bar
int position_hint; ///< Hint for the ordering
String icon_filename; ///< Icon for lists
String dark_icon_filename; ///< Icon for lists, if a variant for dark mode is needed
Bitmap icon; ///< The loaded icon (optional of course)
OptionalScript script; ///< Script that determines the value(s), ran on each card
OptionalScript global_script; ///< Script that determines the value(s), ran only once at the start
bool numeric; ///< Are the values numeric? If so, they require special sorting
double bin_size; ///< Bin adjecent numbers?
bool show_empty; ///< Should "" be shown?
bool split_list; ///< Split values into multiple ones separated by commas
map<String,Color> colors; ///< Colors for the categories
vector<String> groups; ///< Order of the items
DECLARE_REFLECTION();
};
@@ -54,15 +55,16 @@ public:
StatsCategory();
StatsCategory(const StatsDimensionP&);
const bool automatic; ///< Automatically generated?
String name; ///< Name/label
LocalizedString description; ///< Description, used in status bar
int position_hint; ///< Hint for the ordering
String icon_filename; ///< Icon for lists
Bitmap icon; ///< The loaded icon (optional of course)
vector<String> dimension_names; ///< Names of the dimensions to use
vector<StatsDimensionP> dimensions; ///< Actual dimensions
GraphType type; ///< Type of graph to use
const bool automatic; ///< Automatically generated?
String name; ///< Name/label
LocalizedString description; ///< Description, used in status bar
int position_hint; ///< Hint for the ordering
String icon_filename; ///< Icon for lists
String dark_icon_filename; ///< Icon for lists when a variant for dark mode is needed
Bitmap icon; ///< The loaded icon (optional of course)
vector<String> dimension_names; ///< Names of the dimensions to use
vector<StatsDimensionP> dimensions; ///< Actual dimensions
GraphType type; ///< Type of graph to use
/// Initialize dimensions from dimension_names
void find_dimensions(const vector<StatsDimensionP>& available);