常數供應商
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
ConstantProvider
是一組魔法數字、形狀和字串,所有其他轉譯器元件,以及 Blockly 的其他部分,例如內建欄位。
所有常數值均假設為常數!在執行階段變更值會導致轉譯錯誤。
連線形狀
常數提供者包含不同連線標準形狀的定義,Notch
則定義下一個和上一個連線的形狀。PuzzleTab
則定義輸入和輸出連線的形狀。(這些名稱以預設轉譯器提供的形狀為基礎)。
根據檢查項目產生的連線形狀
常數提供者也可以根據其連線檢查,動態定義連線的形狀。方法是使用 shapeFor
方法。
其他各種路徑
常數提供者也會定義區塊其他不同部分的路徑,例如用於收合區塊的鋸齒狀邊緣。
其他各種值
最後,常數提供者也會定義各種值,例如不同元素之間的邊框間距或資料列的最小高度。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eThe \u003ccode\u003eConstantProvider\u003c/code\u003e stores essential values like shapes, strings, and numbers used by Blockly's rendering components.\u003c/p\u003e\n"],["\u003cp\u003eIt defines standard shapes for different connection types, including notches for previous/next connections and puzzle tabs for input/output connections.\u003c/p\u003e\n"],["\u003cp\u003eConnection shapes can be dynamically determined based on connection checks using the \u003ccode\u003eshapeFor\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eConstantProvider\u003c/code\u003e also defines paths for elements like collapsed block edges and various values for padding and minimum heights.\u003c/p\u003e\n"],["\u003cp\u003eModifying \u003ccode\u003eConstantProvider\u003c/code\u003e values during runtime is discouraged as it can lead to rendering issues.\u003c/p\u003e\n"]]],["The `ConstantProvider` stores essential rendering data for Blockly, including connection shapes, paths, and values. It defines standard connection shapes like `Notch` for next/previous connections and `PuzzleTab` for input/output. The `shapeFor` method allows dynamic shape definition based on connection checks. Additionally, it defines paths for block components, like jagged edges, and values for padding and minimum row heights, ensuring consistent rendering. Changing these values at runtime will cause rendering issues.\n"],null,["# Constant provider\n\nThe [`ConstantProvider`](/blockly/reference/js/blockly.blockrendering_namespace.constantprovider_class) is a collection of magic numbers,\nshapes and strings used by all of the other renderer components, as well as\nother parts of Blockly like the built-in fields.\n\nAll constant values are assumed to be *constant*! Changing values at\nruntime causes rendering bugs.\n\nConnection shapes\n-----------------\n\nThe constant provider contains definitions for the standard shapes of different\nconnections. [`Notch`](/blockly/reference/js/blockly.blockrendering_namespace.constantprovider_class.notch_property)es define the shapes of next and previous\nconnections. And the [`PuzzleTab`](/blockly/reference/js/blockly.blockrendering_namespace.constantprovider_class.puzzle_tab_property)s define the shapes of input\nand output connections. (These names are based on the shapes provided by\nthe default renderer.)\n\n### Connection shapes based on checks\n\nThe constant provider can also define the shapes of connections dynamically\nbased on their [connection check](/blockly/guides/create-custom-blocks/type-checks). This is done using the\n[`shapeFor`](/blockly/reference/js/blockly.blockrendering_namespace.constantprovider_class.shapefor_1_method) method.\n\nOther various paths\n-------------------\n\nThe constant provider also defines paths for other various parts of the\nblock, like jagged edges for collapsed blocks.\n\nOther various values\n--------------------\n\nAnd finally, the constant provider also defines various values for things like\nthe padding between different elements, or the minimum heights of rows."]]