aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Fadel <samuel@nihil.ws>2023-06-05 13:34:27 +0200
committerSamuel Fadel <samuel@nihil.ws>2023-06-05 13:34:27 +0200
commit4f05d891f05a038bad7b911ce52d27e01b34f7cb (patch)
tree94af6ab205f72d0d716c616a857c5a22b4382f70
parent4ce1a7a6d0d9b6b2aaab1b502b878d616f378d1f (diff)
* main.cpp: Safer colormap/metric names.
-rw-r--r--main.cpp62
1 files changed, 30 insertions, 32 deletions
diff --git a/main.cpp b/main.cpp
index 0d5d8ab..39aa830 100644
--- a/main.cpp
+++ b/main.cpp
@@ -55,9 +55,23 @@ static const int MAX_ELEMENT_MEMORY = 128 * 1024;
#include "brushinghandler.h"
static const int RNG_SEED = 123;
-static const int WINDOW_WIDTH = 1200;
+static const int WINDOW_WIDTH = 1000;
static const int WINDOW_HEIGHT = 800;
+
+static const std::vector<std::string> COLORMAP_NAMES{
+ "Categorical",
+ "Continuous",
+ "Divergent",
+ "Rainbow",
+};
+
+static const std::vector<std::string> METRIC_NAMES{
+ "Aggregate error",
+ "Ctrl. Pt. influence",
+ "Stress",
+};
+
struct media {
struct nk_font *font_14;
struct nk_font *font_18;
@@ -387,21 +401,6 @@ public:
ColorScaleRainbow
};
- static constexpr const char *colormapItemNames[] = {
- "Categorical",
- "Continuous",
- "Divergent",
- "Rainbow",
- nullptr,
- };
-
- static constexpr const char *metricItemNames[] = {
- "Aggregate error",
- "Ctrl. Pt. influence",
- "Stress",
- nullptr,
- };
-
void setCPColorScale(ColorScaleType colorScaleType) {
float min = 0.0f;
float max = 1.0f;
@@ -1078,13 +1077,13 @@ int main(int argc, char *argv[])
nk_layout_row_push(&ctx, 0.3f);
nk_label(&ctx, "Scale:", NK_TEXT_RIGHT);
nk_layout_row_push(&ctx, 0.7f);
- if (nk_combo_begin_label(&ctx, Main::colormapItemNames[cpColorScaleType],
+ if (nk_combo_begin_label(&ctx, COLORMAP_NAMES[cpColorScaleType].c_str(),
nk_vec2(nk_widget_width(&ctx), 200))) {
nk_layout_row_dynamic(&ctx, 25, 1);
size_t i = 0;
- for (const char * const *name = &Main::colormapItemNames[0];
- *name != nullptr; name++) {
- if (nk_combo_item_label(&ctx, *name, NK_TEXT_LEFT)) {
+ for (auto it = COLORMAP_NAMES.begin();
+ it != COLORMAP_NAMES.end(); it++) {
+ if (nk_combo_item_label(&ctx, it->c_str(), NK_TEXT_LEFT)) {
enum Main::ColorScaleType type = static_cast<Main::ColorScaleType>(i);
if (type != cpColorScaleType) {
m.setCPColorScale(type);
@@ -1101,13 +1100,13 @@ int main(int argc, char *argv[])
nk_layout_row_push(&ctx, 0.3f);
nk_label(&ctx, "Map to:", NK_TEXT_RIGHT);
nk_layout_row_push(&ctx, 0.7f);
- if (nk_combo_begin_label(&ctx, Main::metricItemNames[0],
+ if (nk_combo_begin_label(&ctx, METRIC_NAMES[0].c_str(),
nk_vec2(nk_widget_width(&ctx), 200))) {
nk_layout_row_dynamic(&ctx, 25, 1);
size_t i = 0;
- for (const char * const *name = &Main::metricItemNames[0];
- *name != nullptr; name++) {
- if (nk_combo_item_label(&ctx, *name, NK_TEXT_LEFT)) {
+ for (auto it = METRIC_NAMES.begin();
+ it != METRIC_NAMES.end(); it++) {
+ if (nk_combo_item_label(&ctx, it->c_str(), NK_TEXT_LEFT)) {
// TODO
}
i++;
@@ -1159,13 +1158,13 @@ int main(int argc, char *argv[])
nk_layout_row_push(&ctx, 0.3f);
nk_label(&ctx, "Scale:", NK_TEXT_RIGHT);
nk_layout_row_push(&ctx, 0.7f);
- if (nk_combo_begin_label(&ctx, Main::colormapItemNames[rpColorScaleType],
+ if (nk_combo_begin_label(&ctx, COLORMAP_NAMES[rpColorScaleType].c_str(),
nk_vec2(nk_widget_width(&ctx), 200))) {
nk_layout_row_dynamic(&ctx, 25, 1);
size_t i = 0;
- for (const char * const *name = &Main::colormapItemNames[0];
- *name != nullptr; name++) {
- if (nk_combo_item_label(&ctx, *name, NK_TEXT_LEFT)) {
+ for (auto it = COLORMAP_NAMES.begin();
+ it != COLORMAP_NAMES.end(); it++) {
+ if (nk_combo_item_label(&ctx, it->c_str(), NK_TEXT_LEFT)) {
enum Main::ColorScaleType type = static_cast<Main::ColorScaleType>(i);
if (type != rpColorScaleType) {
m.setRPColorScale(type);
@@ -1182,13 +1181,12 @@ int main(int argc, char *argv[])
nk_layout_row_push(&ctx, 0.3f);
nk_label(&ctx, "Map to:", NK_TEXT_RIGHT);
nk_layout_row_push(&ctx, 0.7f);
- if (nk_combo_begin_label(&ctx, Main::metricItemNames[0],
+ if (nk_combo_begin_label(&ctx, METRIC_NAMES[0].c_str(),
nk_vec2(nk_widget_width(&ctx), 200))) {
nk_layout_row_dynamic(&ctx, 25, 1);
size_t i = 0;
- for (const char * const *name = &Main::metricItemNames[0];
- *name != nullptr; name++) {
- if (nk_combo_item_label(&ctx, *name, NK_TEXT_LEFT)) {
+ for (auto it = METRIC_NAMES.begin(); it != METRIC_NAMES.end(); it++) {
+ if (nk_combo_item_label(&ctx, it->c_str(), NK_TEXT_LEFT)) {
// TODO
}
i++;