Dragging
See the DraggingDemo.cs.
using Gridrand.Contracts;
using Gridrand.RimGui.Manual.Utility;
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.LabelSliderInput("offset", ref offset, new Vector2(0, 0), new Vector2(200, 200));
// Allocate a 200x200 rectangle for the dragging area.
var rect = Ctx.AllocateRect(200, 200);
// 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);
}
}
}
}