Skip to content

Commit

Permalink
fixed .move values being reset when using .resize()
Browse files Browse the repository at this point in the history
  • Loading branch information
newk5 committed Jul 29, 2020
1 parent a0eafa2 commit d231b9a
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 2 deletions.
106 changes: 106 additions & 0 deletions script/decui/UI/Store.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
class Store {

data = null;
constructor(d = {}) {
this.data = {};

foreach (key,v in d){
local t = typeof v;
if (t=="string" || t == "bool" || t=="integer"){
this.put(key,v);
}else{
this.initDefaults(v);
this.data[key] <- v;
}
}


}

function put(key, value, opts={value=null, el="", elID=""}) {
this.initDefaults(opts);
opts.value = value;
this.data[key] <- opts;
}

function attachIDAndType(key,id, type) {
if (this.data.rawin(key)){
local o = this.getEntry(key);
o.elID = id;
o.el = type;
}
}

function set(key, val){
if (this.data.rawin(key)){
local o = this.data[key];
local old = o.value;
o.value = val;
if (o.el=="GUIEditbox" ){
UI.Editbox(o.elID).Text =val+"";
} else if (o.el=="GUICheckbox"){
if (val == true){
UI.Checkbox(o.elID).AddFlags(GUI_FLAG_CHECKBOX_CHECKED);
}else{
UI.Checkbox(o.elID).RemoveFlags(GUI_FLAG_CHECKBOX_CHECKED);
}

} else if (o.el=="GUILabel"){
UI.Label(o.elID).setText(val+"");
}
if (o.onChange != null){
o.onChange(old, val);
}

}
}


function get(key){
if (key.find(".")){
local fields = split(key,".");
local o = this.getEntry(fields[0]);

if (o != null){

local val = o.value;
fields = fields.filter(function(idx,e) {
return e != fields[0];
});
foreach (field in fields ) {
val = val[field];
}
return val;
}
}
if (this.data.rawin(key)){
return this.data[key].value;
}
return null;
}

function getEntry(key){
if (this.data.rawin(key)){
return this.data[key];
}
return null;
}

function initDefaults(opts){

if (!opts.rawin("value")){
opts["value"] <- null;
}
if (!opts.rawin("el")){
opts["el"] <- "";
}
if (!opts.rawin("elID")){
opts["elID"] <- "";
}
if (!opts.rawin("onChange")){
opts["onChange"] <- null;
}


}
}
39 changes: 38 additions & 1 deletion script/decui/UI/UI.nut
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ class UI {
listsNumeration = null;
fetch = null;
events = null;
store = null;
streamControllers = [];
lastClickedEl = null;
openNots = 0;
notsHeight = 0;



constructor() {

this.toDelete =[];
Expand All @@ -35,10 +38,14 @@ class UI {
foreach (idx, name in names) {
listsNumeration[name] <- 0;
}

this.fetch = Fetch(this);
this.events = Events(this);
}

function Data(data) {
this.store= Store(data);
}

function processStream(streamIdentifier, stream){
foreach(i, sc in this.streamControllers) {
Expand Down Expand Up @@ -994,6 +1001,12 @@ class UI {

this.postConstruct(b);

this.postConstruct(b);
if (o.rawin("bindTo")){
this.store.attachIDAndType(o.bindTo,o.id, "GUILabel");
b.setText(this.store.get(o.bindTo));
}

return b;
}
function Editbox(o){
Expand All @@ -1013,8 +1026,22 @@ class UI {


this.postConstruct(b);
if (o.rawin("bindTo")){
this.store.attachIDAndType(o.bindTo,o.id, "GUIEditbox");
b.Text = this.store.get(o.bindTo);
}

return b;
}

function setData(key,val){
this.store.set(key,val);
}

function getData(key){
this.store.get(key);
}

function Canvas(o){
if (typeof o == "string") {
return this.fetch.canvas(o);
Expand Down Expand Up @@ -1100,6 +1127,16 @@ class UI {
this.listsNumeration.checkboxes++;

this.postConstruct(b);

if (o.rawin("bindTo")){
this.store.attachIDAndType(o.bindTo,o.id, "GUICheckbox");
local val = this.store.get(o.bindTo);
if (val){
b.AddFlags(GUI_FLAG_CHECKBOX_CHECKED);
}else{
b.RemoveFlags(GUI_FLAG_CHECKBOX_CHECKED);
}
}

return b;
}
Expand Down
1 change: 1 addition & 0 deletions script/decui/decui.nut
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dofile("decui/components/Grid.nut");
dofile("decui/UI/Fetch.nut");
dofile("decui/UI/Events.nut");
dofile("decui/UI/UI.nut");
dofile("decui/UI/Store.nut");

dofile("decui/util/StreamRequest.nut");
dofile("decui/util/StreamReader.nut");
Expand Down
6 changes: 5 additions & 1 deletion script/decui/extensions.nut
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ foreach(i,e in elements ) {
}

c.realign();
c.resetMoves();
c.shiftPos();
}
}

if (this.autoResize){
this.realign();
this.resetMoves();
this.shiftPos();
}

Expand Down Expand Up @@ -600,12 +602,14 @@ foreach(i,e in elements ) {
}
if (adjusted){
this.realign();
this.resetMoves();
this.shiftPos();

foreach (i, c in this.getChildren()) {
if (!c.rawin("className")) {
c.resetPosition();
c.realign();
c.resetMoves();
c.shiftPos();
}
}
Expand Down
1 change: 1 addition & 0 deletions script/main.nut
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ function Script::ScriptLoad(){
//dofile("NotificationDemo.nut")
//dofile("PopupDemo.nut")
//dofile("TabviewDemo.nut")


}

0 comments on commit d231b9a

Please sign in to comment.