Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-ui-2d

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Build Canvas UI with sprites, Label text, layout and widgets. Use for missing UI, viewport alignment, 2D draw order, BMFont binding or AIR_E_LABEL_WRAP.

  • 10 files
  • 39.1 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-ui-2d

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referenceswidgets.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Derived from build/cocosair.module.js, src/cocos/2d/framework/canvas.ts, src/cocos/ui/widget.ts, src/cocos/ui/layout.ts, src/cocos/ui/button.ts, src/cocos/ui/toggle.ts, src/cocos/ui/slider.ts, src/cocos/ui/progress-bar.ts, src/cocos/ui/scroll-view.ts, src/cocos/ui/page-view.ts, src/cocos/ui/editbox/edit-box.ts, src/cocos/ui/safe-area.ts, src/cocos/ui/block-input-events.ts, docs/manual/ui-layout-and-interaction.md - 2026-10-10

Widget and interaction components

Every UI component in scope is on the single export { ... } block of build/cocosair.module.js (currently :161574). Most ship twice: a bare class and an ... as XComponent alias, so either import name binds. Two are aliases-only or renamed - Layout and RichText - and that difference is load bearing for import statements.

Export aliases

Import (bare) Also exported as Class definition note
Canvas Canvas as CanvasComponent base UI root, links camera (src/cocos/2d/framework/canvas.ts:92)
Widget Widget as WidgetComponent class Widget extends Component (src/cocos/ui/widget.ts:227)
Button Button as ButtonComponent class Button extends Component (src/cocos/ui/button.ts:177)
Toggle Toggle as ToggleComponent class Toggle extends Button (src/cocos/ui/toggle.ts:53)
Slider Slider as SliderComponent class Slider extends Component (src/cocos/ui/slider.ts:80)
ProgressBar ProgressBar as ProgressBarComponent class ProgressBar extends Component (src/cocos/ui/progress-bar.ts:102)
ScrollView ScrollView as ScrollViewComponent class ScrollView extends ViewGroup (src/cocos/ui/scroll-view.ts:236)
PageView PageView as PageViewComponent class PageView extends ScrollView (src/cocos/ui/page-view.ts:103)
EditBox EditBox as EditBoxComponent class EditBox extends Component (src/cocos/ui/editbox/edit-box.ts:77)
SafeArea SafeArea as SafeAreaComponent class SafeArea extends Component (src/cocos/ui/safe-area.ts:62)
BlockInputEvents BlockInputEvents as BlockInputEventsComponent class BlockInputEvents extends Component (src/cocos/ui/block-input-events.ts:51)
Layout Layout$1 as LayoutComponent class Layout extends Component (src/cocos/ui/layout.ts:214); no bare Layout export name

RichText is exported only as RichText as RichTextComponent, with no bare RichText name (class at src/cocos/2d/components/rich-text.ts:157). Importing { RichText } from the bundle resolves to nothing. See label-and-text.md.

Base-class relationships

  • Toggle extends Button (src/cocos/ui/toggle.ts:53): reuses the Button transition machinery and adds checked state.
  • PageView extends ScrollView (src/cocos/ui/page-view.ts:103): page-flip behavior over the ScrollView drag model; PageViewIndicator and ScrollBar are separate exported helpers for it.
  • ScrollView extends ViewGroup (src/cocos/ui/scroll-view.ts:236): inherits Layout-aware content grouping.
  • ToggleContainer is exported bare and enforces exclusivity across member Toggles; the sample wires it for mutually exclusive check marks (docs/manual/ui-layout-and-interaction.md:38).

Interaction surface

Button/Toggle/Slider/ScrollView/EditBox emit component events driven by the engine input chain; a click is bound with node.on('click', handler), not with a DOM listener (docs/manual/ui-layout-and-interaction.md:11-12, :29-36):

buttonNode.on('click', () => {
  buttonLabel.string = `Clicked x${count}`;
});

BlockInputEvents swallows pointer events for its subtree so underlying nodes are not hit-tested; SafeArea offsets its node into the device safe region (src/cocos/ui/safe-area.ts:62, src/cocos/ui/block-input-events.ts:51). Hit testing requires a UITransform on every interactive node and a UI camera whose visibility includes the node layer - both enforced by createUICanvas (docs/manual/2d-ui.md:56-57, src/air/ui-kit.ts:38-66).

Component versus sprite backing

Button with transition = Button.Transition.COLOR needs a target sprite whose color it tweens (docs/manual/ui-layout-and-interaction.md:21-27). ProgressBar tracks a Sprite fill amount. Slider reads a handle node position against its track. All of these read the same Sprite, UITransform and UIRenderer components; there is no parallel widget-makeup system, and none of them require a Prefab.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "put sprites, labels or controls on screen",
  "UI renders nothing despite visible nodes",
  "widgets must realign after a viewport change",
  "bind an existing bitmap font to Label",
  "2D sprites and labels overlap in the wrong order"
]
owns
[
  "ui-canvas",
  "sprite-label",
  "widget-layout",
  "ui-controls",
  "font-binding",
  "sorting-2d"
]
not_for
[
  "load or parse a bitmap font -> cocosair-assets",
  "sprite masks and DOM overlays -> cocosair-graphics-and-dom",
  "native input and action mapping -> cocosair-input-action"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "使用 Canvas、布局、控件、Label、位图字体和二维排序。用于 UI 构建、文本显示或交互布局问题。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-ui-2d