aboutsummaryrefslogtreecommitdiff
path: root/options.c
diff options
context:
space:
mode:
authorneonloop2021-08-04 18:30:43 +0000
committerneonloop2021-08-04 18:30:43 +0000
commit9fc540857834d4edaa9afbf2937f2f3c9f2e3202 (patch)
tree02526718d21ffd1c838de1f8631f651a3a460412 /options.c
parent0addef625ae5525bc32c3e998ad2d21c1ff892c3 (diff)
downloadpicoarch-9fc540857834d4edaa9afbf2937f2f3c9f2e3202.tar.gz
picoarch-9fc540857834d4edaa9afbf2937f2f3c9f2e3202.tar.bz2
picoarch-9fc540857834d4edaa9afbf2937f2f3c9f2e3202.zip
Wraps core option info lines
Diffstat (limited to 'options.c')
-rw-r--r--options.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/options.c b/options.c
index 92918d4..2bac4b1 100644
--- a/options.c
+++ b/options.c
@@ -14,6 +14,8 @@ enum scale_filter scale_filter;
struct core_options core_options;
#define MAX_DESC_LEN 20
+#define MAX_LINE_LEN 52
+#define MAX_LINES 3
static void truncate(char *string, int max_len) {
size_t len = strlen(string) + 1;
@@ -22,6 +24,29 @@ static void truncate(char *string, int max_len) {
strncpy(&string[max_len - 4], "...\0", 4);
}
+static void wrap(char *string, size_t max_len, size_t max_lines) {
+ char *line = string;
+
+ for (int i = 1; i < max_lines; i++) {
+ char *p = line;
+ char *prev;
+ do {
+ prev = p;
+ p = strchr(prev+1, ' ');
+ } while (p && p - line < max_len);
+
+ if (!p && strlen(line) < max_len) break;
+
+ if (prev && prev != line) {
+ line = prev + 1;
+ *prev = '\n';
+ }
+ }
+ truncate(line, max_len);
+
+ return;
+}
+
static const char *blocked_options[] = { "gpsp_save_method", NULL};
static bool option_blocked(const char *key) {
@@ -65,7 +90,6 @@ void options_init(const struct retro_core_option_definition *defs) {
entry->def = &core_options.defs[i];
entry->value = options_default_index(entry->def->key);
entry->prev_value = entry->value;
- entry->info = entry->def->info;
entry->blocked = option_blocked(entry->def->key);
if (entry->blocked)
core_options.visible_len--;
@@ -81,6 +105,16 @@ void options_init(const struct retro_core_option_definition *defs) {
strncpy(entry->desc, entry->def->desc, len);
truncate(entry->desc, MAX_DESC_LEN);
+ len = strlen(entry->def->info) + 1;
+ entry->info = (char *)calloc(len, sizeof(char));
+ if (!entry->info) {
+ PA_ERROR("Error allocating description string\n");
+ options_free();
+ return;
+ }
+ strncpy(entry->info, entry->def->info, len);
+ wrap(entry->info, MAX_LINE_LEN, MAX_LINES);
+
for (j = 0; entry->def->values[j].value; j++)
;
j++; /* Make room for NULL entry */