סקר מחקר: נשמח לשמוע על החוויה שלך עם Blockly
לפתיחת הסקר
יצירת מעבדים מותאמים אישית
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי ליצור מעבד גרפיקה מותאם אישית, צריך ליצור תת-מחלקה של הכיתה Renderer
. מידע נוסף על המושג 'מַעבד גרפיקה' ועל הפעולות שהוא מבצע זמין במסמכי התיעוד בנושא מושגים של מעבדי גרפיקה.
class CustomRenderer extends Blockly.blockRendering.Renderer {
constructor() {
super();
}
}
ללא התאמה אישית, המרת ה-HTML כברירת מחדל נראית כך:
אפשר גם ליצור תת-סוג של אחד מהמעבדים המובנים האחרים, ואז לשנות את החלקים הרלוונטיים.
class CustomRenderer extends Blockly.thrasos.Renderer {
constructor() {
super();
}
}
יצירת תת-סוג של רכיבי עיבוד אחרים
הצורה בפועל של הבלוק נקבעת על ידי רכיבי המשנה של המרינר.
כברירת מחדל, הכיתה Renderer
מספקת גרסאות שפועלות של כל רכיבי המעבד. כך תוכלו לשנות רכיב אחד בלי לדאוג לגבי הרכיבים האחרים.
לדוגמה, אם רוצים לשנות את הצורות של החיבורים, אפשר לשנות את הקבועים בלי לגעת ברכיבים האחרים.
במסמכי התיעוד של רכיבי ה-renderer מפורט מידע נוסף על הפעולות של כל רכיב.
שינוי שיטות המפעל
אחרי שיוצרים צאצא של רכיבי ה-renderer, צריך לשנות את שיטות המפעל של Renderer
לרכיבים שיצרתם להם צאצא. כך ה-renderer יכול לחבר את הרכיבים השונים בצורה נכונה.
יש שיטה לכל סוג של רכיב:
רישום המכשיר להמרה
לבסוף, אחרי שתסיימו ליצור את המרת ה-HTML בהתאמה אישית, תצטרכו לרשום אותה. כך המערכת משייך את ה-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. Java הוא סימן מסחרי רשום של חברת 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 });"]]