sdlSetGamepadMapping function gamepad

bool sdlSetGamepadMapping(
  1. int instanceId,
  2. String? mapping
)

Set the current mapping of a joystick or gamepad.

Details about mappings are discussed with SDL_AddGamepadMapping().

\param instance_id the joystick instance ID. \param mapping the mapping to use for this device, or NULL to clear the mapping. \returns true on success or false on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.2.0.

\sa SDL_AddGamepadMapping \sa SDL_GetGamepadMapping

extern SDL_DECLSPEC bool SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping)

Implementation

bool sdlSetGamepadMapping(int instanceId, String? mapping) {
  final sdlSetGamepadMappingLookupFunction = _libSdl
      .lookupFunction<
        Uint8 Function(Uint32 instanceId, Pointer<Utf8> mapping),
        int Function(int instanceId, Pointer<Utf8> mapping)
      >('SDL_SetGamepadMapping');
  final mappingPointer = mapping != null ? mapping.toNativeUtf8() : nullptr;
  final result =
      sdlSetGamepadMappingLookupFunction(instanceId, mappingPointer) == 1;
  calloc.free(mappingPointer);
  return result;
}