Skip to main content

GUI Panel Operations

Source: qar-streaming-c/examples/gui_panel_operations.c. Conceptual background: Custom GUI Panels.

GUI Panel Operations

Overview

  • Obtain a session (rejoin, or onboard with the hub pairing code)
  • Get-or-create a GUI panel by its stable common name
  • Adjust pose, size, state, and navigate to content
  • Enumerate GUI panels to inspect current values

Prerequisites

  • Complete the App Volume Management tutorial
  • A running QarOS hub (for the first run, read the pairing code off its onboarding screen)

Build and Run

 cmake --build --preset x64-windows-debug --target gui_panel_operations
 ./build/x64-windows/Debug/gui_panel_operations.exe
 <path-to-qar-streaming-c.dll> [runtime-dir] [pairing-code]

Parse Arguments

  if(argc < 2)
  {
  print_usage(argv[0]);
  return 1;
  }
 
  const char* library_path = argv[1];
  const char* runtime_dir = NULL;
  char runtime_dir_buffer[1024] = { 0 };
 
  if(argc >= 3)
  {
  runtime_dir = argv[2];
  }
  else if(get_dir_from_path(
  library_path, runtime_dir_buffer, sizeof(runtime_dir_buffer)
  ))
  {
  runtime_dir = runtime_dir_buffer;
  }
 
  const char* pairing_code = (argc >= 4) ? argv[3] : NULL;

Set Up the Session

The session is obtained with the shared rejoin-or-onboard helper described in the Onboarding and Rejoin tutorial.

  if(!qar_library_load(library_path))
  {
  fprintf(stderr, "Failed to load '%s'.\n", library_path);
  return 2;
  }
 
  library_init.enable_console_logging = true;
  QarResult library_result = qar_library_init(&library_init);
  if(qar_result_is_error(library_result))
  {
  log_result("qar_library_init", library_result);
  return 3;
  }
 
  QarRuntime* runtime = NULL;
  runtime_init.runtime_binaries_folder_path = runtime_dir;
  QarResult runtime_result = qar_runtime_create(&runtime_init, &runtime);
  if(qar_result_is_error(runtime_result) || runtime == NULL)
  {
  log_result("qar_runtime_create", runtime_result);
  return 4;
  }
 
  QarSession* session = NULL;
  runtime,
  pairing_code,
  "gui_panel_operations.onboarding-id.txt",
  "GUI Panel Peer",
  &onboarding_id,
  &session
  ) != 0
  || session == NULL)
  {
  qar_runtime_destroy(runtime);
  return 5;
  }

Create and Update the Panel

  panel_init.common_name = "tutorial-panel.examples.qaros";
  panel_init.display_name = "Tutorial Panel";
  panel_init.pose = qar_pose_default();
  panel_init.pose.position.x = 0.5f;
  panel_init.pose.position.y = 1.5f;
  panel_init.pose.position.z = -1.2f;
  panel_init.size = qar_gui_panel_size_default();
  panel_init.size.width_meters = 1.2f;
  panel_init.size.height_meters = 0.7f;
 
  QarResult create_result =
  qar_gui_panels_get_or_create(session, &panel_init, &panel_id);
  log_result("qar_gui_panels_get_or_create", create_result);
  if(qar_result_is_success(create_result))
  {
  printf("Created GUI panel with id: ");
  printf("\n");
  }
 
  QarPose new_pose = qar_pose_default();
  new_pose.position.x = 0.2f;
  new_pose.position.y = 1.6f;
  new_pose.position.z = -1.0f;
  "qar_gui_panels_update_pose",
  qar_gui_panels_update_pose(session, &panel_id, &new_pose)
  );
 
  new_size.width_meters = 1.0f;
  new_size.height_meters = 0.6f;
  "qar_gui_panels_change_size",
  qar_gui_panels_change_size(session, &panel_id, &new_size)
  );
 
  session, &panel_id, QAR_GUI_PANEL_STATE_MINIMIZED
  ));
 
  session, &panel_id, "https://example.com/tutorial"
  ));

Enumerate GUI Panels

  size_t panel_count = 0;
  QarResult count_result = qar_query_gui_panels_count(session, &panel_count);
  log_result("qar_query_gui_panels_count", count_result);
  if(qar_result_is_success(count_result) && panel_count > 0)
  {
  QarGuiPanel** handles =
  (QarGuiPanel**)calloc(panel_count, sizeof(QarGuiPanel*));
  if(handles)
  {
  size_t written = 0;
  QarResult list_result =
  qar_query_gui_panels(session, handles, panel_count, &written);
  log_result("qar_query_gui_panels", list_result);
  if(qar_result_is_success(list_result))
  {
  for(size_t i = 0; i < written; ++i)
  {
  QarGuiPanel* handle = handles[i];
  if(!handle)
  {
  continue;
  }
 
  char name[QAR_MAX_STRING_LENGTH] = { 0 };
 
  (void)qar_gui_panel_get_id(handle, &id);
  handle, name, sizeof(name)
  );
  (void)qar_gui_panel_get_size(handle, &size);
  (void)qar_gui_panel_get_pose(handle, &pose);
  (void)qar_gui_panel_get_state(handle, &state);
 
  printf("- Panel id: ");
  printf(
  " name='%s' size(%.2f x %.2f) position(%.2f, %.2f, "
  "%.2f) state=%d\n",
  name,
  size.width_meters,
  size.height_meters,
  pose.position.x,
  pose.position.y,
  pose.position.z,
  (int)state
  );
 
  }
  }
 
  free(handles);
  }
  }
 
  "qar_gui_panels_close_panel",
  qar_gui_panels_close_panel(session, &panel_id)
  );

Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.9.8.