-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
8 changed files
with
303 additions
and
29 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,150 @@ | ||
# Виджет zb.ui.HelpBar | ||
|
||
## Описание конструктора | ||
Принимает на вход один необязательный параметр — объект, состоящий из необязательных полей: | ||
|
||
* `itemClass` | ||
* Тип — `Function`. | ||
* Контруктор элементов. | ||
* Значение по умолчанию — `zb.ui.HelpBarItem`. | ||
|
||
## Описание публичных методов | ||
|
||
### Метод `processHelpBarKey(zbKey[, opt_event])` | ||
|
||
#### Параметры | ||
* zbKey | ||
* Тип — `zb.device.input.Keys`. | ||
* opt_event | ||
* Тип — `KeyboardEvent=`. | ||
|
||
#### Описание | ||
Обрабатывает клавиши. | ||
|
||
### Метод `createItem(options)` | ||
|
||
#### Параметры | ||
Объект `options`, состоящий из обязательных полей: | ||
|
||
* `label` | ||
* Тип — `string`. | ||
* Текст элемента. | ||
* `keys` | ||
* Тип — `Array.<zb.device.input.Keys>`. | ||
* Массив из клавиш, которые должен обрабатывать элемент. | ||
* `cssClass` | ||
* Тип — `string`. | ||
* CSS-класс элемента. | ||
|
||
#### Описание | ||
Создает элемент по установленному классу с параметрами `options`. | ||
Возвращает элемент `zb.ui.HelpBar` типа `zb.ui.IHelpBarItem`. | ||
|
||
### Метод `setItems(items)` | ||
|
||
#### Параметры | ||
* items | ||
* Тип — `Array.<?zb.ui.IHelpBarItem>` | ||
|
||
#### Описание | ||
Устанавливает элементы в `zb.ui.HelpBar`. | ||
|
||
### Метод `setOrder(order)` | ||
|
||
#### Параметры | ||
* order | ||
* Тип — `?Array.<zb.device.input.Keys>`. | ||
|
||
#### Описание | ||
Устанавливает порядок отображения элементов согласно позиции их клавиш в массиве. | ||
|
||
### Метод `clear()` | ||
|
||
#### Описание | ||
Удаляет все элементы `zb.ui.HelpBar`. | ||
|
||
### Метод `getItem(zbKey)` | ||
|
||
#### Параметры | ||
* zbKey | ||
* Тип — `zb.device.input.Keys`. | ||
|
||
#### Описание | ||
Возвращает элемент `zb.ui.HelpBar` обрабатывающий клавишу `zbKey`. | ||
|
||
## Использование паттерна фабрика | ||
|
||
### Создание кнопки | ||
|
||
/** | ||
* @param {function()=} opt_callback | ||
* @return {zb.ui.HelpBarItem} | ||
*/ | ||
someApp.widgets.helpBarItemFactory.back = function(opt_callback) { | ||
var item = new zb.ui.HelpBarItem({ | ||
cssClass: '_back', | ||
label: 'Назад', | ||
keys: [zb.device.input.Keys.BACK] | ||
}); | ||
|
||
item.on(item.EVENT_CLICK, function() { | ||
opt_callback ? opt_callback() : app.back(); | ||
}); | ||
|
||
return item; | ||
}; | ||
|
||
/** | ||
* @param {function()=} opt_callback | ||
* @return {zb.ui.HelpBarItem} | ||
*/ | ||
someApp.widgets.helpBarItemFactory.exit = function(opt_callback) { | ||
var item = new zb.ui.HelpBarItem({ | ||
cssClass: '_exit', | ||
label: 'Выход', | ||
keys: [zb.device.input.Keys.EXIT] | ||
}); | ||
|
||
item.on(item.EVENT_CLICK, function() { | ||
opt_callback ? opt_callback() : app.exit(); | ||
}); | ||
|
||
return item; | ||
}; | ||
|
||
### Интеграция со сценой | ||
|
||
/** | ||
* @extends {zb.layers.CuteScene} | ||
* @constructor | ||
*/ | ||
someApp.scenes.SomeScene = function() { | ||
goog.base(this); | ||
|
||
this._createHelpBar(); | ||
}; | ||
goog.inherits(someApp.scenes.SomeScene, zb.layers.CuteScene); | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
someApp.scenes.SomeScene.prototype.processKey = function(zbKey, opt_event) { | ||
if (goog.base(this, 'processKey', zbKey, opt_event)) { | ||
return true; | ||
} | ||
return this._helpBar.processHelpBarKey(zbKey, opt_event); | ||
}; | ||
|
||
/** | ||
* @protected | ||
*/ | ||
someApp.scenes.SomeScene.prototype._createHelpBar = function() { | ||
this._helpBar = new zb.ui.HelpBar; | ||
this._helpBar.setItems([ | ||
someApp.widgets.helpBarItemFactory.back(), | ||
someApp.widgets.helpBarItemFactory.exit() | ||
]); | ||
|
||
this._container.appendChild(this._helpBar.getContainer()); | ||
this.appendWidget(this._helpBar); | ||
}; |
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
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
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
Oops, something went wrong.