Add insertBefore and fix RadioButton.Item handling Fixes #152 and #148

This commit is contained in:
kusti8 2018-06-01 18:37:23 -04:00
parent 8f9f925ef7
commit 995314ff22
30 changed files with 240 additions and 60 deletions

102
package-lock.json generated
View file

@ -198,7 +198,8 @@
"anymatch": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.2.tgz",
"integrity": "sha1-VT3Lj5HjyImEXf26NMd3IbkLnXo=",
"integrity":
"sha512-0XNayC8lTHQ2OI8aljNCN3sSx6hsr/1+rlcDAotXJR7C1oZZHCNsfpbKwMjRA3Uqb5tF1Rae2oloTr4xpq+WjA==",
"dev": true,
"optional": true,
"requires": {
@ -253,7 +254,8 @@
"version": "1.1.0",
"resolved":
"https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.1.0.tgz",
"integrity": "sha1-NgSLv/TntH4TZkQxbJlmnqWukfE=",
"integrity":
"sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg==",
"dev": true
},
"arr-union": {
@ -1433,7 +1435,8 @@
"babylon": {
"version": "6.18.0",
"resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz",
"integrity": "sha1-ry87iPpvXB5MY00aD46sT1WzleM=",
"integrity":
"sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==",
"dev": true
},
"balanced-match": {
@ -1537,6 +1540,12 @@
"dev": true,
"optional": true
},
"bindings": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.0.tgz",
"integrity":
"sha512-DpLh5EzMR2kzvX1KIlVC0VkC3iZtHKTgdtZ0a3pglBZdaQFjt5S9g9xd1lE+YvXyfd6mtCeRnrUfOLYiTMlNSw=="
},
"block-stream": {
"version": "0.0.9",
"resolved":
@ -1928,7 +1937,8 @@
"version": "1.9.1",
"resolved":
"https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz",
"integrity": "sha1-wSYRB66y8pTr/+ye2eytUppgl+0=",
"integrity":
"sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==",
"requires": {
"color-name": "^1.1.1"
}
@ -2151,7 +2161,8 @@
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha1-XRKFFd8TT/Mn6QpMk/Tgd6U2NB8=",
"integrity":
"sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
@ -2755,7 +2766,8 @@
"version": "1.1.0",
"resolved":
"https://registry.npmjs.org/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz",
"integrity": "sha1-4y/AMKLM7kSmtTcTCNpUvgs5fSc=",
"integrity":
"sha512-GNanXlVr2pf02+sPN40XN8HG+ePaNcvM0q5mZBd668Obwb0yD5GiUbZOFgwn8kGMY6I3mdyDJzieUy3PTYyTRA==",
"dev": true
},
"fs.realpath": {
@ -3402,7 +3414,8 @@
"globals": {
"version": "9.18.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz",
"integrity": "sha1-qjiWs+abSH8X4x7SFD1pqOMMLYo=",
"integrity":
"sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==",
"dev": true
},
"got": {
@ -3615,7 +3628,8 @@
"version": "0.4.19",
"resolved":
"https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz",
"integrity": "sha1-90aPYBNfXl2tM5nAqBvpoWA6CCs="
"integrity":
"sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ=="
},
"import-lazy": {
"version": "2.1.0",
@ -3658,7 +3672,8 @@
"ini": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
"integrity": "sha1-7uJfVtscnsYIXgwid4CD9Zar+Sc="
"integrity":
"sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw=="
},
"invariant": {
"version": "2.2.2",
@ -3706,7 +3721,8 @@
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha1-76ouqdqg16suoTqXsritUf776L4=",
"integrity":
"sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
"dev": true
},
"is-builtin-module": {
@ -5387,7 +5403,8 @@
"lodash": {
"version": "4.17.5",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",
"integrity": "sha1-maktZcAnLevoyWtgV7yPv6O+1RE=",
"integrity":
"sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==",
"dev": true
},
"lodash.sortby": {
@ -5486,7 +5503,8 @@
"lru-cache": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.1.tgz",
"integrity": "sha1-Yi4y6CSItJJ5EUpPns9F581rulU=",
"integrity":
"sha512-q4spe4KTfsAS1SUHLO0wz8Qiyf1+vMIAgpRYioFYDMNqKfHQbg+AVDH3i4fvpl71/P1L0dBl+fQi+P37UYf0ew==",
"dev": true,
"requires": {
"pseudomap": "^1.0.2",
@ -5605,7 +5623,8 @@
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=",
"integrity":
"sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "^1.1.7"
}
@ -5700,9 +5719,7 @@
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
"integrity":
"sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==",
"dev": true,
"optional": true
"sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA=="
},
"nanomatch": {
"version": "1.2.9",
@ -5783,7 +5800,8 @@
"version": "1.7.3",
"resolved":
"https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
"integrity": "sha1-mA9vcthSEaU0fGsrwYxbhMPrR+8=",
"integrity":
"sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
"requires": {
"encoding": "^0.1.11",
"is-stream": "^1.0.1"
@ -6335,7 +6353,8 @@
"private": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz",
"integrity": "sha1-I4Hts2ifelPWUxkAYPz4ItLzaP8=",
"integrity":
"sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==",
"dev": true
},
"process-nextick-args": {
@ -6358,7 +6377,8 @@
"promise": {
"version": "7.3.1",
"resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",
"integrity": "sha1-BktyYCsY+Q8pGSuLG8QY/9Hr078=",
"integrity":
"sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==",
"requires": {
"asap": "~2.0.3"
}
@ -6389,7 +6409,8 @@
"qs": {
"version": "6.5.1",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz",
"integrity": "sha1-NJzfbu+J7EXBLX1es/wMhwNDptg="
"integrity":
"sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A=="
},
"randomatic": {
"version": "3.0.0",
@ -6492,7 +6513,8 @@
"version": "0.7.0",
"resolved":
"https://registry.npmjs.org/react-reconciler/-/react-reconciler-0.7.0.tgz",
"integrity": "sha1-lhSJQQPl8Tje7rXquvPugOsdAm0=",
"integrity":
"sha512-50JwZ3yNyMS8fchN+jjWEJOH3Oze7UmhxeoJLn2j6f3NjpfCRbcmih83XTWmzqtar/ivd5f7tvQhvvhism2fgg==",
"requires": {
"fbjs": "^0.8.16",
"loose-envify": "^1.1.0",
@ -6526,7 +6548,8 @@
"version": "2.3.3",
"resolved":
"https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz",
"integrity": "sha1-No8lEtefnUb9/HE0mueHi7weuVw=",
"integrity":
"sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
@ -6564,7 +6587,8 @@
"version": "1.3.3",
"resolved":
"https://registry.npmjs.org/regenerate/-/regenerate-1.3.3.tgz",
"integrity": "sha1-DDNtOYBVPXVcObWGrjsgqknIK38=",
"integrity":
"sha512-jVpo1GadrDAK59t/0jRx5VxYWQEDkkEKi6+HjE3joFVLfDOh9Xrdh0dF1eSq+BI/SwvTQ44gSscJ8N5zYL61sg==",
"dev": true
},
"regenerator-runtime": {
@ -6579,7 +6603,8 @@
"version": "0.10.1",
"resolved":
"https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.10.1.tgz",
"integrity": "sha1-HkmWg3Ix2ot/PPQRTXG1aRoGgN0=",
"integrity":
"sha512-PJepbvDbuK1xgIgnau7Y90cwaAmO/LCLMI2mPvaXq2heGMR3aWW5/BQvYrhJ8jgmQjXewXvBjzfqKcVOmhjZ6Q==",
"dev": true,
"requires": {
"babel-runtime": "^6.18.0",
@ -6591,7 +6616,8 @@
"version": "0.4.4",
"resolved":
"https://registry.npmjs.org/regex-cache/-/regex-cache-0.4.4.tgz",
"integrity": "sha1-db3FiioUls7EihKDW8VMjVYjNt0=",
"integrity":
"sha512-nVIZwtCjkC9YgvWkpM55B5rBhBYRZhAaJbgcFYXXsHnbZ9UZI9nnVWYZpBlCqv9ho2eZryPnWrZGsOdPwVWXWQ==",
"dev": true,
"requires": {
"is-equal-shallow": "^0.1.3"
@ -6829,7 +6855,8 @@
"version": "5.1.1",
"resolved":
"https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
"integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM="
"integrity":
"sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
},
"safe-regex": {
"version": "1.1.0",
@ -6848,6 +6875,17 @@
"sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==",
"dev": true
},
"segfault-handler": {
"version": "1.0.1",
"resolved":
"https://registry.npmjs.org/segfault-handler/-/segfault-handler-1.0.1.tgz",
"integrity":
"sha512-3koBV3F0IPxTYacnoL7WoFlaMndXsXj62tiVbbW9Kzp3K+F9Y6GWW5XmKSv7j+7nf2M+qjNzc4W1iZoa8vocjw==",
"requires": {
"bindings": "^1.2.1",
"nan": "^2.0.9"
}
},
"semver": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
@ -7144,7 +7182,8 @@
"version": "0.4.18",
"resolved":
"https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz",
"integrity": "sha1-Aoam3ovkJkEzhZTpfM6nXwosWF8=",
"integrity":
"sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==",
"dev": true,
"requires": {
"source-map": "^0.5.6"
@ -7314,7 +7353,8 @@
"version": "1.0.3",
"resolved":
"https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha1-D8Z9fBQYJd6UKC3VNr7GubzoYKs=",
"integrity":
"sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"requires": {
"safe-buffer": "~5.1.0"
}
@ -7629,7 +7669,8 @@
"version": "0.7.17",
"resolved":
"https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz",
"integrity": "sha1-6exflJi57JEOeuOsYmqAXE0J7Kw="
"integrity":
"sha512-uRdSdu1oA1rncCQL7sCj8vSyZkgtL7faaw9Tc9rZ3mGgraQ7+Pdx7w5mnOSF3gw9ZNG6oc+KXfkon3bKuROm0g=="
},
"ultron": {
"version": "1.1.1",
@ -7943,7 +7984,8 @@
"which": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz",
"integrity": "sha1-/wS9/AEO5UfXgL7DjhrBwnd9JTo=",
"integrity":
"sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==",
"requires": {
"isexe": "^2.0.0"
}

View file

@ -34,6 +34,7 @@
"prop-types": "^15.6.1",
"react": "^16.3.2",
"react-reconciler": "^0.7.0",
"segfault-handler": "^1.0.1",
"svg-path-parser": "^1.1.0"
},
"devDependencies": {

View file

@ -12,10 +12,14 @@ class App extends DesktopComponent {
super(root, props);
this.root = root;
this.props = { ...props };
this.element = {};
this.newElement();
this.setDefaults(props);
}
newElement() {
this.element = {};
}
update(oldProps, newProps) {
if (newProps.onShouldQuit !== oldProps.onShouldQuit) {
libui.Ui.onShouldQuit(() => {

View file

@ -14,10 +14,14 @@ class Button extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiButton();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiButton();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -14,10 +14,14 @@ class Checkbox extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiCheckbox();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiCheckbox();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -18,10 +18,14 @@ class ColorButton extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiColorButton();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiColorButton();
}
toColorLibui(input) {
input = input.toLowerCase();
let alpha;

View file

@ -13,10 +13,14 @@ class Combobox extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiCombobox();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiCombobox();
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -84,6 +84,13 @@ class DesktopComponent {
// we are already closing, so we don't want to do it again
child.element.close();
}
} else if (
child instanceof RadioButton.Item ||
child instanceof Combobox.Item ||
child instanceof EditableCombobox.Item
) {
// these don't have deleteAt functions
this.removeChildManual(child);
}
const index = this.children.indexOf(child);
this.children.splice(index, 1);
@ -109,6 +116,36 @@ class DesktopComponent {
}
}
insertChild(child, beforeChild) {
// used in reconciler to add a new child before others
const beforeIndex = this.children.indexOf(beforeChild);
for (let i = this.children.length - 1; i >= beforeIndex; i--) {
// we go backwards cause otherwise we're trying to remove indexes in libui that don't exist, but still do in our local children array
this.deparentChild(this.children[i]); // we remove all the children from the parent
}
this.children.splice(beforeIndex, 0, child); // insert our child
for (let i = beforeIndex; i < this.children.length; i++) {
this.reparentChild(this.children[i]);
}
}
removeChildManual(child) {
// used for RadioButtons and Picker to delete an Item
const index = this.children.indexOf(child);
for (let i = this.lastParent.children.length - 1; i >= 0; i--) {
// we go backwards cause otherwise we're trying to remove indexes in libui that don't exist, but still do in our local children array
this.lastParent.deparentChild(this.lastParent.children[i]); // we remove all the children from the parent
}
this.newElement();
for (let child of this.lastParent.children) {
this.lastParent.reparentChild(child); // add back all of the children, in the same order
}
this.initialProps(this.props);
}
renderChildNode(parent) {
// render the children
for (let i = 0; i < this.children.length; i += 1) {
@ -171,6 +208,7 @@ class DesktopComponent {
}
addParent(parent) {
this.lastParent = parent;
// add itself to the parent
if (this.exists(parent.element.setChild)) {
parent.element.setChild(this.element);

View file

@ -13,10 +13,14 @@ class EditableCombobox extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiEditableCombobox();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiEditableCombobox();
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -14,10 +14,14 @@ class Entry extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiEntry();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiEntry();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -13,10 +13,14 @@ class FontButton extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiFontButton();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiFontButton();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -11,10 +11,14 @@ class Form extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiForm();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiForm();
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -11,10 +11,14 @@ class Grid extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiGrid();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiGrid();
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -11,10 +11,14 @@ class Group extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiGroup();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiGroup();
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -11,10 +11,14 @@ class HorizontalBox extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiHorizontalBox();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiHorizontalBox();
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -11,10 +11,14 @@ class HorizontalSeparator extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiHorizontalSeparator();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiHorizontalSeparator();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -19,10 +19,14 @@ class MenuBar extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiMenu(this.props.label);
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiMenu(this.props.label);
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -14,10 +14,14 @@ class MultilineEntry extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiMultilineEntry();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiMultilineEntry();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -14,10 +14,14 @@ class PasswordEntry extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiPasswordEntry();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiPasswordEntry();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -11,10 +11,14 @@ class ProgressBar extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiProgressBar();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiProgressBar();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -13,10 +13,14 @@ class RadioButton extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiRadioButtons();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiRadioButtons();
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -10,6 +10,9 @@ class Root extends DesktopComponent {
super();
libui.startLoop();
}
newElement() {}
render() {
this.renderChildNode();
}

View file

@ -13,23 +13,26 @@ class Slider extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiSlider(this.props.min, this.props.max);
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiSlider(this.props.min, this.props.max);
}
minMaxAdjusted(prop, newProps) {
this.props[prop] = newProps[prop];
this.props.value = newProps.value; // save the value, so that it doesn't reset
this.props = { ...newProps };
for (let i = this.lastParent.children.length - 1; i >= 0; i--) {
// we go backwards cause otherwise we're trying to remove indexes in libui that don't exist, but still do in our local children array
this.lastParent.deparentChild(this.lastParent.children[i]); // we remove all the children from the parent
}
const index = this.lastParent.children.indexOf(this); // we store where we are in the child list
this.element = new libui.UiSlider(this.props.min, this.props.max); // we make a new element
for (let child of this.lastParent.children) {
this.lastParent.reparentChild(child); // add back all of the children, in the same order
}
if (
this.props.value > this.props.max ||
this.props.value < this.props.min
@ -40,11 +43,10 @@ class Slider extends DesktopComponent {
); // make the value inside the range
this.props.onChange(this.props.value); // and trigger onChange so that the value can get updated
}
this.element.value = this.props.value; // put back the previous value, since this.element.value gets reset
this.initialProps(this.props);
}
render(parent) {
this.lastParent = parent;
this.addParent(parent);
this.renderChildNode();
}

View file

@ -13,10 +13,14 @@ class Spinbox extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiSpinbox();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiSpinbox();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -11,10 +11,14 @@ class Tab extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiTab();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiTab();
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -13,10 +13,14 @@ class Text extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiLabel();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiLabel();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -11,10 +11,14 @@ class VerticalBox extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiVerticalBox();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiVerticalBox();
}
render(parent) {
this.addParent(parent);
this.renderChildNode(this);

View file

@ -11,10 +11,14 @@ class VerticalSeparator extends DesktopComponent {
this.root = root;
this.props = { ...props };
this.setDefaults(props);
this.element = new libui.UiVerticalSeparator();
this.newElement();
this.initialProps(this.props);
}
newElement() {
this.element = new libui.UiVerticalSeparator();
}
render(parent) {
this.addParent(parent);
this.renderChildNode();

View file

@ -18,6 +18,8 @@ class Window extends DesktopComponent {
this.setDefaults(props);
}
newElement() {}
update(oldProps, newProps) {
this.props = { ...newProps };
this.setDefaults(newProps);

View file

@ -83,7 +83,7 @@ const DesktopRenderer = Reconciler({
},
insertBefore(parentInstance, child, beforeChild) {
// noob
parentInstance.insertChild(child, beforeChild);
},
commitUpdate(instance, updatePayload, type, oldProps, newProps) {