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

Feature request: optional visitable metadata #15

Open
NikolausDemmel opened this issue Feb 27, 2019 · 2 comments
Open

Feature request: optional visitable metadata #15

NikolausDemmel opened this issue Feb 27, 2019 · 2 comments

Comments

@NikolausDemmel
Copy link

I'm using visit_struct to declare structs with parameters and automatically link specific option values to GUI widgets. It works great for simple cases.

However, more often than not I would like to define additional metadata where I specify the options in the struct. For example for numeric options, I would like to specify a range with minimum and maximum acceptable value, such that a slider with the correct limits can be created in the GUI.

I'm currently working around this by using some custom types for the struct member variables, e.g.

template <class T>
struct ranged {
  using ValueType = T;
  T val {0};
  const T min {0};
  const T max {100};
};

struct Foo {

    BEGIN_VISITABLES(Foo);

    VISITABLE_INIT(bool, foo, true);
    VISITABLE_DIRECT_INIT(ranged<double>, bar, {0.5, 0, 1});
    END_VISITABLES;

};

However this is a bit awkward, as a I have to access the actual value always via the val member.

Foo foo;
foo.bar.val = 0.1;

Would it be possible to extend visit_struct to allow declaring additional (typed) meta-data for every member in such a way, that it is transparent (i.e. foo.bar refers to the actual value, not some enclosing struct containing also the metadata), and it is (optionally) accessible during visitation.

I guess for my use-cases I so far only need constant meta-data.

I'm mostly interested in the intrusive syntax, since I want to define "all in one place", but one might also consider adding metadata to existing structs with a non-intrusive syntax.

@cbeck88
Copy link
Owner

cbeck88 commented Mar 17, 2020

i will think about this, sorry i didn't respond already

@NikolausDemmel
Copy link
Author

No worries.

In the meantime I am using a customized solution specific to my application. As it stands it's not very general, but I'm quite happy with it.

Just for some inspiration, the syntax looks something like this:

struct FooOptions : public VisitableOptions<FooOptions> {

  VISITABLE_OPTIONS_DEFAULT_META(readonly());

  BEGIN_VISITABLES(FooOptions);

  VISITABLE_META(int, bar, init(3).range(1, 100).help("foos the bar"));
  VISITABLE_META(BazEnum, baz, init(BazEnum::Baz1));
  VISITABLE_META(double, quux, init(1e2).range(1e-10, 1e10).logscale());
  VISITABLE_META_DEFAULT(std::string, quax));
  VISITABLE_META(QuuzFlags, quuz_flags, init(QuuzFlag::Quuz23 | QuuzFlag::Quuz42));
  VISITABLE_META(bool, corge, init(false).readonly(false));
  VISITABLE_META(std::vector<int>, grault, init({42, 23, 7}).readonly(false));

  END_VISITABLES;
}

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

No branches or pull requests

2 participants