Renders custom graphics in MewUI controls using IGraphicsContext. Use when implementing OnRender, drawing shapes, text, images, or understanding the Measure/Arrange/Render pipeline.
MewUI uses a three-pass layout system:
Measure (calculate DesiredSize) → Arrange (set Bounds) → Render (draw via IGraphicsContext)
Key overrides in custom controls:
MeasureContent(Size availableSize) → return desired sizeArrangeContent(Rect bounds) → position childrenOnRender(IGraphicsContext context) → draw visualsprotected override void OnRender(IGraphicsContext context)
{
var bounds = new Rect(0, 0, Bounds.Width, Bounds.Height);
// State management (always Save/Restore)
context.Save();
context.Translate(10, 10);
context.SetClip(clipRect);
// ... drawing ...
context.Restore();
// Drawing primitives
context.FillRectangle(bounds, Colors.Blue);
context.DrawRectangle(bounds, Colors.Black, thickness: 1);
context.FillRoundedRectangle(bounds, radiusX: 4, radiusY: 4, Colors.White);
context.DrawLine(start, end, Colors.Gray, thickness: 1);
context.FillEllipse(bounds, Colors.Red);
// Text - note parameter order: text, bounds, font, color, alignments, wrapping
context.DrawText("Hello", bounds, font, Colors.Black,
TextAlignment.Center, TextAlignment.Center, TextWrapping.NoWrap);
// Images
context.DrawImage(image, destRect);
}
protected override Size MeasureContent(Size availableSize)
{
var factory = GetGraphicsFactory();
using var ctx = factory.CreateMeasurementContext(GetDpi()); // uint dpi (96, 144, etc.)
return ctx.MeasureText(Text, GetFont(), availableSize.Width);
}
Application.DefaultGraphicsBackend = GraphicsBackend.Direct2D; // GPU (Windows)
Application.DefaultGraphicsBackend = GraphicsBackend.Gdi; // Software (Windows)
Application.DefaultGraphicsBackend = GraphicsBackend.OpenGL; // Cross-platform
InvalidateMeasure(); // Re-measure + re-arrange + re-render
InvalidateArrange(); // Re-arrange + re-render
InvalidateVisual(); // Re-render only
Detailed API: See graphics-api.md Pipeline details: See pipeline.md
npx skills add christian289/rendering-mewui-elements下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer