Advertisement
DOGGYWOOF

tabs manager with ONE UI navbar

May 19th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. local buttons = {
  2. { name = "Command", x = 2, y = 3, width = 15, height = 1, color = colors.gray, command = "/disk/os/home.lua" },
  3. { name = "Programs", x = 2, y = 5, width = 15, height = 1, color = colors.gray, command = "/disk/os/programs" },
  4. { name = "Power Menu", x = 2, y = 7, width = 15, height = 1, color = colors.gray, command = "showPowerMenu" }
  5. }
  6.  
  7. local function drawButton(button)
  8. term.setBackgroundColor(button.color)
  9. term.setTextColor(colors.white)
  10. term.setCursorPos(button.x, button.y)
  11. term.clearLine()
  12. term.write(" " .. button.name .. " ")
  13. end
  14.  
  15. local function drawPowerMenu()
  16. term.setBackgroundColor(colors.gray)
  17. term.setTextColor(colors.white)
  18. term.setCursorPos(2, 8)
  19. term.clearLine()
  20. term.write(" Shut Down ")
  21.  
  22. term.setCursorPos(2, 9)
  23. term.clearLine()
  24. term.write(" Reboot ")
  25.  
  26. term.setCursorPos(2, 10)
  27. term.clearLine()
  28. term.write(" Lock ")
  29. end
  30.  
  31. local function drawHomescreen()
  32. term.setBackgroundColor(colors.black)
  33. term.clear()
  34.  
  35. term.setCursorPos(1, 1)
  36. term.setBackgroundColor(colors.blue)
  37. term.setTextColor(colors.white)
  38. term.write(" Doggy OS 12.0 ")
  39. term.setBackgroundColor(colors.black)
  40.  
  41. for _, button in ipairs(buttons) do
  42. drawButton(button)
  43. end
  44. end
  45.  
  46. local function drawNavBar()
  47. local screenWidth, screenHeight = term.getSize()
  48. local navBarWidth = 20
  49. local navBarStart = math.floor((screenWidth - navBarWidth) / 2)
  50.  
  51. term.setCursorPos(navBarStart + 4, screenHeight)
  52. term.setBackgroundColor(colors.black)
  53. term.setTextColor(colors.white)
  54. term.write(" lll ")
  55.  
  56. term.setCursorPos(navBarStart + 9, screenHeight)
  57. term.setBackgroundColor(colors.black)
  58. term.setTextColor(colors.white)
  59. term.write(" () ")
  60.  
  61. term.setCursorPos(navBarStart + 14, screenHeight)
  62. term.setBackgroundColor(colors.black)
  63. term.setTextColor(colors.white)
  64. term.write(" < ")
  65.  
  66. return {
  67. lll = { x = navBarStart + 4, y = screenHeight, width = 4 },
  68. -- Add coordinates for other nav buttons if needed
  69. }
  70. }
  71.  
  72. local function handleAppClick(x, y)
  73. for _, button in ipairs(buttons) do
  74. if x >= button.x and x <= (button.x + button.width - 1) and y == button.y then
  75. term.setBackgroundColor(colors.black) -- Reset background color
  76. return button.command
  77. end
  78. end
  79. return nil
  80. end
  81.  
  82. local function handlePowerMenuClick(x, y)
  83. if x >= 2 and x <= 16 then
  84. if (y >= 8 and y <= 10) then
  85. term.setBackgroundColor(colors.black) -- Reset background color
  86. if y == 8 then return "shutdown"
  87. elseif y == 9 then return "reboot"
  88. elseif y == 10 then return "lock"
  89. end
  90. end
  91. end
  92. term.setBackgroundColor(colors.black) -- Reset background color
  93. return nil
  94. end
  95.  
  96. local function launchApp(command)
  97. term.clear()
  98. term.setCursorPos(1, 1)
  99.  
  100. -- Terminate the program
  101. os.pullEvent = os.pullEventRaw
  102.  
  103. -- Launch the command or show power menu
  104. if command == "/disk/os/home.lua" or command == "/disk/os/programs" then
  105. shell.run(command)
  106. elseif command == "showPowerMenu" then
  107. drawPowerMenu()
  108. local event, _, x, y = os.pullEvent("mouse_click")
  109.  
  110. local powerMenuCommand = handlePowerMenuClick(x, y)
  111. if powerMenuCommand then
  112. if powerMenuCommand == "shutdown" then
  113. os.shutdown()
  114. elseif powerMenuCommand == "reboot" then
  115. os.reboot()
  116. elseif powerMenuCommand == "lock" then
  117. shell.run("/disk/os/lock")
  118. end
  119. end
  120. elseif command == "/disk/os/recents" then
  121. shell.run(command)
  122. else
  123. shell.run("start " .. command)
  124. end
  125.  
  126. -- Re-enable the event handling
  127. os.pullEvent = os.pullEventRaw
  128. end
  129.  
  130. local function homescreen()
  131. while true do
  132. drawHomescreen()
  133. local navBarButtons = drawNavBar() -- Draw the navigation bar and get the button coordinates
  134. local event, _, x, y = os.pullEvent("mouse_click")
  135.  
  136. if event == "mouse_click" then
  137. local appCommand = handleAppClick(x, y)
  138. if appCommand then
  139. launchApp(appCommand)
  140. return -- Terminate the program after launching the app or showing the power menu
  141. end
  142.  
  143. -- Check for nav bar button clicks
  144. if x >= navBarButtons.lll.x and x <= (navBarButtons.lll.x + navBarButtons.lll.width - 1) and y == navBarButtons.lll.y then
  145. launchApp("/disk/os/recents")
  146. return -- Terminate the program after launching the app
  147. end
  148. end
  149. end
  150. end
  151.  
  152. homescreen()
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement