refining the resizing protocol...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-05-01 21:54:44 +03:00
parent d02795935e
commit abe5277f72
3 changed files with 64 additions and 29 deletions

View File

@ -18,6 +18,14 @@ var toggler = require('lib/toggler')
/*********************************************************************/ /*********************************************************************/
var protocolAction =
module.protocol = function(protocol, func){
return function(){
this[protocol].chainCall(this, func, arguments)
}
}
// NOTE: if not state is set this assumes that the first state is the // NOTE: if not state is set this assumes that the first state is the
// default... // default...
var makeConfigToggler = var makeConfigToggler =

View File

@ -592,12 +592,36 @@ module.ViewerActions = actions.Actions({
// Zooming/scaling root action... // Zooming/scaling root action...
// //
// Protocol: // Protocol:
// - all root zoom/scale action bust be wrapped in the .resizing action // - a compliant action must be wrapped in the .resizing action
// - a compliant action must pass the sizing unit, value and
// overflow to the wrapping action.
//
// Example:
// actionName: ['...',
// function(value){
// this.resizing.chainCall(this, function(){
//
// // action code...
//
// },
// // action unit...
// 'scale',
// // action value...
// scale)
// }],
//
// //
// This will enable clients to attach to a single in/out point. // This will enable clients to attach to a single in/out point.
// //
// NOTE: not intended for direct use... // NOTE: not intended for direct use...
resizing: ['- Zoom/', function(){}], resizing: ['- Zoom/', function(unit, size, overflow){
// This is a resizing protocol root function.
//
// This will never be used directly, but will wrap protocol user
// functions.
//
// As an example see: .setScale(..)
}],
// Root zoom/sclae actions... // Root zoom/sclae actions...
// //
@ -607,14 +631,14 @@ module.ViewerActions = actions.Actions({
this.resizing.chainCall(this, function(){ this.resizing.chainCall(this, function(){
this.ribbons && scale && this.ribbons.scale(scale) this.ribbons && scale && this.ribbons.scale(scale)
this.refresh() this.refresh()
}) }, 'scale', scale)
}], }],
fitOrig: ['Zoom/Fit to original scale', fitOrig: ['Zoom/Fit to original scale',
function(){ function(){
this.resizing.chainCall(this, function(){ this.resizing.chainCall(this, function(){
this.ribbons.scale(1) this.ribbons.scale(1)
this.refresh() this.refresh()
}) }, 'scale', 1)
}], }],
// NOTE: if this gets a count argument it will fit count images, // NOTE: if this gets a count argument it will fit count images,
// default is one. // default is one.
@ -633,7 +657,7 @@ module.ViewerActions = actions.Actions({
} }
this.ribbons.fitImage(count) this.ribbons.fitImage(count)
this.refresh() this.refresh()
}) }, 'screenwidth', count, overflow)
}], }],
// NOTE: this does not accout for ribbon spacing... // NOTE: this does not accout for ribbon spacing...
fitRibbon: ['Zoom/Fit ribbon vertically', fitRibbon: ['Zoom/Fit ribbon vertically',
@ -641,7 +665,7 @@ module.ViewerActions = actions.Actions({
this.resizing.chainCall(this, function(){ this.resizing.chainCall(this, function(){
this.ribbons.fitRibbon(count, whole) this.ribbons.fitRibbon(count, whole)
this.refresh() this.refresh()
}) }, 'screenheight', count, whole)
}], }],
@ -1487,31 +1511,31 @@ module.PartialRibbons = core.ImageGridFeatures.Feature({
function(_, target){ function(_, target){
this.preCacheJumpTargets(target) this.preCacheJumpTargets(target)
}], }],
['setScale.pre',
function(s){
this.updateRibbon('current', this.screenwidth / s || 1)
//this.preCacheJumpTargets()
}],
['resizing.pre', ['resizing.pre',
function(n){ function(unit, size){
this.updateRibbon('current', n || 1) if(unit == 'scale'){
//this.preCacheJumpTargets() this.updateRibbon('current', this.screenwidth / size || 1)
}],
['fitRibbon.pre',
function(n){
n = n || 1
// convert target height in ribbons to width in images... } else if(unit == 'screenwidth'){
// NOTE: this does not account for compensation that this.updateRibbon('current', size || 1)
// .updateRibbon(..) makes for fitting whole image
// counts, this is a small enough error so as not } else if(unit == 'screenheight'){
// to waste time on... size = size || 1
var s = this.ribbons.scale()
var h = this.ribbons.getScreenHeightRibbons() // convert target height in ribbons to width in images...
var w = this.ribbons.getScreenWidthImages() // NOTE: this does not account for compensation that
var nw = w / (h/n) // .updateRibbon(..) makes for fitting whole image
// counts, this is a small enough error so as not
// to waste time on...
var s = this.ribbons.scale()
var h = this.ribbons.getScreenHeightRibbons()
var w = this.ribbons.getScreenWidthImages()
var nw = w / (h/size)
this.updateRibbon('current', nw)
}
this.updateRibbon('current', nw)
//this.preCacheJumpTargets() //this.preCacheJumpTargets()
}], }],
], ],

View File

@ -87,6 +87,9 @@ var object = require('lib/object')
// <action-set>.getDoc(<action-name>[, ..]) // <action-set>.getDoc(<action-name>[, ..])
// -> dict of action-name, doc // -> dict of action-name, doc
// //
// <action-set>.a.getHandlerDocStr(<action-name>)
// -> formated string of action handlers
//
// <action-set>.actions // <action-set>.actions
// -> list of action names // -> list of action names
// //