Added PixiJS UI Text class.
This commit is contained in:
+12
-130
@@ -13,150 +13,32 @@
|
||||
|
||||
<script src="../../dist/iwmlib.js"></script>
|
||||
<script src="../../dist/iwmlib.pixi.js"></script>
|
||||
|
||||
<script src="../3rdparty/d3.min.js"></script>
|
||||
</head>
|
||||
<body onload="Doctest.run()">
|
||||
<h1>Text</h1>
|
||||
<p>
|
||||
The tooltip or infotip or a hint is a common graphical user interface element. It is used in conjunction with a cursor, usually a pointer. The user hovers the pointer over an item, without clicking it, and a tooltip may appear—a small "hover box" with information about the item being hovered over.[1][2] Tooltips do not usually appear on mobile operating systems, because there is no cursor (though tooltips may be displayed when using a mouse).
|
||||
The Button class defines a clickable/touchable button. Use custom button styles for actions in forms, dialogs,
|
||||
and more with support for multiple sizes, states, and more. Buttons will appear pressed when active. Make
|
||||
buttons look inactive by setting the disabled state to true. To allow changing the state between active/inactive, set
|
||||
the button type to "checkbox".
|
||||
</p>
|
||||
<p>Let's look at some tooltip examples:</p><br />
|
||||
<p><a href="../../doc/out/Text.html">JavaScript API</a></p>
|
||||
<p>Let's look at some text examples:</p><br />
|
||||
<canvas id="canvas" class="interactive"></canvas>
|
||||
<p>
|
||||
What you should see: Ten colored circles with different tooltips.
|
||||
What you should see: Many texts with very different styling and behaviour.
|
||||
</p>
|
||||
<script class="doctest">
|
||||
const app = new PIXIApp({
|
||||
view: canvas,
|
||||
width: 900,
|
||||
height: 500,
|
||||
transparent: false,
|
||||
backgroundColor: 0x2c2d2b
|
||||
height: 600,
|
||||
transparent: false
|
||||
}).setup().run()
|
||||
|
||||
const container = new PIXI.Graphics()
|
||||
container.beginFill(0x58595b, 1)
|
||||
container.drawRect(0, 0, 700, 300)
|
||||
container.pivot.set(container.width / 2, container.height / 2)
|
||||
container.position.set(450, 250)
|
||||
app.scene.addChild(container)
|
||||
|
||||
const sixthWidth = container.width / 6
|
||||
const halfHeight = container.height / 2
|
||||
|
||||
app.loadSprites([
|
||||
'./assets/stuttgart-library.jpg',
|
||||
'./assets/Arial.fnt'
|
||||
], sprites => {
|
||||
|
||||
// PIXI.Text
|
||||
//--------------------
|
||||
const text = new PIXI.Text('Bibliothek\nStuttgart', {fontSize: 50})
|
||||
text.x = sixthWidth
|
||||
text.y = halfHeight
|
||||
text.pivot.set(text.width / 2, text.height / 2)
|
||||
container.addChild(text)
|
||||
|
||||
// PIXI.BitmapText
|
||||
//--------------------
|
||||
const bitmapText = new PIXI.BitmapText('Bibliothek\nStuttgart', {
|
||||
font: '50px Arial',
|
||||
align: 'left'
|
||||
})
|
||||
bitmapText.x = sixthWidth * 3
|
||||
bitmapText.y = halfHeight
|
||||
bitmapText.pivot.set(bitmapText.width / 2, bitmapText.height / 2)
|
||||
container.addChild(bitmapText)
|
||||
|
||||
// PIXI.Sprite
|
||||
//--------------------
|
||||
const sprite = sprites.get('./assets/stuttgart-library.jpg')
|
||||
sprite.scale.set(.05, .05)
|
||||
sprite.x = sixthWidth * 5
|
||||
sprite.y = halfHeight
|
||||
sprite.anchor.set(.5, .5)
|
||||
container.addChild(sprite)
|
||||
|
||||
// Scale
|
||||
//--------------------
|
||||
const scaleContainer = d3.scaleLinear().domain([0, 50, 100]).range([.05, 1, 50])
|
||||
const scaleTexts = d3.scaleLinear().domain([0, 50, 100]).range([.1, 1, 10])
|
||||
const scaleSprite = d3.scaleLinear().domain([0, 50, 100]).range([.005, .05, .5])
|
||||
|
||||
// Sliders
|
||||
//--------------------
|
||||
const sliderContainer = new Slider({
|
||||
value: 50,
|
||||
width: 500,
|
||||
tooltip: 'Scale Container',
|
||||
container: app.view,
|
||||
onUpdate: function() {
|
||||
const value = scaleContainer(this.value)
|
||||
container.scale.set(value, value)
|
||||
}
|
||||
})
|
||||
sliderContainer.x = app.size.width / 2 - sliderContainer.width / 2
|
||||
sliderContainer.y = 10
|
||||
app.scene.addChild(sliderContainer)
|
||||
|
||||
const sliderContainerAll = new Slider({
|
||||
value: 50,
|
||||
width: 500,
|
||||
tooltip: 'Scale Container All',
|
||||
container: app.view,
|
||||
onUpdate: function() {
|
||||
const value = scaleContainer(this.value)
|
||||
container.scale.set(value, value)
|
||||
|
||||
text.scale.set(1 / value, 1 / value)
|
||||
bitmapText.scale.set(1 / value, 1 / value)
|
||||
}
|
||||
})
|
||||
sliderContainerAll.x = app.size.width / 2 - sliderContainerAll.width / 2
|
||||
sliderContainerAll.y = 55
|
||||
app.scene.addChild(sliderContainerAll)
|
||||
|
||||
const sliderText = new Slider({
|
||||
value: 50,
|
||||
tooltip: 'Scale PIXI.Text',
|
||||
container: app.view,
|
||||
onUpdate: function() {
|
||||
const value = scaleTexts(this.value)
|
||||
text.scale.set(value, value)
|
||||
}
|
||||
})
|
||||
sliderText.x = app.size.width / 6 - sliderText.width / 2
|
||||
sliderText.y = app.size.height - 10 - sliderText.height
|
||||
app.scene.addChild(sliderText)
|
||||
|
||||
const sliderBitmapText = new Slider({
|
||||
value: 50,
|
||||
tooltip: 'Scale PIXI.extras.BitmapText',
|
||||
container: app.view,
|
||||
onUpdate: function() {
|
||||
const value = scaleTexts(this.value)
|
||||
bitmapText.scale.set(value, value)
|
||||
}
|
||||
})
|
||||
sliderBitmapText.x = app.size.width / 6 * 3 - sliderBitmapText.width / 2
|
||||
sliderBitmapText.y = app.size.height - 10 - sliderBitmapText.height
|
||||
app.scene.addChild(sliderBitmapText)
|
||||
|
||||
const sliderSprite = new Slider({
|
||||
value: 50,
|
||||
tooltip: 'Scale PIXI.Sprite',
|
||||
container: app.view,
|
||||
onUpdate: function() {
|
||||
const value = scaleSprite(this.value)
|
||||
sprite.scale.set(value, value)
|
||||
}
|
||||
})
|
||||
sliderSprite.x = app.size.width / 6 * 5 - sliderSprite.width / 2
|
||||
sliderSprite.y = app.size.height - 10 - sliderSprite.height
|
||||
app.scene.addChild(sliderSprite)
|
||||
|
||||
}, {resolutionDependent: false})
|
||||
const text1 = new Text({x: 10, y: 10})
|
||||
|
||||
app.scene.addChild(text1)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user