AgentSkillsCN

rendering-absolute-coords

使用绝对边界坐标渲染MewUI自定义元素。当对齐方式似乎被忽略,或元素被渲染在左上角时,可使用此功能。

SKILL.md
--- frontmatter
name: rendering-absolute-coords
description: "Renders MewUI custom elements using absolute Bounds coordinates. Use when alignment appears ignored or element renders at top-left."

MewUI Absolute Coordinates

MewUI does NOT apply coordinate transforms. Each element must render at its absolute Bounds position.

Problem

csharp
// ❌ WRONG - Always draws at top-left
public override void Render(IGraphicsContext context)
{
    context.FillRectangle(new Rect(0, 0, Width, Height), color);
}

Solution

csharp
// ✅ CORRECT - Use Bounds.X and Bounds.Y
public override void Render(IGraphicsContext context)
{
    double ox = Bounds.X;
    double oy = Bounds.Y;

    context.FillRectangle(new Rect(ox, oy, Width, Height), color);
}

Checklist

  • Use Bounds.X and Bounds.Y as offset in Render
  • Apply offset to ALL drawing operations
  • Override MeasureContent to return new Size(Width, Height)