Merge pull request #196 from Susko3/add-SDL_GetTrayEntries-helper

Implement helper for `SDL_GetTrayEntries()`
This commit is contained in:
Dan Balasescu 2025-01-05 17:24:19 +09:00 committed by GitHub
commit ab7c7f5a9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 54 additions and 8 deletions

View File

@ -25,6 +25,13 @@ namespace SDL.Tests
Assert.That(exit != null, SDL_GetError); Assert.That(exit != null, SDL_GetError);
SetCallback(exit, () => running = false); SetCallback(exit, () => running = false);
var entries = SDL_GetTrayEntries(RootMenu);
Assert.That(entries, Is.Not.Null, SDL_GetError);
Assert.That(entries!.Count, Is.EqualTo(3));
for (int i = 0; i < entries.Count; i++)
Console.WriteLine($"{i}. {SDL_GetTrayEntryLabel(entries[i]) ?? "<null>"}");
running = true; running = true;
while (running) while (running)

View File

@ -18,13 +18,11 @@ namespace SDL
public static partial class SDL3 public static partial class SDL3
{ {
// The code below is currently incorrect because of https://github.com/libsdl-org/SDL/issues/11787. public static unsafe SDLConstOpaquePointerArray<SDL_TrayEntry>? SDL_GetTrayEntries(SDL_TrayMenu* menu)
// [MustDisposeResource] {
// public static unsafe SDLOpaquePointerArray<SDL_TrayEntry>? SDL_GetTrayEntries(SDL_TrayMenu* menu) int count;
// { var array = SDL_GetTrayEntries(menu, &count);
// int count; return SDLArray.CreateConstOpaque(array, count);
// var array = SDL_GetTrayEntries(menu, &count); }
// return SDLArray.CreateOpaque(array, count);
// }
} }
} }

View File

@ -73,5 +73,14 @@ namespace SDL
return new SDLOpaquePointerArray<T>(array, count); return new SDLOpaquePointerArray<T>(array, count);
} }
internal static SDLConstOpaquePointerArray<T>? CreateConstOpaque<T>(T** array, int count)
where T : unmanaged
{
if (array == null)
return null;
return new SDLConstOpaquePointerArray<T>(array, count);
}
} }
} }

View File

@ -0,0 +1,32 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
namespace SDL
{
public sealed unsafe class SDLConstOpaquePointerArray<T>
where T : unmanaged
{
private readonly T** array;
public readonly int Count;
internal SDLConstOpaquePointerArray(T** array, int count)
{
this.array = array;
Count = count;
}
public T* this[int index]
{
get
{
ArgumentOutOfRangeException.ThrowIfNegative(index);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count);
Debug.Assert(array[index] != null);
return array[index];
}
}
}
}