pepejik

Untitled

Jan 2nd, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.16 KB | None | 0 0
  1. ------------------------------------------------------------
  2. -- GUI.lua (Собранная библиотека)
  3. -- Содержит: table.reduce, объекты GUI, GUI.Scene,
  4. -- все components (Button, Switch, Label и т.д.),
  5. -- утилиты (gpuMethods, StyleValidator, Symbols),
  6. -- базовую тему (default).
  7. ------------------------------------------------------------
  8. local component = require("component")
  9. local computer = require("computer")
  10. local unicode = require("unicode")
  11. local gpu = component.gpu -- При необходимости можете перенести в другое место
  12. local os = require("os")
  13.  
  14. ------------------------------------------------------------
  15. -- table.reduce (из GUI_01.lua)
  16. ------------------------------------------------------------
  17. table.reduce = function(tbl, init, func)
  18. local accumulator = init
  19. for _, value in ipairs(tbl) do
  20. accumulator = func(accumulator, value)
  21. end
  22. return accumulator
  23. end
  24.  
  25. ------------------------------------------------------------
  26. -- Объявляем GUI как глобальную таблицу
  27. ------------------------------------------------------------
  28. GUI = {}
  29. GUI.__index = GUI
  30. GUI.last_event = nil
  31. GUI.themes = {} -- Список всех тем
  32. GUI.components = {} -- Список всех компонентов
  33.  
  34. ------------------------------------------------------------
  35. -- Обёртка для задержки (для sleep(0)) и т.д.
  36. -- Если нужно, чтобы код "отпускал" CPU при долгих циклах
  37. ------------------------------------------------------------
  38. local function safeSleep(t)
  39. os.sleep(t or 0)
  40. end
  41.  
  42. ------------------------------------------------------------
  43. -- Определим Scene (основной класс сцены)
  44. ------------------------------------------------------------
  45. GUI.Scene = {}
  46. GUI.Scene.__index = GUI.Scene
  47.  
  48. function GUI.Scene:newScene(themeName)
  49. local scene = {
  50. themeName = themeName or "default",
  51. isActive = false,
  52. last_event = {},
  53. windows = {},
  54. theme = {},
  55. signalHandlerSleepTLWD = 0
  56. }
  57. setmetatable(scene, GUI.Scene)
  58. scene:setTheme(themeName or "default")
  59. return scene
  60. end
  61.  
  62. --- Обрабатывает сигналы (pullSignal(0)).
  63. function GUI.Scene:signalHandler(callback)
  64. self.signalHandlerSleepTLWD = self.signalHandlerSleepTLWD + 1
  65. if self.signalHandlerSleepTLWD == 2048 then
  66. safeSleep(0)
  67. self.signalHandlerSleepTLWD = 0
  68. end
  69. local signal = { computer.pullSignal(0) }
  70. if signal then return signal end
  71. return { [1]="none",[2]="",[3]=0,[4]=0,[5]=0,[6]=0 }
  72. end
  73.  
  74. function GUI.Scene:run(callback)
  75. self.isActive = true
  76. while self.isActive do
  77. self.last_event = self:signalHandler(callback)
  78. for _, window in ipairs(self.windows) do
  79. window:handleEvent(self.last_event)
  80. end
  81. end
  82. end
  83.  
  84. function GUI.Scene:stop()
  85. self.isActive = false
  86. end
  87.  
  88. function GUI.Scene:setTheme(themeName)
  89. assert(GUI.themes[themeName],("Theme (%s) not found in GUI.themes"):format(themeName))
  90. -- Рекурсивная таблица
  91. local function createSearchableTable(data)
  92. local mt = {
  93. __index = function(tbl, key)
  94. if rawget(tbl,key) then return rawget(tbl,key) end
  95. for k,v in pairs(tbl) do
  96. if type(v)=="table" then
  97. local result = v[key]
  98. if result then return result end
  99. error(("Ключ (%s) не найден в подтаблице: %s"):format(key,tostring(k)))
  100. end
  101. end
  102. error(("Ключ (%s) не найден в таблице."):format(key))
  103. end
  104. }
  105. return setmetatable(data,mt)
  106. end
  107. self.theme = createSearchableTable(GUI.themes[themeName])
  108. end
  109.  
  110. function GUI.Scene:validateColorTheme(objType, objName, colorName)
  111. assert(self.theme[objType],("objType: %s not found in theme"):format(objType))
  112. assert(self.theme[objType][objName],
  113. ("objName: %s not found in %s"):format(objName,objType))
  114. assert(self.theme[objType][objName][colorName],
  115. ("colorName: %s not found in %s"):format(colorName,objName))
  116. return self.theme[objType][objName][colorName]
  117. end
  118.  
  119. function GUI.Scene:addWindow(x,y,width,height,colorName)
  120. self:validateColorTheme("components","Window",colorName)
  121. local window = self.Window:new(x,y,width,height,colorName)
  122. window.Scene = self
  123. table.insert(self.windows, window)
  124. return self.windows[#self.windows]
  125. end
  126.  
  127. function GUI.Scene:destroyWindow(window_name)
  128. if not self.windows[window_name] then
  129. error("Can\'t find a window in the scene")
  130. end
  131. self.windows[window_name] = nil
  132. end
  133.  
  134. ------------------------------------------------------------
  135. -- Класс окна (Window)
  136. ------------------------------------------------------------
  137. GUI.Scene.Window = {}
  138. GUI.Scene.Window.__index = GUI.Scene.Window
  139.  
  140. function GUI.Scene.Window:new(x,y,width,height,colorName)
  141. local window = {
  142. type = "Window",
  143. x=x,y=y,width=width,height=height,
  144. colorName=colorName, background=0,
  145. elements={}
  146. }
  147. setmetatable(window, GUI.Scene.Window)
  148. return window
  149. end
  150.  
  151. function GUI.Scene.Window:draw()
  152. gpu.setForeground(self.Scene.theme.Scene.Window[self.colorName])
  153. gpu.setBackground(self.Scene.theme.Scene.Window[self.colorName])
  154. self.background = self.Scene.theme.Scene.Window[self.colorName]
  155. gpu.fill(self.x,self.y,self.width,self.height," ")
  156. end
  157.  
  158. function GUI.Scene.Window:handleEvent(event)
  159. for _,el in ipairs(self.elements) do
  160. if el.handleEvent then el:handleEvent(event) end
  161. end
  162. end
  163.  
  164. function GUI.Scene.Window:addElement(elementType,elementName,...)
  165. assert(GUI[elementType],("elementType (%s) not found"):format(elementType))
  166. assert(GUI[elementType][elementName],
  167. ("elementName (%s) not found in GUI[%s]"):format(elementName,elementType))
  168. local element = GUI[elementType][elementName]:new(...)
  169. element.ParentOBJ = self
  170. table.insert(self.elements, element)
  171. return self.elements[#self.elements]
  172. end
  173.  
  174. ------------------------------------------------------------
  175. -- Некоторые вспомогательные методы GUI
  176. ------------------------------------------------------------
  177. function GUI:new() return self end
  178. function GUI:getThemesName()
  179. local t={}
  180. for k,_ in pairs(self.themes) do table.insert(t,k) end
  181. return t
  182. end
  183. function GUI:getCurrentThemeName()
  184. return self.themeName
  185. end
  186.  
  187. ------------------------------------------------------------
  188. -- gpuMethods (.\src\Depency\gpuMethods.lua)
  189. ------------------------------------------------------------
  190. GUI.gpuMethods = {}
  191. GUI.gpuMethods.__index = GUI.gpuMethods
  192.  
  193. function GUI.gpuMethods:set(text,x,y,foreground,background)
  194. if foreground then gpu.setForeground(foreground) end
  195. if background then gpu.setBackground(background) end
  196. gpu.set(x,y,text)
  197. end
  198.  
  199. function GUI.gpuMethods:fill(symbol,x,y,width,height,foreground,background)
  200. if foreground then gpu.setForeground(foreground) end
  201. if background then gpu.setBackground(background) end
  202. gpu.fill(x,y,width,height,symbol)
  203. end
  204.  
  205. ------------------------------------------------------------
  206. -- StyleValidator (.\src\Utils\StyleValidator.lua)
  207. ------------------------------------------------------------
  208. GUI.StyleValidator = {}
  209. GUI.StyleValidator.__index = GUI.StyleValidator
  210.  
  211. function GUI.StyleValidator:_checkForDuplicateStyles(stylesString)
  212. local seen={}
  213. for style in stylesString:gmatch("%S+") do
  214. if seen[style] then
  215. error(("Дублирующийся стиль: \'%s\'"):format(style))
  216. end
  217. seen[style]=true
  218. end
  219. end
  220.  
  221. function GUI.StyleValidator:isStyleCompatible(compatibilityTable,style1,style2)
  222. if compatibilityTable[style1] then
  223. for _,compatible in ipairs(compatibilityTable[style1]) do
  224. if compatible==style2 then return true end
  225. end
  226. end
  227. return false
  228. end
  229.  
  230. function GUI.StyleValidator:validateStyles(stylesString,compatibilityTable,validatedStyles)
  231. local valid_styles={}
  232. self:_checkForDuplicateStyles(stylesString)
  233. for style in stylesString:gmatch("%S+") do
  234. local isValid=false
  235. for _,v in ipairs(validatedStyles) do
  236. if style==v then isValid=true;break end
  237. end
  238. assert(isValid,
  239. ("Стиль \'%s\' недопустим. Допустимые стили: %s"):format(
  240. style,table.concat(validatedStyles,"; ")))
  241. if compatibilityTable[style] then
  242. for otherStyle in stylesString:gmatch("%S+") do
  243. if style~=otherStyle and not self:isStyleCompatible(compatibilityTable,style,otherStyle) then
  244. error(("Стили \'%s\' и \'%s\' несовместимы."):format(style,otherStyle))
  245. end
  246. end
  247. end
  248. valid_styles[style]=true
  249. end
  250. return valid_styles
  251. end
  252.  
  253. ------------------------------------------------------------
  254. -- Components
  255. ------------------------------------------------------------
  256.  
  257. -- Button (.\src\Components\Button.lua)
  258. GUI.components.Button={}
  259. GUI.components.Button.__index=GUI.components.Button
  260.  
  261. function GUI.components.Button:new(x,y,styles,callback)
  262. local button={
  263. type="Button", styles=styles,
  264. x=x,y=y, width=0, height=0,
  265. callback=callback,
  266. background=0, foreground=0xFFFFFF, disabled=false,
  267. button_colors_names={
  268. "btn-primary","btn-secondary","btn-success","btn-danger","btn-warning",
  269. "btn-info","btn-light","btn-dark","btn-link"
  270. },
  271. styles_validated={
  272. "btn-primary","btn-secondary","btn-success","btn-danger","btn-warning",
  273. "btn-info","btn-light","btn-dark","btn-link",
  274. "sm","rounded","brackets","strokes","doted","disabled"
  275. },
  276. compatibility_styles={
  277. ["btn-primary"]={"sm","rounded","brackets","strokes","doted","disabled"},
  278. ["btn-secondary"]={"sm","rounded","brackets","strokes","doted","disabled"},
  279. ["btn-success"]={"sm","rounded","brackets","strokes","doted","disabled"},
  280. ["btn-danger"]={"sm","rounded","brackets","strokes","doted","disabled"},
  281. ["btn-warning"]={"sm","rounded","brackets","strokes","doted","disabled"},
  282. ["btn-info"]={"sm","rounded","brackets","strokes","doted","disabled"},
  283. ["btn-light"]={"sm","rounded","brackets","strokes","doted","disabled"},
  284. ["btn-dark"]={"sm","rounded","brackets","strokes","doted","disabled"},
  285. ["btn-link"]={"sm","rounded","brackets","strokes","doted","disabled"},
  286. ["sm"]={"rounded","brackets","disabled"}
  287. },
  288. inserted_obj={},
  289. valid_styles={},
  290. button_colors={}
  291. }
  292.  
  293. button.button_colors = table.reduce(
  294. button.button_colors_names,{},function(acc,colorClassName)
  295. local themeColor = GUI.Scene.theme.components.Button[colorClassName]
  296. acc[colorClassName] = themeColor or 0xFFFFFF
  297. return acc
  298. end
  299. )
  300.  
  301. button.valid_styles = GUI.StyleValidator:validateStyles(
  302. styles, button.compatibility_styles, button.styles_validated
  303. )
  304. button.height = (button.valid_styles["sm"] and 1) or 3
  305. assert(type(x)=="number","x must be number")
  306. assert(type(y)=="number","y must be number")
  307. setmetatable(button,GUI.components.Button)
  308. return button
  309. end
  310.  
  311. function GUI.components.Button:addElement(elementName,...)
  312. local supportElements={Label=true,Checked=true,Badge=true,Switch=true}
  313. assert(supportElements[elementName],("ElementName (%s) not supported in Button"):format(elementName))
  314. assert(GUI.components[elementName],("No GUI.components.%s"):format(elementName))
  315. local element=GUI.components[elementName]:new(...)
  316. element.ParentOBJ=self
  317. table.insert(self.inserted_obj,element)
  318. return element
  319. end
  320.  
  321. function GUI.components.Button:draw()
  322. local fg=self.foreground or 0xFFFFFF
  323. local bg=self.background or 0x000000
  324. GUI.gpuMethods:fill(" ",self.x,self.y,self.width,self.height,fg,bg)
  325. for _,obj in ipairs(self.inserted_obj) do
  326. if obj.draw then obj:draw() end
  327. end
  328. end
  329.  
  330. function GUI.components.Button:erase()
  331. local bg=(self.ParentOBJ and self.ParentOBJ.background) or 0x000000
  332. GUI.gpuMethods:fill(" ",self.x,self.y,self.width,self.height,bg,bg)
  333. end
  334.  
  335. function GUI.components.Button:disable(state)
  336. self.disabled=(state==true)
  337. self:draw()
  338. end
  339.  
  340. function GUI.components.Button:handleEvent(event)
  341. if not self.disabled and event[1]=="touch" then
  342. local _,_,tx,ty=table.unpack(event)
  343. if tx>=self.x and tx<=(self.x+self.width-1)
  344. and ty>=self.y and ty<=(self.y+self.height-1)
  345. then
  346. if type(self.callback)=="function" then self.callback(self) end
  347. end
  348. end
  349. end
  350.  
  351. -- Switch (.\src\Components\Switch.lua)
  352. GUI.components.Switch={}
  353. GUI.components.Switch.__index=GUI.components.Switch
  354.  
  355. function GUI.components.Switch:new(x,y,isOn,callback)
  356. local sw={
  357. type="Switch", x=x,y=y,
  358. isOn=(isOn==true),
  359. width=5,height=1,
  360. backgroundOn=0x00FF00, backgroundOff=0xFF0000,
  361. foreground=0x000000,
  362. callback=callback
  363. }
  364. setmetatable(sw,GUI.components.Switch)
  365. return sw
  366. end
  367.  
  368. function GUI.components.Switch:draw()
  369. local bg=self.isOn and self.backgroundOn or self.backgroundOff
  370. local text=self.isOn and "[On] " or "[Off]"
  371. GUI.gpuMethods:fill(" ",self.x,self.y,self.width,self.height,self.foreground,bg)
  372. gpu.setForeground(self.foreground)
  373. gpu.setBackground(bg)
  374. gpu.set(self.x,self.y,text)
  375. end
  376.  
  377. function GUI.components.Switch:handleEvent(event)
  378. if event[1]=="touch" then
  379. local _,_,tx,ty=table.unpack(event)
  380. if tx>=self.x and tx<(self.x+self.width) and ty==self.y then
  381. self.isOn=not self.isOn
  382. if type(self.callback)=="function" then
  383. self.callback(self,self.isOn)
  384. end
  385. self:draw()
  386. end
  387. end
  388. end
  389.  
  390. -- Checked (.\src\Components\Checked.lua) (Чекбокс/флажок)
  391. GUI.Checked={}
  392. GUI.Checked.__index=GUI.Checked
  393.  
  394. function GUI.Checked:new(x,y,checked)
  395. local c={x=x,y=y,checked=checked or false}
  396. setmetatable(c,GUI.Checked)
  397. return c
  398. end
  399.  
  400. function GUI.Checked:handleEvent(event)
  401. if event[1]=="touch" then
  402. local _,_,tx,ty=table.unpack(event)
  403. if tx==self.x and ty==self.y then
  404. self.checked=not self.checked
  405. end
  406. end
  407. end
  408.  
  409. -- Label (.\src\Components\Label.lua)
  410. GUI.components.Label={}
  411. GUI.components.Label.__index=GUI.Label
  412.  
  413. function GUI.components.Label:new(text_table,x,y,align,callback)
  414. self:validateTextTable(text_table)
  415. local label={
  416. type="Label",
  417. x=0,y=y, full_len_text=0,
  418. text_table=self:prepareTextTable(text_table),
  419. background=0,
  420. callback=callback
  421. }
  422. label.x, label.full_len_text = self:calculatePositionAndLength(text_table,x,align)
  423. setmetatable(label,GUI.components.Label)
  424. return label
  425. end
  426.  
  427. function GUI.components.Label:validateTextTable(tt)
  428. assert(type(tt)=="table" and next(tt),("Label text_table is empty or not table"))
  429. for _,v in ipairs(tt) do
  430. assert(type(v.colorName)=="string","Label colorName must be string")
  431. -- Здесь проверка GUI:validateColorTheme("components","Label",v.colorName)
  432. -- но такой функции нет напрямую в GUI, поэтому опустим или реализуем при желании.
  433. end
  434. end
  435.  
  436. function GUI.components.Label:prepareTextTable(tt)
  437. local t={}
  438. for _,v in ipairs(tt) do
  439. table.insert(t,{str=v.str,colorName=v.colorName,str_len=unicode.len(v.str)})
  440. end
  441. return t
  442. end
  443.  
  444. function GUI.components.Label:calculatePositionAndLength(tt,x,align)
  445. local s=""
  446. for _,v in ipairs(tt) do
  447. s=s..v.str
  448. end
  449. local length=unicode.len(s)
  450. if align then return x,length end
  451. return math.abs(math.floor(x-(length/2))),length
  452. end
  453.  
  454. function GUI.components.Label:draw()
  455. local x=self.x
  456. for _,v in ipairs(self.text_table) do
  457. gpu.setBackground(self.ParentOBJ.background)
  458. -- Если хотите цвета из темы, надо делать что-то вроде:
  459. -- local fgColor = self.ParentOBJ.Scene.theme.components.Label[v.colorName]
  460. -- но здесь используем "gpu.setForeground(...)"
  461. gpu.setForeground(0xFFFFFF)
  462. gpu.set(x,self.y,v.str)
  463. x=x+v.str_len
  464. end
  465. end
  466.  
  467. function GUI.components.Label:handleEvent(event)
  468. if event[1]=="touch" then
  469. local _,_,tx,ty=table.unpack(event)
  470. if tx>=self.x and tx<=(self.x+self.full_len_text) and ty==self.y then
  471. return self.callback and self.callback(self) or false
  472. end
  473. end
  474. end
  475.  
  476. ------------------------------------------------------------
  477. -- AllColors (.\src\Depency\AllColors.lua) -- не обязательно используется
  478. ------------------------------------------------------------
  479. GUI.AllColors={
  480. [1] = {
  481. [1] = 0x000000, [11] = 0x660000, [21] = 0xcc0000,
  482. [2] = 0x000040, [12] = 0x660040, [22] = 0xcc0040,
  483. [3] = 0x000080, [13] = 0x660080, [23] = 0xcc0080,
  484. [4] = 0x0000c0, [14] = 0x6600c0, [24] = 0xcc00c0,
  485. [5] = 0x0000ff, [15] = 0x6600ff, [25] = 0xcc00ff,
  486. [6] = 0x330000, [16] = 0x990000, [26] = 0xff0000,
  487. [7] = 0x330040, [17] = 0x990040, [27] = 0xff0040,
  488. [8] = 0x330080, [18] = 0x990080, [28] = 0xff0080,
  489. [9] = 0x3300c0, [19] = 0x9900c0, [29] = 0xff00c0,
  490. [10]= 0x3300ff, [20] = 0x9900ff, [30] = 0xff00ff
  491. },
  492. [2] = {
  493. [1] = 0x002400, [11] = 0x662400, [21] = 0xcc2400,
  494. [2] = 0x002440, [12] = 0x662440, [22] = 0xcc2440,
  495. [3] = 0x002480, [13] = 0x662480, [23] = 0xcc2480,
  496. [4] = 0x0024c0, [14] = 0x6624c0, [24] = 0xcc24c0,
  497. [5] = 0x0024ff, [15] = 0x6624ff, [25] = 0xcc24ff,
  498. [6] = 0x332400, [16] = 0x992400, [26] = 0xff2400,
  499. [7] = 0x332440, [17] = 0x992440, [27] = 0xff2440,
  500. [8] = 0x332480, [18] = 0x992480, [28] = 0xff2480,
  501. [9] = 0x3324c0, [19] = 0x9924c0, [29] = 0xff24c0,
  502. [10]= 0x3324ff, [20] = 0x9924ff, [30] = 0xff24ff
  503. },
  504. [3] = {
  505. [1] = 0x004900, [11] = 0x664900, [21] = 0xcc4900,
  506. [2] = 0x004940, [12] = 0x664940, [22] = 0xcc4940,
  507. [3] = 0x004980, [13] = 0x664980, [23] = 0xcc4980,
  508. [4] = 0x0049c0, [14] = 0x6649c0, [24] = 0xcc49c0,
  509. [5] = 0x0049ff, [15] = 0x6649ff, [25] = 0xcc49ff,
  510. [6] = 0x334900, [16] = 0x994900, [26] = 0xff4900,
  511. [7] = 0x334940, [17] = 0x994940, [27] = 0xff4940,
  512. [8] = 0x334980, [18] = 0x994980, [28] = 0xff4980,
  513. [9] = 0x3349c0, [19] = 0x9949c0, [29] = 0xff49c0,
  514. [10]= 0x3349ff, [20] = 0x9949ff, [30] = 0xff49ff
  515. },
  516. [4] = {
  517. [1] = 0x006d00, [11] = 0x666d00, [21] = 0xcc6d00,
  518. [2] = 0x006d40, [12] = 0x666d40, [22] = 0xcc6d40,
  519. [3] = 0x006d80, [13] = 0x666d80, [23] = 0xcc6d80,
  520. [4] = 0x006dc0, [14] = 0x666dc0, [24] = 0xcc6dc0,
  521. [5] = 0x006dff, [15] = 0x666dff, [25] = 0xcc6dff,
  522. [6] = 0x336d00, [16] = 0x996d00, [26] = 0xff6d00,
  523. [7] = 0x336d40, [17] = 0x996d40, [27] = 0xff6d40,
  524. [8] = 0x336d80, [18] = 0x996d80, [28] = 0xff6d80,
  525. [9] = 0x336dc0, [19] = 0x996dc0, [29] = 0xff6dc0,
  526. [10]= 0x336dff, [20] = 0x996dff, [30] = 0xff6dff
  527. },
  528. [5] = {
  529. [1] = 0x009200, [11] = 0x669200, [21] = 0xcc9200,
  530. [2] = 0x009240, [12] = 0x669240, [22] = 0xcc9240,
  531. [3] = 0x009280, [13] = 0x669280, [23] = 0xcc9280,
  532. [4] = 0x0092c0, [14] = 0x6692c0, [24] = 0xcc92c0,
  533. [5] = 0x0092ff, [15] = 0x6692ff, [25] = 0xcc92ff,
  534. [6] = 0x339200, [16] = 0x999200, [26] = 0xff9200,
  535. [7] = 0x339240, [17] = 0x999240, [27] = 0xff9240,
  536. [8] = 0x339280, [18] = 0x999280, [28] = 0xff9280,
  537. [9] = 0x3392c0, [19] = 0x9992c0, [29] = 0xff92c0,
  538. [10]= 0x3392ff, [20] = 0x9992ff, [30] = 0xff92ff
  539. },
  540. [6] = {
  541. [1] = 0x00b600, [11] = 0x66b600, [21] = 0xccb600,
  542. [2] = 0x00b640, [12] = 0x66b640, [22] = 0xccb640,
  543. [3] = 0x00b680, [13] = 0x66b680, [23] = 0xccb680,
  544. [4] = 0x00b6c0, [14] = 0x66b6c0, [24] = 0xccb6c0,
  545. [5] = 0x00b6ff, [15] = 0x66b6ff, [25] = 0xccb6ff,
  546. [6] = 0x33b600, [16] = 0x99b600, [26] = 0xffb600,
  547. [7] = 0x33b640, [17] = 0x99b640, [27] = 0xffb640,
  548. [8] = 0x33b680, [18] = 0x99b680, [28] = 0xffb680,
  549. [9] = 0x33b6c0, [19] = 0x99b6c0, [29] = 0xffb6c0,
  550. [10]= 0x33b6ff, [20] = 0x99b6ff, [30] = 0xffb6ff
  551. },
  552. [7] = {
  553. [1] = 0x00db00, [11] = 0x66db00, [21] = 0xccdb00,
  554. [2] = 0x00db40, [12] = 0x66db40, [22] = 0xccdb40,
  555. [3] = 0x00db80, [13] = 0x66db80, [23] = 0xccdb80,
  556. [4] = 0x00dbc0, [14] = 0x66dbc0, [24] = 0xccdbc0,
  557. [5] = 0x00dbff, [15] = 0x66dbff, [25] = 0xccdbff,
  558. [6] = 0x33db00, [16] = 0x99db00, [26] = 0xffdb00,
  559. [7] = 0x33db40, [17] = 0x99db40, [27] = 0xffdb40,
  560. [8] = 0x33db80, [18] = 0x99db80, [28] = 0xffdb80,
  561. [9] = 0x33dbc0, [19] = 0x99dbc0, [29] = 0xffdbc0,
  562. [10]= 0x33dbff, [20] = 0x99dbff, [30] = 0xffdbff
  563. },
  564. [8] = {
  565. [1] = 0x00ff00, [11] = 0x66ff00, [21] = 0xccff00,
  566. [2] = 0x00ff40, [12] = 0x66ff40, [22] = 0xccff40,
  567. [3] = 0x00ff80, [13] = 0x66ff80, [23] = 0xccff80,
  568. [4] = 0x00ffc0, [14] = 0x66ffc0, [24] = 0xccffc0,
  569. [5] = 0x00ffff, [15] = 0x66ffff, [25] = 0xccffff,
  570. [6] = 0x33ff00, [16] = 0x99ff00, [26] = 0xffff00,
  571. [7] = 0x33ff40, [17] = 0x99ff40, [27] = 0xffff40,
  572. [8] = 0x33ff80, [18] = 0x99ff80, [28] = 0xffff80,
  573. [9] = 0x33ffc0, [19] = 0x99ffc0, [29] = 0xffffc0,
  574. [10]= 0x33ffff, [20] = 0x99ffff, [30] = 0xffffff
  575. },
  576. [0] = { -- grey colors
  577. [1] = 0x0f0f0f, [9] = 0x878787,
  578. [2] = 0x1e1e1e, [10] = 0x969696,
  579. [3] = 0x2d2d2d, [11] = 0xa5a5a5,
  580. [4] = 0x3c3c3c, [12] = 0xb4b4b4,
  581. [5] = 0x4b4b4b, [13] = 0xc3c3c3,
  582. [6] = 0x5a5a5a, [14] = 0xd2d2d2,
  583. [7] = 0x696969, [15] = 0xe1e1e1,
  584. [8] = 0x787878, [16] = 0xf0f0f0,
  585. }
  586. }
  587. -- (Укорочено)
  588.  
  589. ------------------------------------------------------------
  590. -- Symbols (.\src\Utils\Symbols.lua)
  591. ------------------------------------------------------------
  592. GUI.Symbols={}
  593. GUI.Symbols.__index=GUI.Symbols
  594. GUI.Symbols.fullwidth_symbols={
  595. -- Полношрифтные латинские буквы
  596. ["A"] = "A", -- U+FF21
  597. ["B"] = "B", -- U+FF22
  598. ["C"] = "C", -- U+FF23
  599. ["D"] = "D", -- U+FF24
  600. ["E"] = "E", -- U+FF25
  601. ["F"] = "F", -- U+FF26
  602. ["G"] = "G", -- U+FF27
  603. ["H"] = "H", -- U+FF28
  604. ["I"] = "I", -- U+FF29
  605. ["J"] = "J", -- U+FF2A
  606. ["K"] = "K", -- U+FF2B
  607. ["L"] = "L", -- U+FF2C
  608. ["M"] = "M", -- U+FF2D
  609. ["N"] = "N", -- U+FF2E
  610. ["O"] = "O", -- U+FF2F
  611. ["P"] = "P", -- U+FF30
  612. ["Q"] = "Q", -- U+FF31
  613. ["R"] = "R", -- U+FF32
  614. ["S"] = "S", -- U+FF33
  615. ["T"] = "T", -- U+FF34
  616. ["U"] = "U", -- U+FF35
  617. ["V"] = "V", -- U+FF36
  618. ["W"] = "W", -- U+FF37
  619. ["X"] = "X", -- U+FF38
  620. ["Y"] = "Y", -- U+FF39
  621. ["Z"] = "Z", -- U+FF3A
  622.  
  623. -- Полношрифтные цифры
  624. ["0"] = "0", -- U+FF10
  625. ["1"] = "1", -- U+FF11
  626. ["2"] = "2", -- U+FF12
  627. ["3"] = "3", -- U+FF13
  628. ["4"] = "4", -- U+FF14
  629. ["5"] = "5", -- U+FF15
  630. ["6"] = "6", -- U+FF16
  631. ["7"] = "7", -- U+FF17
  632. ["8"] = "8", -- U+FF18
  633. ["9"] = "9", -- U+FF19
  634.  
  635. -- Полношрифтные русские буквы
  636. ["А"] = "A", -- U+FF21 (А)
  637. ["Б"] = "Б", -- U+FF22 (Б)
  638. ["В"] = "В", -- U+FF23 (В)
  639. ["Г"] = "Г", -- U+FF24 (Г)
  640. ["Д"] = "Д", -- U+FF25 (Д)
  641. ["Е"] = "Е", -- U+FF26 (Е)
  642. ["Ё"] = "Ё", -- U+FF27 (Ё)
  643. ["Ж"] = "Ж", -- U+FF28 (Ж)
  644. ["З"] = "З", -- U+FF29 (З)
  645. ["И"] = "И", -- U+FF2A (И)
  646. ["Й"] = "Й", -- U+FF2B (Й)
  647. ["К"] = "К", -- U+FF2C (К)
  648. ["Л"] = "Л", -- U+FF2D (Л)
  649. ["М"] = "М", -- U+FF2E (М)
  650. ["Н"] = "Н", -- U+FF2F (Н)
  651. ["О"] = "О", -- U+FF30 (О)
  652. ["П"] = "П", -- U+FF31 (П)
  653. ["Р"] = "Р", -- U+FF32 (Р)
  654. ["С"] = "С", -- U+FF33 (С)
  655. ["Т"] = "Т", -- U+FF34 (Т)
  656. ["У"] = "У", -- U+FF35 (У)
  657. ["Ф"] = "Ф", -- U+FF36 (Ф)
  658. ["Х"] = "Х", -- U+FF37 (Х)
  659. ["Ц"] = "Ц", -- U+FF38 (Ц)
  660. ["Ч"] = "Ч", -- U+FF39 (Ч)
  661. ["Ш"] = "Ш", -- U+FF3A (Ш)
  662. ["Щ"] = "Щ", -- U+FF3B (Щ)
  663. ["Ъ"] = "Ъ", -- U+FF3C (Ъ)
  664. ["Ы"] = "Ы", -- U+FF3D (Ы)
  665. ["Ь"] = "Ь", -- U+FF3E (Ь)
  666. ["Э"] = "Э", -- U+FF3F (Э)
  667. ["Ю"] = "Ю", -- U+FF40 (Ю)
  668. ["Я"] = "Я", -- U+FF41 (Я)
  669.  
  670.  
  671. -- Полношрифтные специальные символы
  672. ["!"] = "!", -- U+FF01
  673. ["\""] = """, -- U+FF02
  674. ["#"] = "#", -- U+FF03
  675. ["$"] = "$", -- U+FF04
  676. ["%"] = "%", -- U+FF05
  677. ["&"] = "&", -- U+FF06
  678. ["'"] = "'", -- U+FF07
  679. ["("] = "(", -- U+FF08
  680. [")"] = ")", -- U+FF09
  681. ["*"] = "*", -- U+FF0A
  682. ["+"] = "+", -- U+FF0B
  683. [","] = ",", -- U+FF0C
  684. ["-"] = "-", -- U+FF0D
  685. ["."] = ".", -- U+FF0E
  686. ["/"] = "/", -- U+FF0F
  687. [":"] = ":", -- U+FF1A
  688. [";"] = ";", -- U+FF1B
  689. ["<"] = "<", -- U+FF1C
  690. ["="] = "=", -- U+FF1D
  691. [">"] = ">", -- U+FF1E
  692. ["?"] = "?", -- U+FF1F
  693. ["@"] = "@", -- U+FF20
  694. ["["] = "[", -- U+FF3B
  695. ["\\"] = "\", -- U+FF3C
  696. ["]"] = "]", -- U+FF3D
  697. ["^"] = "^", -- U+FF3E
  698. ["_"] = "_", -- U+FF3F
  699. ["`"] = "`", -- U+FF40
  700. ["{"] = "{", -- U+FF5B
  701. ["|"] = "|", -- U+FF5C
  702. ["}"] = "}", -- U+FF5D
  703. ["~"] = "~", -- U+FF5E
  704.  
  705. -- Математические символы
  706. ["±"] = "±", -- U+00B1
  707. ["×"] = "×", -- U+00D7
  708. ["÷"] = "÷", -- U+00F7
  709. ["≠"] = "≠", -- U+2260
  710. ["≤"] = "≤", -- U+2264
  711. ["≥"] = "≥", -- U+2265
  712. ["∞"] = "∞", -- U+221E
  713. ["∑"] = "∑", -- U+2211
  714. ["√"] = "√", -- U+221A
  715. ["∏"] = "∏", -- U+220F
  716.  
  717. -- Другие специальные символы
  718. ["§"] = "§", -- U+00A7
  719. ["©"] = "©", -- U+00A9
  720. ["®"] = "®", -- U+00AE
  721. ["™"] = "™", -- U+2122
  722. }
  723. GUI.Symbols.additionalSymbols={
  724. cross="❌"
  725. }
  726. function GUI.Symbols:replaceSpecialSymbols(input)
  727. local value=unicode.upper(input)
  728. local res=""
  729. local length=unicode.len(value)
  730. for i=1,length do
  731. local ch=unicode.sub(value,i,i)
  732. if self.fullwidth_symbols[ch] then
  733. res=res..self.fullwidth_symbols[ch]
  734. else
  735. res=res..ch
  736. end
  737. end
  738. return res
  739. end
  740. function GUI.Symbols:getSymbol(key)
  741. if self.fullwidth_symbols[key] then return self.fullwidth_symbols[key] end
  742. if self.additionalSymbols[key] then return self.additionalSymbols[key] end
  743. return false
  744. end
  745.  
  746. ------------------------------------------------------------
  747. -- Подключаем (или просто объявляем) тему (.\src\Themes\default_02.lua)
  748. ------------------------------------------------------------
  749. GUI.themes.default={
  750. components={
  751. Label={white=0xFFFFFF,background=0},
  752. Button={foreground=0xFFFFFF,background=0,["btn-primary"]=0x00AAFF,["btn-success"]=0x00FF00,["btn-danger"]=0xFF0000},
  753. Badge={foreground=0xFFFFFF,background=0},
  754. Input={foreground=0,background=0},
  755. Window={grey=0xCFCFCF,background=0,foreground=0}
  756. },
  757. Scene={
  758. Window={
  759. grey=0xCFCFCF
  760. }
  761. }
  762. }
  763.  
  764. ------------------------------------------------------------
  765. -- Возвращаем GUI (на случай require(...) )
  766. ------------------------------------------------------------
  767. return GUI
  768.  
Advertisement
Add Comment
Please, Sign In to add comment