Nelarius / imnodes

A small, dependency-free node editor for dear imgui
MIT License
1.97k stars 241 forks source link

Selection API enhancement - modify programatically #106

Closed ekcoh closed 3 years ago

ekcoh commented 3 years ago

Awesome library and thanks for sharing/contributing. I find the API straightforward and intuitive but I ran into a problem related to selection when implementing a more flexible/serious UI.

The current API relating to selection is currently (if I haven't missed anything):

// Read (imnodes.h)
int NumSelectedNodes();
int NumSelectedLinks();
void GetSelectedNodes(int* node_ids);
void GetSelectedLinks(int* link_ids);

// Write (imnodes.h)
void ClearNodeSelection();
void ClearLinkSelection();

The issue I would like to discuss at the moment is the lack of possibility to set the selection from outside the translation unit imnodes.cpp. It would be very useful to be able to do this in order to do e.g. "Select All", "Select by id", "Invert selection" etc. in "user-code". Missing setters is also a bit inconsistent with the ClearXXXSelection methods since "write access" is already provided via "clear all" semantics. I see no added exposure by providing more fine-grained control.

Hence I propose the following changes:

If write operations on selections are available in the API, it also requires less "flag features" to be implemented as part of the library since each use-case might have different needs/opinions whether or what key-combinations or input device actions should actually lead to selection, clear selection etc. It might be beneficial to define this in "user-code" to not lock into a predefined behavior.

The linked PR f/selection_improvements contain an implementation proposal for above mentioned functionality.