initial player stuff

This commit is contained in:
Blue 2018-08-05 00:52:16 +03:00 committed by Gitea
parent 4b60ece582
commit 00f26c431e
38 changed files with 1107 additions and 93 deletions

View file

@ -11,5 +11,6 @@ configure_file(mainLayout.js mainLayout.js)
configure_file(page.js page.js)
configure_file(pane.js pane.js)
configure_file(image.js image.js)
configure_file(button.js button.js)
add_subdirectory(helpers)

95
lorgar/views/button.js Normal file
View file

@ -0,0 +1,95 @@
"use strict";
(function() {
var moduleName = "views/button";
var deps = [];
deps.push("views/layout");
deps.push("views/label");
define(moduleName, deps, function() {
var Layout = require("views/layout");
var Label = require("views/label");
var Button = Layout.inherit({
"className": "Button",
"constructor": function(controller, options) {
var base = {
padding: 5
};
W.extend(base, options)
Layout.fn.constructor.call(this, controller, base);
this.addClass("hoverable");
this._enabled = true;
this._hasLabel = false;
this._e.addEventListener("click", this._onClick.bind(this), false);
controller.on("setEnabled", this._onSetEnabled, this);
controller.on("setLabel", this._onSetLabel, this);
},
"destructor": function() {
this._f.off("setEnabled", this._onSetEnabled, this);
this._f.off("setLabel", this._onSetLabel, this);
Layout.fn.destructor.call(this);
},
"append": function(child, aligment, index) {
this._updateLimits();
Layout.fn.append.call(this, child, aligment, index);
},
"_onChildChangeLimits": function(child) {
this._updateLimits();
Layout.fn._onChildChangeLimits.call(this, child);
},
"_onClick": function() {
if (this._enabled) {
this._f.activate();
}
},
"_onSetEnabled": function(enabled) {
if (this._enabled !== enabled) {
this._enabled = enabled;
if (this._enabled) {
this.addClass("hoverable");
this.removeClass("disabled");
} else {
this.removeClass("hoverable");
this.addClass("disabled");
}
}
},
"_onSetLabel": function(hasLabel, label) {
if (this._hasLabel !== hasLabel) {
this._hasLabel = hasLabel;
if (this._hasLabel) {
this._label = new Label(label);
this.append(this._label, Layout.Aligment.CenterCenter);
} else {
this._label.destructor();
delete this._label();
}
}
},
"_updateLimits": function() {
var minWidth = this._o.padding * 2;
var maxWidth = this._o.padding * 2;
var minHeight = this._o.padding * 2;
var maxHeight = this._o.padding * 2;
if (this._hasLabel) {
minWidth += this._label._o.minWidth;
minHeight += this._label._o.minHeight;
maxWidth += this._label._o.maxWidth;
maxHeight += this._label._o.maxHeight;
}
this._setLimits(minWidth, minHeight, maxWidth, maxHeight);
}
});
return Button;
})
})();

View file

@ -76,8 +76,12 @@
}
}
if (this._w !== undefined && this._h !== undefined) {
child.setSize(this._w, this._h);
index = index || this._c.length - 1;
var c = this._c[index];
this._positionElement(c);
}
},
"clear": function() {

View file

@ -191,9 +191,12 @@
}
if (needToTell) {
this.trigger("changeLimits", this);
if (this._w !== undefined && this._h !== undefined) {
this.setSize(this._w, this._h);
}
}
return needToTell && this._events.changeLimits && this._events.changeLimits.length; //to see if someone actually going to listen that event
return needToTell && this._events.changeLimits && this._events.changeLimits.length; //to see if someone actually going to listen that event, if not - return result
},
"setMaxSize": function(w, h) {
this._o.maxWidth = w;
@ -284,22 +287,27 @@
View.ViewType = {
Label: 0,
Image: 3,
View: 4,
Image: 4,
Button: 5,
View: 6,
Page: 102,
PanesList: 104
PanesList: 104,
Player: 107
};
View.ReversedViewType = {
"0": "Label",
"3": "Image",
"4": "View",
"4": "Image",
"5": "Button",
"6": "View",
"101": "Nav",
"102": "Page",
"104": "PanesList"
"104": "PanesList",
"107": "Player"
};
View.ViewTypesPaths = {
@ -307,7 +315,9 @@
Nav: "views/nav",
Page: "views/page",
PanesList: "views/panesList",
Image: "views/image"
Image: "views/image",
Button: "views/button",
Player: "views/player"
};
View.constructors = {