Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Theming #57

Merged
merged 11 commits into from
Sep 13, 2018
Merged

Implement Theming #57

merged 11 commits into from
Sep 13, 2018

Conversation

friedkeenan
Copy link
Contributor

This fixes issue #6.

You can check out the binary and an example of a theme here.

Like the readme says, you just put the hbtheme.cfg file on the root of the SD card to use a theme. If there are any problems with that file or if it doesn't exist at all, it will just use the default themes.

My C knowledge is super shallow, and I'm not sure if my coding style matches up with yours all the time (I tried my best), so the code probably isn't that good, but it's something. You probably also want to move the theming info in the readme to http://switchbrew.org/index.php/Homebrew_Menu

Now requires libconfig
"separator" was spelled "seperator"
@yellows8
Copy link
Collaborator

yellows8 commented Sep 9, 2018

:D

README.md Outdated
#### Usage
See [Homebrew_Applications](http://switchbrew.org/index.php?title=Homebrew_Applications) for SD layout and applications, etc. See [Switchbrew](http://switchbrew.org/index.php?title=Homebrew_Menu) for hbmenu docs.

#### Download
The latest release is available from the [releases](https://github.com/switchbrew/nx-hbmenu/releases/latest) page.
The latest release is available from the [releases](https://github.com/friedkeenan/nx-hbmenu/releases/latest) page.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

@yellows8
Copy link
Collaborator

yellows8 commented Sep 9, 2018

Use same spacing style as elsewhere, not tabs.

@yellows8
Copy link
Collaborator

yellows8 commented Sep 9, 2018

Settings not specified in the config should be loaded from the default theme config.

README.md Outdated
@@ -1,8 +1,11 @@
#### Theming
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this too, can be moved to wiki later.

common/theme.c Outdated
if(rgba==NULL)
return MakeColor(128,0,128,255);
return MakeColor(config_setting_get_int_elem(rgba, 0), config_setting_get_int_elem(rgba, 1), config_setting_get_int_elem(rgba, 2), config_setting_get_int_elem(rgba, 3));
}
void themeStartup(ThemePreset preset) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert newline

common/theme.c Outdated
//.buttonBImage = button_b_light_bin,
.hbmenuLogoImage = hbmenu_logo_light_bin
};
}
break;

case THEME_PRESET_DARK:
Copy link
Collaborator

@yellows8 yellows8 Sep 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate code, same code should be used for light/dark.

I tried to remove as much duplicate code as I think I can

Also missing settings in the hbtheme.cfg file will now be supplemented by the default values
@friedkeenan
Copy link
Contributor Author

friedkeenan commented Sep 10, 2018

I'm sorry, I'm not sure what you mean. I get the colors and stuff from the default themes with the "{themename}." prefix, and I get the children from "theme" using the config functions because it's loaded from the config file. Do you want a default config file included?

EDIT: Wait no, I get what you mean. use config_setting_lookup so I don't have to hardcode lightTheme and darkTheme

README.md Outdated
@@ -11,3 +11,4 @@ Build with ```make nx``` or just run ```make```.

* This uses code based on 3DS [new-hbmenu](https://github.com/fincs/new-hbmenu).
* [nanojpeg](https://svn.emphy.de/nanojpeg/trunk/nanojpeg/nanojpeg.c) is used for handling JPEG icons. This library doesn't support lossless JPEG.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

@yellows8
Copy link
Collaborator

Looks better now. :)

common/theme.c Outdated
//.buttonBImage = button_b_light_bin,
.hbmenuLogoImage = hbmenu_logo_light_bin
};
theme_t themeDark = (theme_t) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert newline

common/theme.c Outdated
//.buttonBImage = button_b_dark_bin,
.hbmenuLogoImage = hbmenu_logo_dark_bin
};
theme_t *themeDefault;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert newline

common/theme.c Outdated
color_t text, frontWave, middleWave, backWave, background, highlight, separator;
int waveBlending;
const char *AText, *BText;
bool good_cfg=config_read_file(cfg, "/hbtheme.cfg");
switch (preset) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert newline

common/theme.c Outdated
//.buttonBImage = button_b_light_bin,
.hbmenuLogoImage = hbmenu_logo_light_bin
};
themeDefault = &themeLight;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert: "default:"

common/theme.c Outdated
theme = config_lookup(cfg, "darkTheme");
break;
}
if (good_cfg){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert newline

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

") {"

common/theme.c Outdated Show resolved Hide resolved
The default case acts like the system theme is the dark one, because who really use the light theme?
@friedkeenan
Copy link
Contributor Author

Dang, didn't even know that was a thing

common/theme.c Outdated
};

theme_t *themeDefault;
config_t *cfg = NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store on stack. "config_t cfg = {0};"

Cleanup once finished using it via config_destory is also missing.

common/theme.c Outdated
color_t text, frontWave, middleWave, backWave, background, highlight, separator;
int waveBlending;
const char *AText, *BText;
bool good_cfg=config_read_file(&cfg, "/hbtheme.cfg");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces around =.

//.buttonBImage = button_b_dark_bin,
.hbmenuLogoImage = hbmenu_logo_dark_bin
};

Copy link
Collaborator

@yellows8 yellows8 Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add:

char tmp_path[PATH_MAX] = {0};

#ifdef __SWITCH__
tmp_path[0] = '/';
#endif

strncat(tmp_path, "config/nx-hbmenu/themes/theme.cfg", sizeof(tmp_path)-2);

Then use that string for config_read_file.

EDIT: code updated

@yellows8
Copy link
Collaborator

Can you comment with a link to a gist which contains a sample cfg file, which can be moved to switchbrew later?

@friedkeenan
Copy link
Contributor Author

https://gist.github.com/friedkeenan/14dec59d01410a7fcf40a324be70efcf

I can add comments to give more information if you want

@yellows8
Copy link
Collaborator

ping @ code change

It will load from "config/nx-hbmenu/themes/theme.cfg" if you're using the PC version
@friedkeenan
Copy link
Contributor Author

Yeah, I was just testing it and making sure I knew what the code was actually doing

@yellows8 yellows8 merged commit 8909142 into switchbrew:master Sep 13, 2018
@yellows8
Copy link
Collaborator

@friedkeenan
Copy link
Contributor Author

It looks good, except that if you comment out the enableWaveBlending line, it'll use the default, which is disabled, so you have to do enableWaveBlending=1; to enable it

@yellows8
Copy link
Collaborator

fixed

@friedkeenan
Copy link
Contributor Author

Looks fine now, thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants