Advertisement
Guest User

FIXED layout patch

a guest
Dec 17th, 2014
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. function fixed:fit(ow,oh)
  2. local pos, c = 0, 0
  3. local w,h
  4. for k, v in pairs(self.widgets) do
  5. c = c + 1
  6. w, h = base.fit_widget(v, ow, oh)
  7. if math.fmod(k,2) == 0 then
  8. if self.dir == "y" then
  9. pos = pos + h
  10. else
  11. pos = pos + w
  12. end
  13. end
  14. end
  15. if self.dir == "y" then
  16. return ow, pos + math.fmod(c,2) * h
  17. else
  18. return pos + math.fmod(c,2) * w, oh
  19. end
  20. end
  21.  
  22. function fixed:draw(wibox, cr, width, height)
  23. local pos = 0
  24. local aw, ah = width/2, height/2
  25. for k, v in pairs(self.widgets) do
  26. local x, y, w, h, _
  27. local in_dir
  28. if self.dir == "y" then
  29. if math.fmod(k,2) == 0 then
  30. x = aw
  31. else
  32. x = 0
  33. end
  34. y = pos
  35. w, h = aw, height - pos
  36. if k ~= #self.widgets or not self._fill_space then
  37. _, h = base.fit_widget(v, w, h);
  38. end
  39. if math.fmod(k,2) == 0 then
  40. pos = pos + h
  41. end
  42. in_dir = h
  43. else
  44. if math.fmod(k,2) == 0 then
  45. y = ah
  46. else
  47. y = 0
  48. end
  49. x = pos
  50. w, h = width - pos, ah
  51. if k ~= #self.widgets or not self._fill_space then
  52. w, _ = base.fit_widget(v, w, height);
  53. end
  54. if math.fmod(k,2) == 0 then
  55. pos = pos + w
  56. end
  57. in_dir = w
  58. end
  59.  
  60. if (self.dir == "y" and pos > height) or
  61. (self.dir ~= "y" and pos > width) then
  62. break
  63. end
  64. base.draw_widget(wibox, cr, v, x, y, w, h)
  65. end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement