rive-app / rive-cpp-legacy

C++ runtime for Rive
MIT License
287 stars 43 forks source link

Expose instances directly #247

Closed mikerreed closed 2 years ago

mikerreed commented 2 years ago

Make the 'default' way to use our public API be to use instances.

To achieve this, provide a way for clients iterate and find instances (artboards, animations, statemachines) without ever having to first use a "raw" object (i.e. the non-instance variants).

  1. Add ways to see all the names (already have ways to count items)

std::string File::artboardNameAt(index) std::string Artboard::animationNameAt(index) std::string Artboard::stateMachineNameAt(index)

  1. Add ways to create instances directly

std::unique_ptr File::artboardDefault() std::unique_ptr File::artboardAt(index) std::unique_ptr File::artboardNamed(name)

std::unique_ptr ArtboardInstance::animationDefault() std::unique_ptr ArtboardInstance::animation(index) std::unique_ptr ArtboardInstance::animationNamed(name)

std::unique_ptr ArtboardInstance::stateMachineDefault() std::unique_ptr ArtboardInstance::stateMachineAt(index) std::unique_ptr ArtboardInstance::stateMachineNamed(name)

  1. (TODO) -- update our high-level wrappers to take advantage of this simplification

Don't expose the "raw" variants, only the instances. This reduce the size of our API, making it simpler.

luigi-rosso commented 2 years ago

I think this is a great idea! It'll drive us more and more towards defining a default state/config from the editor. Which is what we want long term anyway.

csmartdalton commented 2 years ago

This looks like a great simplification to me!

Does artboardDefault() always return a value now? I recall trying to draw some riv files in the past that didn't appear to have a default animation.

mikerreed commented 2 years ago

Should return something, or null if there are zero items -- if you have a riv that returned null, let's double check that it actually had the thing you're looking for