node_renderer.vala 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /********************************************************************
  2. # Copyright 2014-2022 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.Node}s 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. Gtk.Widget? title=null);
  86. /**
  87. * Implementations should calculate whether there is a dock
  88. * on this node specified by the {@link Gdk.Point} p . If so,
  89. * return the dock, otherwise return null
  90. */
  91. public abstract GFlow.Dock? get_dock_on_position(Gdk.Point p,
  92. List<DockRenderer> dock_renderers,
  93. uint border_width,
  94. Gtk.Allocation alloc,
  95. Gtk.Widget? title=null);
  96. /**
  97. * Implementations should calculate the position of the given
  98. * dock on the canvas and write it into the parameters x and y.
  99. * If everything went well, return true. If there is no such dock,
  100. * return false.
  101. */
  102. public abstract bool get_dock_position(GFlow.Dock d,
  103. List<DockRenderer> dock_renderers,
  104. int border_width,
  105. Gtk.Allocation alloc,
  106. out int x,
  107. out int y,
  108. Gtk.Widget? title=null);
  109. /**
  110. * Implementations should return true if the given position is
  111. * on the node's closebutton.
  112. */
  113. public abstract bool is_on_closebutton(Gdk.Point p,
  114. Gtk.Allocation alloc,
  115. uint border_width);
  116. /**
  117. * Implementations should return true if the given position is
  118. * on the node's resize handle.
  119. */
  120. public abstract bool is_on_resize_handle(Gdk.Point p,
  121. Gtk.Allocation alloc,
  122. uint border_width);
  123. /**
  124. * Implementations should return the minimum width that this
  125. * node needs in order to be correctly rendered.
  126. */
  127. public abstract uint get_min_width(List<DockRenderer> dock_renderers,
  128. List<Gtk.Widget> children,
  129. int border_width,
  130. Gtk.Widget? title=null);
  131. /**
  132. * Implementations should return the minimum height that this
  133. * node needs in order to be correctly rendered.
  134. */
  135. public abstract uint get_min_height(List<DockRenderer> dock_renderers,
  136. List<Gtk.Widget> children,
  137. int border_width,
  138. Gtk.Widget? title=null);
  139. /**
  140. * If this NodeRenderer-implementation renderes text, like the
  141. * nodes name, this method is executed everytime the namestring of
  142. * the {@link GFlow.Node} changes.
  143. */
  144. public abstract void update_name_layout(string name);
  145. }
  146. }