From bd4f79646f623e929e6aa22bea028952b515aeef Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 12 Jan 2023 10:30:10 -0500 Subject: Add general string hint interface This replaces the window title and class name APIs with a more general one that can be easily extended to other things, like icon names, more detailed application hints, and so on. --- src/common.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 13 deletions(-) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index 7113461..eafb07a 100644 --- a/src/common.c +++ b/src/common.c @@ -52,7 +52,7 @@ puglNewWorld(PuglWorldType type, PuglWorldFlags flags) world->startTime = puglGetTime(world); world->type = type; - puglSetString(&world->className, "Pugl"); + puglSetString(&world->strings[PUGL_CLASS_NAME], "Pugl"); return world; } @@ -61,7 +61,11 @@ void puglFreeWorld(PuglWorld* const world) { puglFreeWorldInternals(world); - free(world->className); + + for (size_t i = 0; i < PUGL_NUM_STRING_HINTS; ++i) { + free(world->strings[i]); + } + free(world->views); free(world); } @@ -79,16 +83,26 @@ puglGetWorldHandle(PuglWorld* world) } PuglStatus -puglSetClassName(PuglWorld* const world, const char* const name) +puglSetWorldString(PuglWorld* const world, + const PuglStringHint key, + const char* const value) { - puglSetString(&world->className, name); + if ((unsigned)key < 0 || (unsigned)key >= PUGL_NUM_STRING_HINTS) { + return PUGL_BAD_PARAMETER; + } + + puglSetString(&world->strings[key], value); return PUGL_SUCCESS; } const char* -puglGetClassName(const PuglWorld* world) +puglGetWorldString(const PuglWorld* const world, const PuglStringHint key) { - return world->className; + if ((unsigned)key < 0 || (unsigned)key >= PUGL_NUM_STRING_HINTS) { + return NULL; + } + + return world->strings[key]; } static void @@ -161,7 +175,10 @@ puglFreeView(PuglView* view) } } - free(view->title); + for (size_t i = 0; i < PUGL_NUM_STRING_HINTS; ++i) { + free(view->strings[i]); + } + puglFreeViewInternals(view); free(view); } @@ -239,6 +256,29 @@ puglGetViewHint(const PuglView* view, PuglViewHint hint) return PUGL_DONT_CARE; } +PuglStatus +puglSetViewString(PuglView* const view, + const PuglStringHint key, + const char* const value) +{ + if ((unsigned)key < 0 || (unsigned)key >= PUGL_NUM_STRING_HINTS) { + return PUGL_BAD_PARAMETER; + } + + puglSetString(&view->strings[key], value); + return puglViewStringChanged(view, key, view->strings[key]); +} + +const char* +puglGetViewString(const PuglView* const view, const PuglStringHint key) +{ + if ((unsigned)key < 0 || (unsigned)key >= PUGL_NUM_STRING_HINTS) { + return NULL; + } + + return view->strings[key]; +} + PuglRect puglGetFrame(const PuglView* view) { @@ -267,12 +307,6 @@ puglGetFrame(const PuglView* view) return frame; } -const char* -puglGetWindowTitle(const PuglView* const view) -{ - return view->title; -} - PuglStatus puglSetParentWindow(PuglView* view, PuglNativeView parent) { -- cgit v1.2.1