demo-paned.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. return function(parent, dir)
  2. local lgi = require 'lgi'
  3. local Gtk = lgi.Gtk
  4. local window = Gtk.Window {
  5. title = "Panes",
  6. Gtk.Box {
  7. orientation = 'VERTICAL',
  8. Gtk.Paned {
  9. orientation = 'VERTICAL',
  10. Gtk.Paned {
  11. id = 'paned_top',
  12. orientation = 'HORIZONTAL',
  13. Gtk.Frame {
  14. id = 'paned_left',
  15. shadow_type = 'IN',
  16. height_request = 60,
  17. width_request = 60,
  18. Gtk.Button {
  19. label = "_Hi there",
  20. use_underline = true,
  21. },
  22. },
  23. Gtk.Frame {
  24. id = 'paned_right',
  25. shadow_type = 'IN',
  26. height_request = 80,
  27. width_request = 60,
  28. },
  29. },
  30. Gtk.Frame {
  31. id = 'paned_bottom',
  32. shadow_type = 'IN',
  33. height_request = 60,
  34. width_request = 80,
  35. },
  36. },
  37. Gtk.Frame {
  38. label = "Horizontal",
  39. border_width = 4,
  40. Gtk.Grid {
  41. {
  42. left_attach = 0, top_attach = 0,
  43. Gtk.Label { label = "Left" },
  44. },
  45. {
  46. left_attach = 0, top_attach = 1,
  47. Gtk.CheckButton {
  48. id = 'resize_left',
  49. label = "_Resize",
  50. use_underline = true,
  51. },
  52. },
  53. {
  54. left_attach = 0, top_attach = 2,
  55. Gtk.CheckButton {
  56. id = 'shrink_left',
  57. label = "_Shrink",
  58. use_underline = true,
  59. },
  60. },
  61. {
  62. left_attach = 1, top_attach = 0,
  63. Gtk.Label { label = "Right" },
  64. },
  65. {
  66. left_attach = 1, top_attach = 1,
  67. Gtk.CheckButton {
  68. id = 'resize_right',
  69. label = "_Resize",
  70. use_underline = true,
  71. },
  72. },
  73. {
  74. left_attach = 1, top_attach = 2,
  75. Gtk.CheckButton {
  76. id = 'shrink_right',
  77. label = "_Shrink",
  78. use_underline = true,
  79. },
  80. },
  81. },
  82. },
  83. Gtk.Frame {
  84. label = "Vertical",
  85. border_width = 4,
  86. Gtk.Grid {
  87. {
  88. left_attach = 0, top_attach = 0,
  89. Gtk.Label { label = "Top" },
  90. },
  91. {
  92. left_attach = 0, top_attach = 1,
  93. Gtk.CheckButton {
  94. id = 'resize_top',
  95. label = "_Resize",
  96. use_underline = true,
  97. },
  98. },
  99. {
  100. left_attach = 0, top_attach = 2,
  101. Gtk.CheckButton {
  102. id = 'shrink_top',
  103. label = "_Shrink",
  104. use_underline = true,
  105. },
  106. },
  107. {
  108. left_attach = 1, top_attach = 0,
  109. Gtk.Label { label = "Bottom" },
  110. },
  111. {
  112. left_attach = 1, top_attach = 1,
  113. Gtk.CheckButton {
  114. id = 'resize_bottom',
  115. label = "_Resize",
  116. use_underline = true,
  117. },
  118. },
  119. {
  120. left_attach = 1, top_attach = 2,
  121. Gtk.CheckButton {
  122. id = 'shrink_bottom',
  123. label = "_Shrink",
  124. use_underline = true,
  125. },
  126. },
  127. },
  128. },
  129. },
  130. }
  131. -- Connect servicing routines for all toggles.
  132. for _, pos in ipairs { 'left', 'right', 'top', 'bottom' } do
  133. local child = window.child['paned_' .. pos]
  134. local paned = child.parent
  135. local resize = window.child['resize_' .. pos]
  136. resize.active = paned.property[child].resize
  137. function resize:on_clicked()
  138. paned.property[child].resize = self.active
  139. end
  140. local shrink = window.child['shrink_' .. pos]
  141. shrink.active = paned.property[child].shrink
  142. function shrink:on_clicked()
  143. paned.property[child].shrink = self.active
  144. end
  145. end
  146. window:show_all()
  147. return window
  148. end,
  149. "Paned Widgets",
  150. table.concat {
  151. [[The Gtk.Paned widget divide its content area into two panes ]],
  152. [[with a divider in between that the user can adjust. A separate ]],
  153. [[child is placed into each pane.
  154. ]],
  155. [[There are a number of options that can be set for each pane. ]],
  156. [[This test contains both a horizontal and a vertical widget, ]],
  157. [[and allows you to adjust the options for each side of each widget.]],
  158. }