Skip to content

Commit

Permalink
updated pixi-viewport to new version; fixed bug with overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfig committed Dec 12, 2018
1 parent 7841262 commit c85082a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Features:
* scrollbox's scrollbars may be hidden when not needed (options.overflow=auto or hidden)
* scrollbox may also be scrolled by dragging on the content window (options.dragScroll=true)

[**Live Example**](https://davidfig.github.io/pixi-scrollbox/)
## Live Example
[davidfig.github.io/pixi-scrollbox/](https://davidfig.github.io/pixi-scrollbox/)

## Rationale
I needed a scrollbox for the UI of my game and since I had this nifty pixi-viewport, I figured it wouldn't be much work to create it. Five hours later and I realized I was a bit off on my estimates. Hopefully others will find it useful.
Expand All @@ -33,7 +34,7 @@ app.stage.addChild(scrollbox);

## Usage

[![npm i pixi-scrollbox](https://nodei.co/npm/pixi-scrollbox.png?mini=true)](https://npmjs.org/package/pixi-scrollbox/)
npm i pixi-scrollbox

or [download the latest build from github](https://github.com/davidfig/pixi-scrollbox/releases)
```html
Expand All @@ -49,4 +50,4 @@ or [download the latest build from github](https://github.com/davidfig/pixi-scro

## license
MIT License
(c) 2018 [YOPEY YOPEY LLC](https://yopeyopey.com/) by [David Figatner](https://twitter.com/yopey_yopey/)
(c) 2018 [YOPEY YOPEY LLC](https://yopeyopey.com/) by [David Figatner](https://twitter.com/yopey_yopey/)
2 changes: 1 addition & 1 deletion docs/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function horizontalVertical(title)
function horizontal()
{
const size = 500
const scrollbox = _renderer.stage.addChild(new Scrollbox({ boxWidth: 300, boxHeight: 300 }))
const scrollbox = _renderer.stage.addChild(new Scrollbox({ boxWidth: 300, boxHeight: 300, overflowY: 'hidden' }))
scrollbox.position.set(50, 425)
const box = scrollbox.content.addChild(new PIXI.Graphics())
box.beginFill(0xff0000, 0.25).drawRect(0, 0, size, 290).endFill()
Expand Down
12 changes: 10 additions & 2 deletions src/scrollbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Scrollbox extends PIXI.Container

/**
* content in placed in here
* @type {PIXI.Container}
* you can use any function from pixi-viewport on content to manually move the content (see https://davidfig.github.io/pixi-viewport/jsdoc/)
* @type {PIXI.extras.Viewport}
*/
this.content = this.addChild(new Viewport({ passiveWheel: this.options.stopPropagation, stopPropagation: this.options.stopPropagation, screenWidth: this.options.boxWidth, screenHeight: this.options.boxHeight }))
this.content
Expand Down Expand Up @@ -386,7 +387,7 @@ class Scrollbox extends PIXI.Container
{
this.content
.drag({ clampWheel: true, direction })
.clamp({ direction, underflow: 'top-left' })
.clamp({ direction, underflow: 'none' })
}
}
}
Expand Down Expand Up @@ -511,6 +512,13 @@ class Scrollbox extends PIXI.Container
this.update()
}

/**
* ensure that the bounding box is visible
* @param {number} x - relative to content's coordinate system
* @param {number} y
* @param {number} width
* @param {number} height
*/
ensureVisible(x, y, width, height)
{
this.content.ensureVisible(x, y, width, height)
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,9 @@ pixi-gl-core@^1.1.4:
integrity sha1-i0tcQzsx5Bm8N53FZc4bg1qRs3I=

pixi-viewport@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/pixi-viewport/-/pixi-viewport-3.12.0.tgz#7a09620835113498bf9ab969cc5200567c9f4117"
integrity sha512-ODHKBOsMzcXErYZg7Svx+6dOfCsDof3tEgwfA9liMUKvElzS++bLke3lVUFbKXutfFgmuN/gxaW2fum3ZUE9bA==
version "3.13.0"
resolved "https://registry.yarnpkg.com/pixi-viewport/-/pixi-viewport-3.13.0.tgz#28e99283737bbde75d1502472d25702ffe81f816"
integrity sha512-/kTAohridT5zlBk049nhxgK0q8St581kYTEO5w7Ey6J2si0PZISCGyQKUsGCScmWIwPOV1RR6k/WhPVvDOzQpg==
dependencies:
eventemitter3 "^3.1.0"
penner "^0.1.3"
Expand Down

0 comments on commit c85082a

Please sign in to comment.