Skip to content

Commit

Permalink
Merge pull request #3 from bpxl-labs/feature/focus-debugging
Browse files Browse the repository at this point in the history
Improvements to debugging.
  • Loading branch information
brandonjpierce authored Jul 21, 2017
2 parents c5a150c + 73fac6c commit 66ecbfd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
19 changes: 16 additions & 3 deletions FocusEngine.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
layerA.on "unfocus", ->
layerA.on "selected", ->
# Check the currently focused layer
print fe.focus
# Check whether a layer has focus
print layerA.focus
# Integration with RemoteLayer (https://github.com/bpxl-labs/RemoteLayer)
RemoteLayer = require "RemoteLayer"
myRemote = new RemoteLayer
Expand Down Expand Up @@ -94,9 +100,9 @@ exports.unfocusStyle =
exports.initialize = (focusableArray) ->
exports.focusable = focusableArray
for layer in exports.focusable
layer.focus = false
styleLayer(layer)


# layer visibility
checkVisible = (layer) ->
isVisible = true
Expand Down Expand Up @@ -125,13 +131,15 @@ exports.placeFocus = Utils.throttle 0.1, (layer = null) ->
exports.focus = layer
unfocusAll()
layer.emit "focus"
layer.focus = true
if layer != null and layer in exports.focusable
layer?.animate("focus")

unfocusAll = () ->
for layer in exports.focusable
if layer.states.current.name == "focus"
if layer.focus == true
layer.emit "unfocus"
layer.focus = false
layer.animate("unfocus")

exports.focusPrevious = () ->
Expand All @@ -140,6 +148,7 @@ exports.focusPrevious = () ->

exports.addLayer = (layer) ->
exports.focusable.push(layer)
layer.focus = false
styleLayer(layer)

styleLayer = (layer) ->
Expand All @@ -162,8 +171,12 @@ styleLayer = (layer) ->
layer.animate("unfocus", instant: true)

exports.changeFocus = Utils.throttle 0.1, (direction) ->
# if focus was never placed, give up
if exports.focus == null and exports.initialFocus == null
print "No initial focus set. Use placeFocus(layer) to set."
return
if exports.debug == true
print "current: " + exports.focus?.name + "; direction: " + direction
print "focus was: " + (exports.focus?.name or exports.focus?.__framerInstanceInfo?.name or "unnamed layer") + "; direction: " + direction
tempArray = []
# if we've lost all focus, reset
if exports.focus == null or exports.focus == undefined
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ myRemote = new RemoteLayer
fe.debug = true
```

#### Check the currently focused layer
```coffeescript
print fe.focus
```

#### Check whether a layer has focus
```coffeescript
print layerA.focus
```

#### Known issues

Attempting to perform a `placeFocus()` call as FocusEngine is changing its own focus will fail. (The call is discarded.) If you need to override FocusEngine's logic, Use a slight delay to ensure the call is respected.
Expand Down

0 comments on commit 66ecbfd

Please sign in to comment.