연구 설문조사: Blockly 사용 경험을 알려주세요
설문조사 시작
맞춤 렌더기 만들기
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
맞춤 렌더러를 만들려면 Renderer
클래스의 서브클래스를 만들어야 합니다. 렌더러의 정의와 기능에 관한 자세한 내용은 렌더러 개념 문서를 참고하세요.
class CustomRenderer extends Blockly.blockRendering.Renderer {
constructor() {
super();
}
}
맞춤설정을 하지 않으면 기본 렌더기는 다음과 같이 표시됩니다.
다른 기본 제공 렌더러 중 하나를 서브클래스화한 다음 일부를 재정의할 수도 있습니다.
class CustomRenderer extends Blockly.thrasos.Renderer {
constructor() {
super();
}
}
다른 렌더러 구성요소 서브클래스화
블록의 실제 모양은 렌더러의 하위 구성요소에 따라 결정됩니다.
기본적으로 Renderer
클래스는 모든 렌더러 구성요소의 작동하는 버전을 제공합니다. 이렇게 하면 다른 구성요소에 관해 걱정하지 않고도 단일 구성요소를 수정할 수 있습니다.
예를 들어 연결의 도형을 변경하려면 다른 구성요소를 건드리지 않고도 상수를 재정의할 수 있습니다.
각 개별 구성요소의 기능에 관한 자세한 내용은 렌더러 구성요소 문서를 참고하세요.
팩토리 메서드 재정의
렌더러 구성요소를 서브클래스화한 후에는 서브클래스화한 구성요소의 Renderer
의 팩토리 메서드를 재정의해야 합니다. 이렇게 하면 렌더러가 여러 구성요소를 올바르게 연결할 수 있습니다.
구성요소의 종류마다 메서드가 있습니다.
렌더기 등록
마지막으로 맞춤 렌더러 생성을 완료하면 이를 등록해야 합니다. 이렇게 하면 렌더러를 문자열과 연결하여 구성 옵션에 전달할 수 있습니다.
Blockly.blockRendering.register('custom_renderer', CustomRenderer);
const workspace = Blockly.inject(blocklyDiv, {
renderer: 'custom_renderer',
});
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-25(UTC)
[null,null,["최종 업데이트: 2025-07-25(UTC)"],[[["\u003cp\u003eTo create custom renderers in Blockly, you need to subclass the \u003ccode\u003eRenderer\u003c/code\u003e class and potentially its subcomponents like constants, render info, path objects, and drawers.\u003c/p\u003e\n"],["\u003cp\u003eCustom renderers allow you to change the visual appearance of blocks, including connection shapes and overall block structure, by overriding factory methods for specific components.\u003c/p\u003e\n"],["\u003cp\u003eAfter creating the custom renderer, register it with a unique string using \u003ccode\u003eBlockly.blockRendering.register()\u003c/code\u003e to use it within your workspace configuration.\u003c/p\u003e\n"],["\u003cp\u003eBefore starting with custom renderers, it's recommended to review the renderer concept documentation and complete the custom renderers codelab for foundational knowledge.\u003c/p\u003e\n"]]],[],null,["# Create custom renderers\n\n| **Note:** If you haven't read through the [renderer concept docs](/blockly/guides/create-custom-blocks/renderers/concepts/renderer) or completed the [custom renderers codelab](https://blocklycodelabs.dev/codelabs/custom-renderer/index.html) we recommend doing those first!\n\nTo create a custom renderer, you need to subclass the [`Renderer`](/blockly/reference/js/blockly.blockrendering_namespace.renderer_class)\nclass. Refer to the [renderer concept docs](/blockly/guides/create-custom-blocks/renderers/concepts/renderer) for more\ninformation about what a renderer is and what it does. \n\n class CustomRenderer extends Blockly.blockRendering.Renderer {\n constructor() {\n super();\n }\n }\n\nWithout any customization, the default renderer looks like this:\n\nYou can also subclass one of the other [built-in renderers](/blockly/guides/create-custom-blocks/renderers/overview#built-in_renderers)\nand then override parts of it. \n\n class CustomRenderer extends Blockly.thrasos.Renderer {\n constructor() {\n super();\n }\n }\n\nSubclass other renderer components\n----------------------------------\n\nThe actual shape of the block is determined by the\n[subcomponents](/blockly/guides/create-custom-blocks/renderers/concepts/overview) of the renderer.\n\nBy default, the [`Renderer`](/blockly/reference/js/blockly.blockrendering_namespace.renderer_class) class provides working versions of\nall the [renderer components](/blockly/guides/create-custom-blocks/renderers/concepts/overview). This lets you modify a\nsingle component, without having to worry about the others.\n\nFor example, if you want to\n[change the shapes of connections](/blockly/guides/create-custom-blocks/renderers/create-custom-renderers/connection-shapes), you can override the\n[constants](/blockly/guides/create-custom-blocks/renderers/concepts/constants) without having to touch the other components.\n\nCheck out the [renderer component docs](/blockly/guides/create-custom-blocks/renderers/concepts/overview) for more\ninformation about what each individual component does.\n\nOverride factory methods\n------------------------\n\nAfter subclassing the [renderer components](/blockly/guides/create-custom-blocks/renderers/concepts/overview), you need to\noverride the [`Renderer`](/blockly/reference/js/blockly.blockrendering_namespace.renderer_class)'s factory methods for the components you\nsubclassed. This lets the renderer properly wire the different components\ntogether.\n\nThere is a method for each kind of component:\n\n- [`makeConstants_`](/blockly/reference/js/blockly.blockrendering_namespace.renderer_class.makeconstants__1_method)\n- [`makeRenderInfo_`](/blockly/reference/js/blockly.blockrendering_namespace.renderer_class.makerenderinfo__1_method)\n- [`makePathObject`](/blockly/reference/js/blockly.blockrendering_namespace.renderer_class.makepathobject_1_method) (note there is no underscore)\n- [`makeDrawer_`](/blockly/reference/js/blockly.blockrendering_namespace.renderer_class.makedrawer__1_method)\n\nRegister the renderer\n---------------------\n\nFinally, once you've completed the creation of your custom renderer, you need to\nregister it. This associates the renderer with a string so that you can pass it\nto your [configuration options](/blockly/guides/configure/web/configuration_struct). \n\n Blockly.blockRendering.register('custom_renderer', CustomRenderer);\n\n const workspace = Blockly.inject(blocklyDiv, {\n renderer: 'custom_renderer',\n });"]]