Skip to content

Implement optional item names #17

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ typedef struct lay_item_t {
lay_id next_sibling;
lay_vec4 margins;
lay_vec2 size;
#ifdef LAY_USE_NAMES
const char *name;
#endif // LAY_USE_NAMES
} lay_item_t;

typedef struct lay_context {
Expand Down Expand Up @@ -334,6 +337,11 @@ LAY_EXPORT void lay_append(lay_context *ctx, lay_id earlier, lay_id later);
// of as the last.
LAY_EXPORT void lay_push(lay_context *ctx, lay_id parent, lay_id child);

#ifdef LAY_USE_NAMES
LAY_EXPORT const char *lay_get_name(lay_context *ctx, lay_id item);
LAY_EXPORT void lay_set_name(lay_context *ctx, lay_id item, const char *name);
#endif // LAY_USE_NAMES

// Gets the size that was set with lay_set_size or lay_set_size_xy. The _xy
// version writes the output values to the specified addresses instead of
// returning the values in a lay_vec2.
Expand Down Expand Up @@ -667,6 +675,20 @@ void lay_push(lay_context *ctx, lay_id parent, lay_id new_child)
pchild->next_sibling = old_child;
}

#ifdef LAY_USE_NAMES
const char *lay_get_name(lay_context *ctx, lay_id item)
{
lay_item_t *pitem = lay_get_item(ctx, item);
return pitem->name;
}

void lay_set_name(lay_context *ctx, lay_id item, const char *name)
{
lay_item_t *pitem = lay_get_item(ctx, item);
pitem->name = name;
}
#endif // LAY_USE_NAMES

lay_vec2 lay_get_size(lay_context *ctx, lay_id item)
{
lay_item_t *pitem = lay_get_item(ctx, item);
Expand Down