Search code examples
cfunctionpebble-watchshorthandpebble-sdk

Can someone explain part of this code found in the Pebble C Watchface tutorial?


I'm looking into the Pebble C watch face tutorial found here https://developer.getpebble.com/tutorials/watchface-tutorial/part1

The part of code in question is here:

static void init() {
  // Create main Window element and assign to pointer
  s_main_window = window_create();

  // Set handlers to manage the elements inside the Window
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });

  // Show the Window on the watch, with animated=true
  window_stack_push(s_main_window, true);
}

Is window_set_window_handlers a function declaration and call? And what is the terminology for the .load and .unload shorthand notation in C?

Would greatly appreciate if someone could possibly explain that snippet of code, thanks.


Solution

  • It's called Designated Initializers. The struct WindowHandlers is created and initialized inline before being passed to the function call of window_set_window_handlers.