@@ -49,6 +49,8 @@ return function(name, parent, pTerm, basalt)
49
49
50
50
local activeEvents = {}
51
51
52
+ local colorTheme = {}
53
+
52
54
base :setZIndex (10 )
53
55
54
56
local basaltDraw = BasaltDraw (termObject )
@@ -81,6 +83,7 @@ return function(name, parent, pTerm, basalt)
81
83
end
82
84
83
85
local function getObject (name )
86
+ if (type (name )~= " string" )then name = name .name end
84
87
for _ , value in pairs (objects ) do
85
88
for _ , b in pairs (value ) do
86
89
if (b :getName () == name ) then
@@ -240,11 +243,11 @@ return function(name, parent, pTerm, basalt)
240
243
end
241
244
return false
242
245
end
243
-
246
+ local math = math
244
247
local function stringToNumber (str )
245
- local ok , err = pcall (load (" return " .. str ))
248
+ local ok , result = pcall (load (" return " .. str , " " , nil , { math = math } ))
246
249
if not (ok )then error (str .. " is not a valid dynamic code" ) end
247
- return load ( " return " .. str )()
250
+ return result
248
251
end
249
252
250
253
local function newDynamicValue (_ , obj , str )
@@ -327,8 +330,13 @@ return function(name, parent, pTerm, basalt)
327
330
for _ , index in pairs (objZIndex ) do
328
331
if (objects [index ] ~= nil ) then
329
332
for _ , value in pairs (objects [index ]) do
330
- if (value .eventHandler ~= nil ) then
331
- value :eventHandler (" dynamicValueEvent" , self )
333
+ if (basalt .getDynamicValueEventSetting ())then
334
+ if (value .eventHandler ~= nil ) then
335
+ value :eventHandler (" basalt_dynamicvalue" , self )
336
+ end
337
+ end
338
+ if (value .customEventHandler ~= nil ) then
339
+ value :customEventHandler (" basalt_resize" , self )
332
340
end
333
341
end
334
342
end
@@ -340,17 +348,49 @@ return function(name, parent, pTerm, basalt)
340
348
return dynamicValues [id ][1 ]
341
349
end
342
350
343
- local function calculateMaxScroll (self )
351
+ local function getVerticalScrollAmount (self )
352
+ local amount = 0
344
353
for _ , value in pairs (objects ) do
345
354
for _ , b in pairs (value ) do
346
355
if (b .getHeight ~= nil )and (b .getY ~= nil )then
347
- local h , y = b :getHeight (), b :getY ()
348
- if (h + y - self :getHeight () > scrollAmount ) then
349
- scrollAmount = max (h + y - self :getHeight (), 0 )
356
+ if (b :getType ()== " Dropdown" )then
357
+ local h , y = b :getHeight (), b :getY ()
358
+ local wD , hD = b :getDropdownSize ()
359
+ h = h + hD - 1
360
+ if (h + y - self :getHeight () >= amount ) then
361
+ amount = max (h + y - self :getHeight (), 0 )
362
+ end
363
+ else
364
+ local h , y = b :getHeight (), b :getY ()
365
+ if (h + y - self :getHeight () >= amount ) then
366
+ amount = max (h + y - self :getHeight (), 0 )
367
+ end
350
368
end
351
369
end
352
370
end
353
371
end
372
+ return amount
373
+ end
374
+
375
+ local function getHorizontalScrollAmount (self )
376
+ local amount = 0
377
+ for _ , value in pairs (objects ) do
378
+ for _ , b in pairs (value ) do
379
+ if (b .getWidth ~= nil )and (b .getX ~= nil )then
380
+ local h , y = b :getWidth (), b :getX ()
381
+ if (h + y - self :getWidth () >= amount ) then
382
+ amount = max (h + y - self :getWidth (), 0 )
383
+ end
384
+ end
385
+ end
386
+ end
387
+ return amount
388
+ end
389
+
390
+ local function calculateMaxScroll (self )
391
+ if (autoScroll )then
392
+ scrollAmount = getVerticalScrollAmount (self )
393
+ end
354
394
end
355
395
356
396
object = {
@@ -371,8 +411,8 @@ return function(name, parent, pTerm, basalt)
371
411
372
412
getType = function (self )
373
413
return objectType
374
- end ,
375
-
414
+ end ;
415
+
376
416
setZIndex = function (self , newIndex )
377
417
base .setZIndex (self , newIndex )
378
418
for k ,v in pairs (activeEvents )do
@@ -386,10 +426,14 @@ return function(name, parent, pTerm, basalt)
386
426
setFocusedObject = function (self , obj )
387
427
if (focusedObject ~= obj )then
388
428
if (focusedObject ~= nil )then
389
- focusedObject :loseFocusHandler ()
429
+ if (getObject (focusedObject )~= nil )then
430
+ focusedObject :loseFocusHandler ()
431
+ end
390
432
end
391
433
if (obj ~= nil )then
392
- obj :getFocusHandler ()
434
+ if (getObject (obj )~= nil )then
435
+ obj :getFocusHandler ()
436
+ end
393
437
end
394
438
focusedObject = obj
395
439
end
@@ -408,8 +452,8 @@ return function(name, parent, pTerm, basalt)
408
452
for _ , index in pairs (objZIndex ) do
409
453
if (objects [index ] ~= nil ) then
410
454
for _ , value in pairs (objects [index ]) do
411
- if (value .eventHandler ~= nil ) then
412
- value :eventHandler (" basalt_resize" , value , self )
455
+ if (value .customEventHandler ~= nil ) then
456
+ value :customEventHandler (" basalt_resize" , self )
413
457
end
414
458
end
415
459
end
@@ -433,17 +477,34 @@ return function(name, parent, pTerm, basalt)
433
477
return theme [name ] or (self .parent ~= nil and self .parent :getTheme (name ) or basalt .getTheme (name ))
434
478
end ,
435
479
436
- setPosition = function (self , x , y , rel )
437
- base .setPosition (self , x , y , rel )
438
- for _ , index in pairs (objZIndex ) do
439
- if (objects [index ] ~= nil ) then
440
- for _ , value in pairs (objects [index ]) do
441
- if (value .eventHandler ~= nil ) then
442
- value :eventHandler (" basalt_reposition" , value , self )
480
+ getThemeColor = function (self , col )
481
+ return col ~= nil and colorTheme [col ] or colorTheme
482
+ end ,
483
+
484
+ setThemeColor = function (self , col , ...)
485
+ if (self .parent == nil )then
486
+ if (self == basalt .getActiveFrame ())then
487
+ if (type (col )== " string" )then
488
+ colorTheme [col ] = ...
489
+ termObject .setPaletteColor (type (col )== " number" and col or colors [col ], ... )
490
+ elseif (type (col )== " table" )then
491
+ for k ,v in pairs (col )do
492
+ colorTheme [k ] = v
493
+ if (type (v )== " number" )then
494
+ termObject .setPaletteColor (type (k )== " number" and k or colors [k ], v )
495
+ else
496
+ local r ,g ,b = table.unpack (v )
497
+ termObject .setPaletteColor (type (k )== " number" and k or colors [k ], r ,g ,b )
498
+ end
443
499
end
444
500
end
445
501
end
446
502
end
503
+ return self
504
+ end ,
505
+
506
+ setPosition = function (self , x , y , rel )
507
+ base .setPosition (self , x , y , rel )
447
508
self :recalculateDynamicValues ()
448
509
return self
449
510
end ;
@@ -469,7 +530,9 @@ return function(name, parent, pTerm, basalt)
469
530
470
531
removeFocusedObject = function (self )
471
532
if (focusedObject ~= nil )then
472
- focusedObject :loseFocusHandler ()
533
+ if (getObject (focusedObject )~= nil )then
534
+ focusedObject :loseFocusHandler ()
535
+ end
473
536
end
474
537
focusedObject = nil
475
538
return self
@@ -537,10 +600,26 @@ return function(name, parent, pTerm, basalt)
537
600
return autoScroll and calculateMaxScroll (self ) or scrollAmount
538
601
end ,
539
602
603
+ getCalculatedVerticalScroll = getVerticalScrollAmount ,
604
+ getCalculatedHorizontalScroll = getHorizontalScrollAmount ,
605
+
540
606
show = function (self )
541
607
base .show (self )
542
608
if (self .parent == nil )then
543
609
basalt .setActiveFrame (self )
610
+ for k ,v in pairs (colors )do
611
+ if (type (v )== " number" )then
612
+ termObject .setPaletteColor (v , colors .packRGB (term .nativePaletteColor ((v ))))
613
+ end
614
+ end
615
+ for k ,v in pairs (colorTheme )do
616
+ if (type (v )== " number" )then
617
+ termObject .setPaletteColor (type (k )== " number" and k or colors [k ], v )
618
+ else
619
+ local r ,g ,b = table.unpack (v )
620
+ termObject .setPaletteColor (type (k )== " number" and k or colors [k ], r ,g ,b )
621
+ end
622
+ end
544
623
if (isMonitor )and not (isGroupedMonitor )then
545
624
basalt .setMonitorFrame (monSide , self )
546
625
elseif (isGroupedMonitor )then
@@ -555,7 +634,7 @@ return function(name, parent, pTerm, basalt)
555
634
hide = function (self )
556
635
base .hide (self )
557
636
if (self .parent == nil )then
558
- if (activeFrame == self )then activeFrame = nil end -- bug activeFrame always nil
637
+ if (activeFrame == self )then activeFrame = nil end
559
638
if (isMonitor )and not (isGroupedMonitor )then
560
639
if (basalt .getMonitorFrame (monSide ) == self )then
561
640
basalt .setActiveFrame (nil )
@@ -804,9 +883,6 @@ return function(name, parent, pTerm, basalt)
804
883
self :mouseHandler (1 , p2 , p3 , true )
805
884
end
806
885
end
807
- if (event == " terminate" )and (self .parent == nil )then
808
- basalt .stop ()
809
- end
810
886
end ,
811
887
812
888
mouseHandler = function (self , button , x , y , _ , side )
@@ -891,8 +967,8 @@ return function(name, parent, pTerm, basalt)
891
967
self :updateDraw ()
892
968
end
893
969
end
894
- self :removeFocusedObject ()
895
970
if (yOffset == cache )then return false end
971
+ self :removeFocusedObject ()
896
972
return true
897
973
end
898
974
return false
0 commit comments