-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3b5782
commit fd6a169
Showing
6 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
set main=./examples/ui-label/set-children-align-mode.js | ||
cd .. | ||
cd .. | ||
npm run watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import phaser from 'phaser/src/phaser.js'; | ||
import UIPlugin from '../../templates/ui/ui-plugin.js'; | ||
|
||
const COLOR_MAIN = 0x4e342e; | ||
const COLOR_LIGHT = 0x7b5e57; | ||
const COLOR_DARK = 0x260e04; | ||
|
||
class Demo extends Phaser.Scene { | ||
constructor() { | ||
super({ | ||
key: 'examples' | ||
}) | ||
|
||
} | ||
|
||
preload() { } | ||
|
||
create() { | ||
var label = CreateLabel(this, 'Label', true) | ||
.setPosition(400, 300) | ||
.layout() | ||
|
||
this.rexUI.add.buttons({ | ||
x: 400, y: 400, | ||
orientation: 'x', | ||
|
||
buttons: [ | ||
CreateLabel(this, 'Left'), | ||
CreateLabel(this, 'Center'), | ||
CreateLabel(this, 'Right') | ||
] | ||
}) | ||
.layout() | ||
.on('button.click', function (button, index, pointer, event) { | ||
switch (index) { | ||
case 0: label.setChildrenAlignMode('left').layout(); break; | ||
case 1: label.setChildrenAlignMode('center').layout(); break; | ||
case 2: label.setChildrenAlignMode('right').layout(); break; | ||
} | ||
}) | ||
.on('button.over', function (button, index, pointer, event) { | ||
button.getElement('background').setFillStyle(COLOR_DARK); | ||
}) | ||
.on('button.out', function (button, index, pointer, event) { | ||
button.getElement('background').setFillStyle(); | ||
}) | ||
|
||
} | ||
|
||
update() { } | ||
} | ||
|
||
var CreateLabel = function (scene, text, hasIcon) { | ||
if (hasIcon === undefined) { | ||
hasIcon = false; | ||
} | ||
return scene.rexUI.add.label({ | ||
width: 240, height: 60, | ||
background: scene.rexUI.add.roundRectangle(0, 0, 2, 2).setStrokeStyle(2, COLOR_LIGHT), | ||
text: scene.add.text(0, 0, text), | ||
icon: (hasIcon) ? scene.rexUI.add.roundRectangle(0, 0, 0, 0, 10, COLOR_LIGHT) : undefined, | ||
space: { | ||
left: 10, | ||
right: 10, | ||
top: 10, | ||
bottom: 10, | ||
icon: 10 | ||
} | ||
}); | ||
} | ||
|
||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import AppendText from '../../../../plugins/utils/text/AppendText.js'; | ||
import ResetDisplayContent from './ResetDisplayContent.js'; | ||
import SetChildrenAlignMode from './SetChildrenAlignMode.js'; | ||
|
||
var methods = { | ||
appendText: AppendText, | ||
resetDisplayContent: ResetDisplayContent, | ||
setChildrenAlignMode: SetChildrenAlignMode, | ||
} | ||
|
||
export default methods; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var SetChildrenAlignMode = function (mode) { | ||
var children = this.sizerChildren; | ||
|
||
var firstChild = children[0]; | ||
|
||
if ( // Has left space | ||
(mode === 'right') || | ||
(mode === 'bottom') || | ||
(mode === 'center') | ||
) { | ||
if (!firstChild.isRexSpace) { | ||
this.insertSpace(0); | ||
} | ||
|
||
} else { // Does not have left space | ||
if (firstChild.isRexSpace) { | ||
this.remove(firstChild, true); | ||
} | ||
} | ||
|
||
var lastChildIndex = children.length - 1; | ||
var lastChild = children[lastChildIndex]; | ||
if (mode === 'center') { // Has right space | ||
if (!lastChild.isRexSpace) { | ||
this.insertSpace(lastChildIndex + 1); | ||
} | ||
|
||
} else { // Does not have right space | ||
if (lastChild.isRexSpace) { | ||
this.remove(lastChild, true); | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
|
||
export default SetChildrenAlignMode; |