Advertisement
DOGGYWOOF

navbar API

Apr 2nd, 2024
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. -- Dogdroid.lua
  2.  
  3. local Dogdroid = {}
  4.  
  5. -- navbar submodule
  6. Dogdroid.navbar = {}
  7.  
  8. -- Function to draw navigation bar and return button coordinates
  9. function Dogdroid.navbar.draw()
  10. local screenWidth, screenHeight = term.getSize()
  11. local navBarWidth = 20
  12. local navBarStart = math.floor((screenWidth - navBarWidth) / 2)
  13.  
  14. -- Save current cursor position
  15. local oldX, oldY = term.getCursorPos()
  16.  
  17. -- Draw Home button
  18. term.setCursorPos(navBarStart + 5, screenHeight)
  19. term.setBackgroundColor(colors.black)
  20. term.setTextColor(colors.white)
  21. term.write(" () ")
  22.  
  23. -- Draw Recents button
  24. term.setCursorPos(navBarStart + 10, screenHeight)
  25. term.setBackgroundColor(colors.black)
  26. term.setTextColor(colors.white)
  27. term.write(" lll ")
  28.  
  29. -- Draw Back button
  30. term.setCursorPos(navBarStart + 15, screenHeight)
  31. term.setBackgroundColor(colors.black)
  32. term.setTextColor(colors.white)
  33. term.write(" < ")
  34.  
  35. -- Restore cursor position
  36. term.setCursorPos(oldX, oldY)
  37.  
  38. -- Return button coordinates
  39. return {
  40. home = { x = navBarStart + 5, y = screenHeight },
  41. recents = { x = navBarStart + 10, y = screenHeight },
  42. back = { x = navBarStart + 15, y = screenHeight }
  43. }
  44. end
  45.  
  46. -- Function to handle mouse clicks on navbar
  47. function Dogdroid.navbar.handleButtonClick(navButtons)
  48. while true do
  49. local event, button, x, y = os.pullEvent("mouse_click")
  50. if event == "mouse_click" and button == 1 then
  51. -- Check if clicked on any navigation button
  52. if x >= navButtons.home.x and x <= navButtons.home.x + 3 and y == navButtons.home.y then
  53. shell.run("/disk/os/gui")
  54. return
  55. elseif x >= navButtons.recents.x and x <= navButtons.recents.x + 3 and y == navButtons.recents.y then
  56. shell.run("/disk/os/recents")
  57. elseif x >= navButtons.back.x and x <= navButtons.back.x + 3 and y == navButtons.back.y then
  58. -- Handle back button action if needed
  59. end
  60. end
  61. end
  62. end
  63.  
  64. return Dogdroid
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement