node_renderer.vala 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /********************************************************************
  2. # Copyright 2014-2019 Daniel 'grindhold' Brendle
  3. #
  4. # This file is part of libgtkflow.
  5. #
  6. # libgtkflow is free software: you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public License
  8. # as published by the Free Software Foundation, either
  9. # version 3 of the License, or (at your option) any later
  10. # version.
  11. #
  12. # libgtkflow is distributed in the hope that it will be
  13. # useful, but WITHOUT ANY WARRANTY; without even the implied
  14. # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. # PURPOSE. See the GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with libgtkflow.
  19. # If not, see http://www.gnu.org/licenses/.
  20. *********************************************************************/
  21. namespace GtkFlow {
  22. /**
  23. * Representations of libgtkflows internal NodeRenderer-Types
  24. */
  25. public enum NodeRendererType {
  26. DOCKLINE,
  27. DEFAULT,
  28. CUSTOM
  29. }
  30. /**
  31. * Errors concerning NodeRenderer
  32. */
  33. public errordomain NodeRendererError {
  34. /**
  35. * If you pass a invalid value to {@link GtkFlow.NodeView.set_node_renderer}
  36. * Thats not within {@link GtkFlow.NodeRendererType}
  37. */
  38. NOT_A_NODE_RENDERER,
  39. /**
  40. * You passed a null value to a function that needs to be passed a
  41. * {@link GtkFlow.NodeRenderer}-implementation instance
  42. */
  43. NO_CUSTOM_NODE_RENDERER,
  44. }
  45. /**
  46. * Implementing this class in your application enables you to represent
  47. * your {@link GFlow.Nodes} in a completely customized manner by entirely
  48. * drawing them yourself.
  49. */
  50. public abstract class NodeRenderer : GLib.Object {
  51. /**
  52. * Default value for the spacing between the title and the first dock
  53. */
  54. public int title_spacing {get; set; default=15;}
  55. /**
  56. * Default value for the spacing between the delete button
  57. * and the title
  58. */
  59. public int delete_btn_size {get; set; default=16;}
  60. /**
  61. * Default value for the sizeof the Node's resize handle
  62. */
  63. public int resize_handle_size {get; set; default=10;}
  64. /**
  65. * This signal is triggered whenever the size of the node changes
  66. */
  67. public signal void size_changed();
  68. /**
  69. * Trigger this signal in implementations to tell the Node
  70. * to render the given childwidget
  71. */
  72. public signal void child_redraw(Gtk.Widget child);
  73. protected NodeRenderer () {}
  74. /**
  75. * Implementations should draw the graphical representation of
  76. * the node on the given {@link Cairo.Context}
  77. */
  78. public abstract void draw_node(Gtk.Widget w,
  79. Cairo.Context cr,
  80. Gtk.Allocation alloc,
  81. List<DockRenderer> dock_renderers,
  82. List<Gtk.Widget> children,
  83. int border_width,
  84. NodeProperties node_properties);
  85. /**
  86. * Implementations should calculate whether there is a dock
  87. * on this node specified by the {@link Gdk.Point} p . If so,
  88. * return the dock, otherwise return null
  89. */
  90. public abstract GFlow.Dock? get_dock_on_position(Gdk.Point p,
  91. List<DockRenderer> dock_renderers,
  92. uint border_width,
  93. Gtk.Allocation alloc );
  94. /**
  95. * Implementations should calculate the position of the given
  96. * dock on the canvas and write it into the parameters x and y.
  97. * If everything went well, return true. If there is no such dock,
  98. * return false.
  99. */
  100. public abstract bool get_dock_position(GFlow.Dock d,
  101. List<DockRenderer> dock_renderers,
  102. int border_width,
  103. Gtk.Allocation alloc,
  104. out int x,
  105. out int y);
  106. /**
  107. * Implementations should return true if the given position is
  108. * on the node's closebutton.
  109. */
  110. public abstract bool is_on_closebutton(Gdk.Point p,
  111. Gtk.Allocation alloc,
  112. uint border_width);
  113. /**
  114. * Implementations should return true if the given position is
  115. * on the node's resize handle.
  116. */
  117. public abstract bool is_on_resize_handle(Gdk.Point p,
  118. Gtk.Allocation alloc,
  119. uint border_width);
  120. /**
  121. * Implementations should return the minimum width that this
  122. * node needs in order to be correctly rendered.
  123. */
  124. public abstract uint get_min_width(List<DockRenderer> dock_renderers,
  125. List<Gtk.Widget> children,
  126. int border_width);
  127. /**
  128. * Implementations should return the minimum height that this
  129. * node needs in order to be correctly rendered.
  130. */
  131. public abstract uint get_min_height(List<DockRenderer> dock_renderers,
  132. List<Gtk.Widget> children,
  133. int border_width);
  134. /**
  135. * If this NodeRenderer-implementation renderes text, like the
  136. * nodes name, this method is executed everytime the namestring of
  137. * the {@link GFlow.Node} changes.
  138. */
  139. public abstract void update_name_layout(string name);
  140. }
  141. }