lexgui 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/codeeditor.js +74 -90
- package/build/components/imui.js +34 -31
- package/build/lexgui.js +9 -9
- package/build/lexgui.module.js +7 -7
- package/package.json +1 -1
|
@@ -530,43 +530,83 @@ class CodeEditor {
|
|
|
530
530
|
return this.code.lines.join(min ? ' ' : '\n');
|
|
531
531
|
}
|
|
532
532
|
|
|
533
|
-
setText(text)
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
let num_lines = new_lines.length;
|
|
539
|
-
console.assert(num_lines > 0);
|
|
540
|
-
const first_line = new_lines.shift();
|
|
541
|
-
num_lines--;
|
|
533
|
+
setText( text ) {
|
|
534
|
+
|
|
535
|
+
console.assert( text.length > 0 );
|
|
536
|
+
let new_lines = text.split('\n');
|
|
542
537
|
|
|
538
|
+
this.code.lines = [].concat(new_lines);
|
|
539
|
+
|
|
540
|
+
let cursor = this.cursors.children[0];
|
|
541
|
+
let lastLine = new_lines.pop();
|
|
542
|
+
|
|
543
|
+
this.cursorToLine(cursor, new_lines.length); // Already substracted 1
|
|
544
|
+
this.cursorToPosition(cursor, lastLine.length);
|
|
545
|
+
|
|
546
|
+
this.processLines();
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
appendText( text ) {
|
|
550
|
+
|
|
543
551
|
let cursor = this.cursors.children[0];
|
|
544
552
|
let lidx = cursor.line;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
//
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
553
|
+
|
|
554
|
+
if( this.selection ) {
|
|
555
|
+
this.deleteSelection(cursor);
|
|
556
|
+
lidx = cursor.line;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
this.endSelection();
|
|
560
|
+
|
|
561
|
+
const new_lines = text.split('\n');
|
|
562
|
+
|
|
563
|
+
// Pasting Multiline...
|
|
564
|
+
if(new_lines.length != 1)
|
|
565
|
+
{
|
|
566
|
+
let num_lines = new_lines.length;
|
|
567
|
+
console.assert(num_lines > 0);
|
|
568
|
+
const first_line = new_lines.shift();
|
|
569
|
+
num_lines--;
|
|
570
|
+
|
|
571
|
+
const remaining = this.code.lines[lidx].slice(cursor.position);
|
|
572
|
+
|
|
573
|
+
// Add first line
|
|
574
|
+
this.code.lines[lidx] = [
|
|
575
|
+
this.code.lines[lidx].slice(0, cursor.position),
|
|
576
|
+
first_line
|
|
577
|
+
].join('');
|
|
578
|
+
|
|
579
|
+
this.cursorToPosition(cursor, (cursor.position + first_line.length));
|
|
580
|
+
|
|
581
|
+
// Enter next lines...
|
|
582
|
+
|
|
583
|
+
let _text = null;
|
|
584
|
+
|
|
585
|
+
for( var i = 0; i < new_lines.length; ++i ) {
|
|
586
|
+
_text = new_lines[i];
|
|
587
|
+
this.cursorToLine(cursor, cursor.line++, true);
|
|
588
|
+
// Add remaining...
|
|
589
|
+
if( i == (new_lines.length - 1) )
|
|
590
|
+
_text += remaining;
|
|
591
|
+
this.code.lines.splice( 1 + lidx + i, 0, _text);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if(_text) this.cursorToPosition(cursor, _text.length);
|
|
595
|
+
this.cursorToLine(cursor, cursor.line + num_lines);
|
|
596
|
+
this.processLines(lidx);
|
|
597
|
+
}
|
|
598
|
+
// Pasting one line...
|
|
599
|
+
else
|
|
600
|
+
{
|
|
601
|
+
this.code.lines[lidx] = [
|
|
602
|
+
this.code.lines[lidx].slice(0, cursor.position),
|
|
603
|
+
new_lines[0],
|
|
604
|
+
this.code.lines[lidx].slice(cursor.position)
|
|
605
|
+
].join('');
|
|
606
|
+
|
|
607
|
+
this.cursorToPosition(cursor, (cursor.position + new_lines[0].length));
|
|
608
|
+
this.processLine(lidx);
|
|
565
609
|
}
|
|
566
|
-
|
|
567
|
-
if (_text) this.cursorToPosition(cursor, _text.length);
|
|
568
|
-
this.cursorToLine(cursor, cursor.line + num_lines);
|
|
569
|
-
this.processLines(lidx);
|
|
570
610
|
}
|
|
571
611
|
|
|
572
612
|
loadFile( file ) {
|
|
@@ -1069,64 +1109,8 @@ class CodeEditor {
|
|
|
1069
1109
|
this.onsave( this.getText() );
|
|
1070
1110
|
return;
|
|
1071
1111
|
case 'v': // paste
|
|
1072
|
-
|
|
1073
|
-
if( this.selection ) {
|
|
1074
|
-
this.deleteSelection(cursor);
|
|
1075
|
-
lidx = cursor.line;
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
this.endSelection();
|
|
1079
|
-
|
|
1080
1112
|
let text = await navigator.clipboard.readText();
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
// Pasting Multiline...
|
|
1084
|
-
if(new_lines.length != 1)
|
|
1085
|
-
{
|
|
1086
|
-
let num_lines = new_lines.length;
|
|
1087
|
-
console.assert(num_lines > 0);
|
|
1088
|
-
const first_line = new_lines.shift();
|
|
1089
|
-
num_lines--;
|
|
1090
|
-
|
|
1091
|
-
const remaining = this.code.lines[lidx].slice(cursor.position);
|
|
1092
|
-
|
|
1093
|
-
// Add first line
|
|
1094
|
-
this.code.lines[lidx] = [
|
|
1095
|
-
this.code.lines[lidx].slice(0, cursor.position),
|
|
1096
|
-
first_line
|
|
1097
|
-
].join('');
|
|
1098
|
-
|
|
1099
|
-
this.cursorToPosition(cursor, (cursor.position + first_line.length));
|
|
1100
|
-
|
|
1101
|
-
// Enter next lines...
|
|
1102
|
-
|
|
1103
|
-
let _text = null;
|
|
1104
|
-
|
|
1105
|
-
for( var i = 0; i < new_lines.length; ++i ) {
|
|
1106
|
-
_text = new_lines[i];
|
|
1107
|
-
this.cursorToLine(cursor, cursor.line++, true);
|
|
1108
|
-
// Add remaining...
|
|
1109
|
-
if( i == (new_lines.length - 1) )
|
|
1110
|
-
_text += remaining;
|
|
1111
|
-
this.code.lines.splice( 1 + lidx + i, 0, _text);
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
if(_text) this.cursorToPosition(cursor, _text.length);
|
|
1115
|
-
this.cursorToLine(cursor, cursor.line + num_lines);
|
|
1116
|
-
this.processLines(lidx);
|
|
1117
|
-
}
|
|
1118
|
-
// Pasting one line...
|
|
1119
|
-
else
|
|
1120
|
-
{
|
|
1121
|
-
this.code.lines[lidx] = [
|
|
1122
|
-
this.code.lines[lidx].slice(0, cursor.position),
|
|
1123
|
-
new_lines[0],
|
|
1124
|
-
this.code.lines[lidx].slice(cursor.position)
|
|
1125
|
-
].join('');
|
|
1126
|
-
|
|
1127
|
-
this.cursorToPosition(cursor, (cursor.position + new_lines[0].length));
|
|
1128
|
-
this.processLine(lidx);
|
|
1129
|
-
}
|
|
1113
|
+
this.appendText(text);
|
|
1130
1114
|
return;
|
|
1131
1115
|
case 'x': // cut line
|
|
1132
1116
|
const to_copy = this.code.lines.splice(lidx, 1)[0];
|
package/build/components/imui.js
CHANGED
|
@@ -56,6 +56,7 @@ class ImUI {
|
|
|
56
56
|
// Mouse state
|
|
57
57
|
|
|
58
58
|
this.mousePosition = new LX.vec2();
|
|
59
|
+
this.setPointerCursor = false;
|
|
59
60
|
|
|
60
61
|
this.root = this.canvas = canvas;
|
|
61
62
|
}
|
|
@@ -121,22 +122,17 @@ class ImUI {
|
|
|
121
122
|
|
|
122
123
|
// Draw button
|
|
123
124
|
|
|
125
|
+
ctx.beginPath();
|
|
124
126
|
ctx.fillStyle = active ? "#666" : (hovered ? "#444" : "#222");
|
|
125
|
-
ctx.
|
|
127
|
+
ctx.roundRect( position.x, position.y, size.x + padding.x * 2.0, size.y + padding.y * 2.0, [8, 8, 8, 8] );
|
|
128
|
+
ctx.fill();
|
|
126
129
|
|
|
127
130
|
// Draw text
|
|
128
131
|
|
|
129
132
|
ctx.fillStyle = hovered ? "#fff" : "#ddd";
|
|
130
133
|
ctx.fillText( text, position.x + padding.x, position.y + metrics.actualBoundingBoxAscent + padding.y );
|
|
131
134
|
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
document.body.style.cursor = "default";
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Pointer cursor on hover
|
|
139
|
-
document.body.style.cursor = "pointer";
|
|
135
|
+
this.setPointerCursor |= hovered;
|
|
140
136
|
|
|
141
137
|
if( this.eventClick )
|
|
142
138
|
{
|
|
@@ -176,50 +172,53 @@ class ImUI {
|
|
|
176
172
|
|
|
177
173
|
const metrics = ctx.measureText( text );
|
|
178
174
|
let size = new LX.vec2( metrics.width, metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent );
|
|
175
|
+
let fullSize = size.add( padding.mul( 2.0 ) );
|
|
179
176
|
|
|
180
177
|
// Get mouse state
|
|
181
178
|
|
|
182
|
-
const hovered = this.mousePosition.x >= position.x && this.mousePosition.x <= (position.x +
|
|
183
|
-
&& this.mousePosition.y >= position.y && this.mousePosition.y <= (position.y +
|
|
179
|
+
const hovered = this.mousePosition.x >= position.x && this.mousePosition.x <= (position.x + fullSize.x)
|
|
180
|
+
&& this.mousePosition.y >= position.y && this.mousePosition.y <= (position.y + fullSize.y);
|
|
184
181
|
|
|
185
182
|
const active = hovered && this.mouseDown;
|
|
186
183
|
|
|
187
184
|
// Draw box
|
|
188
185
|
|
|
186
|
+
ctx.beginPath();
|
|
189
187
|
ctx.fillStyle = hovered ? "#444" : "#222";
|
|
190
|
-
ctx.
|
|
191
|
-
|
|
192
|
-
// Draw thumb
|
|
188
|
+
ctx.roundRect( position.x, position.y, fullSize.x, fullSize.y, [8, 8, 8, 8] );
|
|
189
|
+
ctx.fill();
|
|
193
190
|
|
|
194
|
-
|
|
191
|
+
// Draw value
|
|
195
192
|
|
|
196
193
|
const min = position.x;
|
|
197
|
-
const max = position.x +
|
|
194
|
+
const max = position.x + fullSize.x;
|
|
198
195
|
|
|
199
196
|
if(active)
|
|
200
197
|
{
|
|
201
|
-
value = LX.UTILS.clamp((this.mousePosition.x - min
|
|
198
|
+
value = LX.UTILS.clamp((this.mousePosition.x - min) / (max - min), 0.0, 1.0);
|
|
202
199
|
this.widgets[ text ].value = value;
|
|
203
200
|
}
|
|
204
201
|
|
|
205
|
-
let
|
|
202
|
+
let valueSize = new LX.vec2( fullSize.x * value, size.y );
|
|
206
203
|
|
|
207
|
-
ctx.
|
|
208
|
-
ctx.
|
|
204
|
+
ctx.beginPath();
|
|
205
|
+
ctx.fillStyle = hovered ? "#6074e7" : "#3e57e4";
|
|
206
|
+
if( valueSize.x > ( fullSize.x - 8 ) ) // 8: radius
|
|
207
|
+
{
|
|
208
|
+
ctx.roundRect( position.x, position.y, valueSize.x, valueSize.y + padding.y * 2.0, [8, 8, 8, 8] );
|
|
209
|
+
ctx.fill();
|
|
210
|
+
}
|
|
211
|
+
else
|
|
212
|
+
{
|
|
213
|
+
ctx.fillRect( position.x, position.y, valueSize.x, valueSize.y + padding.y * 2.0 );
|
|
214
|
+
}
|
|
209
215
|
|
|
210
216
|
// Draw text
|
|
211
217
|
|
|
212
218
|
ctx.fillStyle = hovered ? "#fff" : "#ddd";
|
|
213
219
|
ctx.fillText( text, position.x + padding.x, position.y + metrics.actualBoundingBoxAscent + padding.y );
|
|
214
220
|
|
|
215
|
-
|
|
216
|
-
{
|
|
217
|
-
document.body.style.cursor = "default";
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Pointer cursor on hover
|
|
222
|
-
document.body.style.cursor = "pointer";
|
|
221
|
+
this.setPointerCursor |= hovered;
|
|
223
222
|
|
|
224
223
|
if( active )
|
|
225
224
|
{
|
|
@@ -259,7 +258,7 @@ class ImUI {
|
|
|
259
258
|
|
|
260
259
|
let boxMargin = 12;
|
|
261
260
|
let fullSize = new LX.vec2(boxMargin * 2.0, 0);
|
|
262
|
-
fullSize.add( size );
|
|
261
|
+
fullSize.add( size, fullSize );
|
|
263
262
|
|
|
264
263
|
// Get mouse state
|
|
265
264
|
|
|
@@ -294,8 +293,7 @@ class ImUI {
|
|
|
294
293
|
ctx.fillStyle = hovered ? "#fff" : "#ddd";
|
|
295
294
|
ctx.fillText( text, position.x + padding.x, position.y + metrics.actualBoundingBoxAscent + padding.y );
|
|
296
295
|
|
|
297
|
-
|
|
298
|
-
document.body.style.cursor = hovered ? "pointer" : "default";
|
|
296
|
+
this.setPointerCursor |= hovered;
|
|
299
297
|
}
|
|
300
298
|
|
|
301
299
|
/**
|
|
@@ -307,6 +305,11 @@ class ImUI {
|
|
|
307
305
|
|
|
308
306
|
this.eventClick = null;
|
|
309
307
|
|
|
308
|
+
// Pointer cursor on hover
|
|
309
|
+
document.body.style.cursor = this.setPointerCursor ? "pointer" : "default";
|
|
310
|
+
|
|
311
|
+
// Clear info
|
|
312
|
+
this.setPointerCursor = false;
|
|
310
313
|
}
|
|
311
314
|
}
|
|
312
315
|
|
package/build/lexgui.js
CHANGED
|
@@ -12,7 +12,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
var LX = global.LX = {
|
|
15
|
-
version: "0.1.
|
|
15
|
+
version: "0.1.4",
|
|
16
16
|
ready: false,
|
|
17
17
|
components: [], // specific pre-build components
|
|
18
18
|
signals: {} // events and triggers
|
|
@@ -126,17 +126,17 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
|
|
|
126
126
|
|
|
127
127
|
constructor(x, y) {
|
|
128
128
|
this.x = x ?? 0;
|
|
129
|
-
this.y = y ?? 0;
|
|
129
|
+
this.y = y ?? (x ?? 0);
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
get xy() { return [ this.x, this.y]; }
|
|
133
133
|
get yx() { return [ this.y, this.x]; }
|
|
134
|
-
|
|
135
|
-
set( x, y ) { this.x = x; this.y = y; }
|
|
136
|
-
add( v ) {
|
|
137
|
-
sub( v ) {
|
|
138
|
-
mul( v ) {
|
|
139
|
-
div( v ) {
|
|
134
|
+
|
|
135
|
+
set ( x, y ) { this.x = x; this.y = y; }
|
|
136
|
+
add ( v, v0 = new vec2() ) { v0.set( this.x + v.x, this.y + v.y ); return v0; }
|
|
137
|
+
sub ( v, v0 = new vec2() ) { v0.set( this.x - v.x, this.y - v.y ); return v0; }
|
|
138
|
+
mul ( v, v0 = new vec2() ) { if( v.constructor == Number ) { v = new vec2(v) } v = v0.set( this.x * v.x, this.y * v.y ); return v0; }
|
|
139
|
+
div ( v, v0 = new vec2() ) { v0.set( this.x / v.x, this.y / v.y ); return v0; }
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
LX.vec2 = vec2;
|
package/build/lexgui.module.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
var LX = {
|
|
11
|
-
version: "0.1.
|
|
11
|
+
version: "0.1.4",
|
|
12
12
|
ready: false,
|
|
13
13
|
components: [], // specific pre-build components
|
|
14
14
|
signals: {} // events and triggers
|
|
@@ -122,17 +122,17 @@ class vec2 {
|
|
|
122
122
|
|
|
123
123
|
constructor(x, y) {
|
|
124
124
|
this.x = x ?? 0;
|
|
125
|
-
this.y = y ?? 0;
|
|
125
|
+
this.y = y ?? (x ?? 0);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
get xy() { return [ this.x, this.y]; }
|
|
129
129
|
get yx() { return [ this.y, this.x]; }
|
|
130
130
|
|
|
131
|
-
set( x, y ) { this.x = x; this.y = y; }
|
|
132
|
-
add( v ) {
|
|
133
|
-
sub( v ) {
|
|
134
|
-
mul( v ) {
|
|
135
|
-
div( v ) {
|
|
131
|
+
set ( x, y ) { this.x = x; this.y = y; }
|
|
132
|
+
add ( v, v0 = new vec2() ) { v0.set( this.x + v.x, this.y + v.y ); return v0; }
|
|
133
|
+
sub ( v, v0 = new vec2() ) { v0.set( this.x - v.x, this.y - v.y ); return v0; }
|
|
134
|
+
mul ( v, v0 = new vec2() ) { if( v.constructor == Number ) { v = new vec2(v) } v = v0.set( this.x * v.x, this.y * v.y ); return v0; }
|
|
135
|
+
div ( v, v0 = new vec2() ) { v0.set( this.x / v.x, this.y / v.y ); return v0; }
|
|
136
136
|
};
|
|
137
137
|
|
|
138
138
|
LX.vec2 = vec2;
|