Dragging
See the DraggingDemo.cs.
using Gridrand.Contracts;
namespace Gridrand.RimGui.Manual
{
/// <summary>
/// Demonstrates a simple dragging interaction using an offset.
/// </summary>
class DraggingDemo : ManualBase, IManual
{
Vector2 offset;
public DraggingDemo(ManualBaseResource p) : base(p)
{
}
public void Draw()
{
Gui.LabelInput("offset", ref offset);
// Allocate a 100x100 rectangle for the dragging area.
var rect = Ctx.AllocateRect(100, 100);
// Render a box to visualize the area.
Gui.Box(rect);
// Define an interactive area for detecting user interaction.
Gui.NextRect(rect).InteractiveArea();
// If the interactive area is active, update the offset based on pointer movement.
if (Ctx.IsWidgetActive<InteractiveAreaWidget>())
{
offset += Input.Pointer.DeltaPos;
}
// Prevents drawing outside the rect.
using (Ctx.PushClip(rect))
{
// Render a sprite inside the dragging area, offset by the user interaction.
Gui.NextRect(new Rect(rect.x + offset.x, rect.y + offset.y, 20 * Style.ScaleFactor, 20 * Style.ScaleFactor))
.Image(Resource.Assets.SampleTexture);
}
}
}
}