Skip to content

Commit

Permalink
Add test code
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Jul 30, 2023
1 parent bdcd520 commit 440bd62
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 3 deletions.
30 changes: 28 additions & 2 deletions docs/docs/ui-gridtable.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ A container with a [grid table](gridtable.md), slider, and scroller.
- Sizer cell:
- [Demo 1](https://codepen.io/rexrainbow/pen/pooZWme)
- [Demo 2](https://codepen.io/rexrainbow/pen/abOgyPo)
- [Two sliders](https://codepen.io/rexrainbow/pen/KKrrYRm)
- [Separator](https://codepen.io/rexrainbow/pen/YzRrOOP)
- [Modal](https://codepen.io/rexrainbow/pen/zYarzzO)
- [Drag item](https://codepen.io/rexrainbow/pen/WNaQrgp)
Expand Down Expand Up @@ -94,7 +95,7 @@ var table = scene.rexUI.add.gridTable({
// width: undefined,
// height: undefined,
scrollMode: 0,
// scrollMode: 0,
// Elements
background: backgroundGameObject,
Expand Down Expand Up @@ -159,6 +160,9 @@ var table = scene.rexUI.add.gridTable({
// }
},
// sliderX: {...},
// sliderY: {...},
// scroller: {
// threshold: 10,
// slidingDeceleration: 5000,
Expand All @@ -167,12 +171,18 @@ var table = scene.rexUI.add.gridTable({
// dragRate: 1,
// },
// scrollerX: {...},
// scrollerY: {...},
mouseWheelScroller: false,
// mouseWheelScroller: {
// focus: false,
// speed: 0.1
// }.
// mouseWheelScrollerX: {...},
// mouseWheelScrollerY: {...},
clamplChildOY: false,
header: headerGameObject,
Expand All @@ -199,6 +209,8 @@ var table = scene.rexUI.add.gridTable({
// left: 0,
// right: 0,
// },
// sliderX: 0,
// sliderY: 0,
header: 0,
footer: 0,
Expand Down Expand Up @@ -253,9 +265,10 @@ var table = scene.rexUI.add.gridTable({
- `width`, `height` : Minimum width, minimum height.
- Set `width` to `undefined`, and `table.width` is not `undefined`, will count width via table + slider.
- Set `height` to `undefined`, and `table.height` is not `undefined`, will count height via table + slider.
- `scrollMode` : Scroll grid table vertically, or horizontally.
- `scrollMode` : Scroll panel vertically, or horizontally.
- `0`, `'vertical'`, or `'v'`, `'y'` : Scroll panel vertically. Default value.
- `1`, `'horizontal'`, or `'h'`. `'x'` : Scroll panel horizontally.
- `2`, or `'xy'` : Two-sliders mode, scroll panel vertically and horizontally.
- `background` : [Game object of background](ui-basesizer.md#background), optional. This background game object will be resized to fit the size of grid table.
- `table` : Configuration of grid table core.
- `table.width` : Width of table, in pixels.
Expand Down Expand Up @@ -316,6 +329,7 @@ var table = scene.rexUI.add.gridTable({
- `slider.buttons.left`, `slider.buttons.right` : Left and right buttons
- `slider.buttons.step` : Scrolling step in each tick. Default value is `0.01`.
- Set to `false` to skip creating slider.
- `sliderX`, `sliderY` : Componments of sliderX and sliderY, for two-sliders mode.
- `scroller` : Configuration of scroller behavior.
- `scroller.threshold` : Minimal movement to scroll. Set `0` to scroll immediately.
- `scroller.slidingDeceleration` : Deceleration of slow down when dragging released.
Expand All @@ -325,12 +339,14 @@ var table = scene.rexUI.add.gridTable({
- `scroller.pointerOutRelease` : Set to `true` to release input control when pointer out of gameObject.
- `scroller.dragRate` : Rate of dragging distance/dragging speed. Default value is `1`.
- Set to `false` to skip creating scroller.
- `scrollerX`, `scrollerY` : Configuration of scrollerX, scrollerY behavior, for two-sliders mode.
- `mouseWheelScroller` : Configuration of mouse-wheel-scroller behavior.
- `mouseWheelScroller.focus` :
- `true` : Only scrolling when cursor is over table.
- `false` : Scrolling without checking cursor. Default behavior.
- `mouseWheelScroller.speed` : Scrolling speed, default value is `0.1`.
- Set to `false` to skip creating mouse-wheel-scroller. Default behavior.
- `mouseWheelScrollerX`, `mouseWheelScrollerY` : Configuration of mouse-wheel-scrollerX, or mouse-wheel-scrollerY behavior, for two-sliders mode.
- `clamplChildOY` : Set `true` to clamp scrolling.
- `createCellContainerCallback` : Callback to return a container object, or `null` of each visible cell.
- Properties of `cell` parameter
Expand Down Expand Up @@ -371,6 +387,8 @@ var table = scene.rexUI.add.gridTable({
- `space.slider` :
- `0` : No space around slider.
- `space.slider.left`, `space.slider.right`, `space.slider.top`, `space.slider.bottom` : Space around slider.
- `space.sliderX`, `space.sliderX` : Space configuration of sliderX, sliderX, for two-sliders mode.
- `0` : No space around slider.
- `space.header` : Space between header and table.
- `space.footer` : Space between footer and table.
- `expand` : Expand width or height of element
Expand All @@ -387,6 +405,14 @@ var table = scene.rexUI.add.gridTable({
- `draggable` : Set `true` to drag top-most object.
- `sizerEvents` : Set `true` to fire [sizer events](ui-basesizer.md#events). Default value is `false`.

#### Scroll mode

If `scrollMode` parameter is not given :

- Set `scrollMode` to `2`, if configuration has `sliderX`, `sliderY`, or `scrollerX`, `scrollerY` parameters.
- Set `scrollMode` to `0`, if configuration has `sliderY`, or `scrollerY` parameters.
- Set `scrollMode` to `1`, if configuration has `sliderX`, or `scrollerX` parameters.

### Custom class

- Define class
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/ui-scrollablepanel.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var panel = scene.rexUI.add.scrollablePanel({
// width: undefined,
// height: undefined,
scrollMode: 0,
// scrollMode: 0,
// Elements
background: backgroundGameObject,
Expand Down
5 changes: 5 additions & 0 deletions examples/ui-gridtable/gridtable-sliderxy.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
set main=./examples/ui-gridtable/gridtable-sliderxy.js
cd ..
cd ..
npm run watch
234 changes: 234 additions & 0 deletions examples/ui-gridtable/gridtable-sliderxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
import phaser from 'phaser/src/phaser.js';
import UIPlugin from '../../templates/ui/ui-plugin.js';

const COLOR_PRIMARY = 0x4e342e;
const COLOR_LIGHT = 0x7b5e57;
const COLOR_DARK = 0x260e04;

const Random = Phaser.Math.Between;

class Demo extends Phaser.Scene {
constructor() {
super({
key: 'examples'
})
}

preload() { }

create() {
var gridTable = this.rexUI.add.gridTable({
x: 400,
y: 300,
width: 300,
height: 420,

background: this.rexUI.add.roundRectangle(0, 0, 20, 10, 10, COLOR_PRIMARY),

table: {
cellWidth: 120,
cellHeight: 60,

columns: 5,

mask: {
padding: 2,
},
// enableLayer: true,

reuseCellContainer: true,
},

sliderX: {
track: this.rexUI.add.roundRectangle(0, 0, 20, 10, 10, COLOR_DARK),
thumb: this.rexUI.add.roundRectangle(0, 0, 0, 0, 13, COLOR_LIGHT),
},

sliderY: {
track: this.rexUI.add.roundRectangle(0, 0, 20, 10, 10, COLOR_DARK),
thumb: this.rexUI.add.roundRectangle(0, 0, 0, 0, 13, COLOR_LIGHT),
},

header: this.rexUI.add.label({
background: this.rexUI.add.roundRectangle(0, 0, 20, 20, 0, COLOR_DARK),
text: this.add.text(0, 0, 'Header'),
}),

footer: GetFooterSizer(this),

space: {
left: 20,
right: 20,
top: 20,
bottom: 20,

sliderX: 10,
sliderY: 10,
header: 10,
footer: 10,
},

createCellContainerCallback: function (cell, cellContainer) {
var scene = cell.scene,
width = cell.width,
height = cell.height,
item = cell.item,
index = cell.index;
if (cellContainer === null) {
cellContainer = scene.rexUI.add.label({
width: width,
height: height,
background: scene.rexUI.add.roundRectangle(0, 0, 20, 20, 0).setStrokeStyle(2, COLOR_DARK),
icon: scene.rexUI.add.roundRectangle(0, 0, 20, 20, 10, 0x0),
text: scene.add.text(0, 0, ''),

space: {
icon: 10,
left: 10
}
});
console.log(cell.index + ': create new cell-container');
} else {
console.log(cell.index + ': reuse cell-container');
}

// Set properties from item value
cellContainer.setMinSize(width, height); // Size might changed in this demo
cellContainer.getElement('text').setText(item.id); // Set text of text object
cellContainer.getElement('icon').setFillStyle(item.color); // Set fill color of round rectangle object
cellContainer.getElement('background').setStrokeStyle(2, COLOR_DARK).setDepth(0);
return cellContainer;
},
items: CreateItems(1000)
})
.setDraggable('header') // Draggable-header
.layout()

//.drawBounds(this.add.graphics(), 0xff0000);

this.print = this.add.text(0, 0, '');
gridTable
.on('cell.down', function (cellContainer, cellIndex) {
this.print.text += 'pointer-down ' + cellIndex + ': ' + cellContainer.text + '\n';
}, this)
.on('cell.up', function (cellContainer, cellIndex) {
this.print.text += 'pointer-up ' + cellIndex + ': ' + cellContainer.text + '\n';
}, this)
.on('cell.over', function (cellContainer, cellIndex) {
cellContainer.getElement('background')
.setStrokeStyle(2, COLOR_LIGHT)
.setDepth(1);
}, this)
.on('cell.out', function (cellContainer, cellIndex) {
cellContainer.getElement('background')
.setStrokeStyle(2, COLOR_DARK)
.setDepth(0);
}, this)
.on('cell.click', function (cellContainer, cellIndex) {
this.print.text += 'click ' + cellIndex + ': ' + cellContainer.text + '\n';

var nextCellIndex = cellIndex + 1;
var nextItem = gridTable.items[nextCellIndex];
if (!nextItem) {
return;
}
nextItem.color = 0xffffff - nextItem.color;
gridTable.updateVisibleCell(nextCellIndex);

}, this)
.on('cell.1tap', function (cellContainer, cellIndex) {
this.print.text += '1 tap (' + cellIndex + ': ' + cellContainer.text + ')\n';
}, this)
.on('cell.2tap', function (cellContainer, cellIndex) {
this.print.text += '2 taps (' + cellIndex + ': ' + cellContainer.text + ')\n';
}, this)
.on('cell.pressstart', function (cellContainer, cellIndex) {
this.print.text += 'press-start (' + cellIndex + ': ' + cellContainer.text + ')\n';
}, this)
.on('cell.pressend', function (cellContainer, cellIndex) {
this.print.text += 'press-end (' + cellIndex + ': ' + cellContainer.text + ')\n';
}, this)
.on('cell.swiperight', function (cellContainer, cellIndex) {
this.print.text += 'swipe-right (' + cellIndex + ': ' + cellContainer.text + ')\n';
}, this)
.on('cell.swipeleft', function (cellContainer, cellIndex) {
this.print.text += 'swipe-left (' + cellIndex + ': ' + cellContainer.text + ')\n';
}, this)
.on('cell.swipeup', function (cellContainer, cellIndex) {
this.print.text += 'swipe-up (' + cellIndex + ': ' + cellContainer.text + ')\n';
}, this)
.on('cell.swipedown', function (cellContainer, cellIndex) {
this.print.text += 'swipe-down (' + cellIndex + ': ' + cellContainer.text + ')\n';
}, this)

}

update() { }
}

var CreateItems = function (count) {
var data = [];
for (var i = 0; i < count; i++) {
data.push({
id: i,
color: Random(0, 0xffffff)
});
}
return data;
}

var GetFooterSizer = function (scene) {
return scene.rexUI.add.sizer()
.add(
CreateFooterButton(scene, 'Reset'), // child
{ proportion: 1 }
)
.add(
CreateFooterButton(scene, 'Exit'), // child
{ proportion: 1 }
)
}

var CreateFooterButton = function (scene, text) {
return scene.rexUI.add.label({
background: scene.rexUI.add.roundRectangle(0, 0, 2, 2, 20, COLOR_DARK),
text: scene.add.text(0, 0, text),
icon: scene.rexUI.add.roundRectangle(0, 0, 0, 0, 10, COLOR_LIGHT),
align: 'center',
space: {
left: 10, right: 10, top: 10, bottom: 10,
icon: 10
}
})
.setInteractive()
.on('pointerdown', function () {
console.log(`Pointer down ${text}`)
})
.on('pointerover', function () {
this.getElement('background').setStrokeStyle(1, 0xffffff);
})
.on('pointerout', function () {
this.getElement('background').setStrokeStyle();
})
}

var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
},
scene: Demo,
plugins: {
scene: [{
key: 'rexUI',
plugin: UIPlugin,
mapping: 'rexUI'
}]
}
};

var game = new Phaser.Game(config);
2 changes: 2 additions & 0 deletions templates/ui/gridtable/GridTable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ declare namespace GridTable {
left?: number, right?: number, top?: number, bottom?: number,
},

sliderX?: number,
sliderY?: number,
header?: number,
footer?: number,
},
Expand Down
2 changes: 2 additions & 0 deletions templates/ui/scrollablepanel/ScrollablePanel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ declare namespace ScrollablePanel {
left?: number, right?: number, top?: number, bottom?: number,
},

sliderX?: number,
sliderY?: number,
header?: number,
footer?: number,
},
Expand Down
2 changes: 2 additions & 0 deletions templates/ui/utils/scrollable/Scrollable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ declare namespace Scrollable {
space?: {
left?: number, right?: number, top?: number, bottom?: number,

sliderX?: number,
sliderY?: number,
header?: number,
footer?: number,
},
Expand Down

0 comments on commit 440bd62

Please sign in to comment.