حظر استراتيجية السحب
إستراتيجية سحب الكتل هي كائن يحدد كيفية تعامل الكتلة مع الدراغ. تستخدم هذه النماذج المنطق لجعل الكتلة قابلة للسحب.
من خلال إنشاء استراتيجيات جديدة لسحب الكتل، يمكنك تغيير طريقة تعامل الكتل مع عمليات التسرّب بدون الحاجة إلى إنشاء خيارات مخصّصة يمكن اختيارها أو التعامل معها.
على سبيل المثال، قد ترغب في تكرار المقطع عند السحب، بدلاً من السحب بشكل طبيعي. تتيح لك استراتيجيات السحب الحظر تنفيذ ذلك.
تحتوي استراتيجيات السحب على جميع الطرق نفسها مثل IDraggable
،
إلى جانب طريقة getRelativeToSurfaceXY
.
التنفيذ
لإنشاء استراتيجية سحب، عليك تنفيذ واجهة
IDragStrategy
. يتطلّب هذا الإجراء جميع الطرق نفسها المستخدَمة في واجهة IDraggable
، باستثناء طريقة getRelativeToSurfaceXY
التي سبق أن ينفِّذها الحظر.
يمكنك اتّباع
تعليمات تنفيذ السحب القابلة للسحب
لتنفيذ استراتيجية السحب، ولكن تخطَّ تنفيذ getRelativeToSurfaceXY()
.
الاستخدام
لاستخدام استراتيجية سحب مخصّصة، عليك تطبيق استراتيجية السحب على كل
مثيل من عناصر المجموعة. يمكنك فعل ذلك في طريقة init
الخاصة بالحظر، من خلال الاتصال بـ setDragStrategy
.
Blockly.Blocks['my_block'] = {
init: function() {
// Other initialization...
this.setDragStrategy(new MyDragStrategy());
// Other initialization...
}
}
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2024-04-12 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2024-04-12 (حسب التوقيت العالمي المتفَّق عليه)"],[[["Block drag strategies dictate how blocks respond to drag events, offering an alternative to custom selectables."],["By implementing the `IDragStrategy` interface, developers can create custom drag behaviors like block duplication on drag."],["Drag strategies encompass the functionality of `IDraggable`, excluding the `getRelativeToSurfaceXY` method, which is handled internally by the block."],["Applying a custom drag strategy requires using `setDragStrategy` within the block's `init` method to associate the strategy with each block instance."]]],["Block drag strategies dictate how a block behaves during drags, allowing for custom drag behaviors like duplication. Developers implement the `IDragStrategy` interface, which mirrors `IDraggable` methods except for `getRelativeToSurfaceXY`. To apply a custom strategy, use the `setDragStrategy` method within a block's `init` method. This enables switching block drag behavior without altering core selection or drag handling. You must implement all the methods of `IDraggable` in the custom strategy except for `getRelativeToSurfaceXY`.\n"]]