-
Notifications
You must be signed in to change notification settings - Fork 129
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] Seed id hash with parent's id #26
Comments
Hello! Firstly, I completely agree with your assertion that we need a local context-aware way to auto generate IDs. At present it's quite painful to have to uniquely everything in the hierarchy, even for immediate mode renderers where it's almost entirely unnecessary. I'll merge your PR in the short term to address that particular problem. Secondly given that you've dug in here already, I'd like to get your opinion on an API change I'm working on at the moment. It replaces all the type-specific element macros with a single generic I specifically started this change to address the painful ergonomics of working on an interface where most elements needed a border and a rectangle. The main idea is that in the new api, all configs are optional, including ID and Layout, e.g: // Create an empty layout element with no children and the default layout config
CLAY()
// Create a scrolling element with a border and background
CLAY(CLAY_SCROLL(...etc), CLAY_BORDER(...etc), CLAY_RECTANGLE(...etc)) {
// ...children
}
// Tag a rectangle with a specific ID for mouse interactions, etc
CLAY(CLAY_ID("Button"), CLAY_RECTANGLE(...etc)) {
// ...children
} With the refactor being relevant to this situation because I'm planning to attach generated ids to each element if the user chooses not to provide one. It makes sense for the auto generated ID to be derived from the parent ID, and positional based on the sibling index. |
This was addressed in #27 but I will leave it open until I've updated the |
Since the user can pick a combination of features, how about having just one type: CLAY(
CLAY_SCROLL(...), // Enable scrolls
CLAY_BORDER(...), // Enable border
) {
} The API is essentially the same but the implementation is different. if (cmd.has_border) {
// draw border
}
if (cmd.has_background) {
// draw solid background
} The macro There would be fewer elements to name or inspect. Maybe scroll is somewhat special but image, rect, border and (plain) container are just decorations and styles. Another radical idea about id: Given that local id seems to be more prevalent, how about make it the default ( |
Yep, you're describing pretty much my exact line of thinking - a single macro that can be configured with whichever features. There is a little internal work to do to support this but it shouldn't take too long.
Yes, I'm very much thinking along the same lines. I want it to be obvious when an element is tagged with a global ID for a reason - it's used for click handling etc. I actually would prefer if the IDs were local internally, but mostly auto generated. e.g. if you don't specify an ID at all: CLAY_ELEMENT(CLAY_SCROLL(), CLAY_RECTANGLE()) { // Automatically assigned CLAY_ID_LOCAL("0")
CLAY_ELEMENT() // Automatically assigned CLAY_ID_LOCAL("0")
CLAY_ELEMENT() // Automatically assigned CLAY_ID_LOCAL("1")
CLAY_ELEMENT() // Automatically assigned CLAY_ID_LOCAL("2")
CLAY_ELEMENT() // Automatically assigned CLAY_ID_LOCAL("3")
CLAY_ELEMENT(CLAY_TAG("ClickableButton")) {} // ID is already specified with a global so no local ID is attached
} This way IDs would be internally be represented by trees of parent -> sibling index, i.e. a local id might end up being equivalent to |
Currently, element id needs to be globally unique.
Copy&paste or refactoring reusable components into functions would be a bit of a pain since you'd need to parameterize all the ids.
What if the id only has to be unique among siblings?
Clay__Rehash
already exists but it is only used for debugger.The fact that it exists mean that kind of id is useful.
CLAY_ID_AUTO
on the other hand, does not allow providing a string and counter which are needed to identify elements independent of orders.e.g: In a list of items.
There are 2 ways of doing this:
Make
CLAY_ID
andCLAY_IDI
context-dependent.This might break some existing code.
Floating attachment may be a bit harder but there are workarounds like saving the id into a variable first.
Alternatively, provide
CLAY_LOCAL_ID
andCLAY_LOCAL_IDI
which takes the parent id as seed.Alternate names:
CLAY_CTX_ID[I]
: context dependent idCLAY_SCOPED_ID[I]
I can make PR for either of these.
The text was updated successfully, but these errors were encountered: