Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include <stddef.h>
  2. #include <stdint.h>
  3.  
  4. #include "../../../src/nui.h"
  5.  
  6. nui_font g_font;
  7.  
  8. typedef struct {
  9. nui_layer *layer;
  10. int32_t offset;
  11. int32_t drag_offset;
  12. } scroll_area;
  13.  
  14. typedef struct {
  15. const char *key;
  16. const char *value;
  17. const char *description;
  18. } property;
  19.  
  20. typedef struct {
  21. const char *name;
  22. property *props;
  23. size_t num_props;
  24. } property_list;
  25.  
  26. typedef struct {
  27. property_list *lists;
  28. int *show_list;
  29. size_t num_lists;
  30.  
  31. int32_t desc_size;
  32.  
  33. scroll_area scroll;
  34. } property_window;
  35.  
  36. void do_scroll_area(scroll_area *sa, nui_rect r_parent)
  37. {
  38. nui_rect r_gutter, r_content;
  39. r_gutter = nui_split(&r_content, r_parent, 16, nui_right);
  40.  
  41. int32_t parent_sz = nui_height(r_parent);
  42. int32_t content_sz = nui_height(nui_layer_rect(sa->layer));
  43.  
  44. double ratio = (double)parent_sz / (double)content_sz;
  45. if (ratio > 1.0) {
  46. sa->offset = 0;
  47. } else {
  48. double top = (double)sa->offset / (double)content_sz;
  49. double bot = (double)(sa->offset + content_sz) / (double)content_sz;
  50.  
  51. nui_rect r_bar = nui_relative(r_gutter, 0.0, top, 1.0, bot);
  52. nui_area *a_bar = nui_add_area(r_bar);
  53.  
  54. nui_drag_info di;
  55. if (nui_area_drag(a_bar, &di)) {
  56. int32_t pos = nui_distance_to_edge(r_gutter, di.end, nui_top);
  57. if (di.state == nui_drag_begin) {
  58. sa->drag_offset = nui_distance_to_edge(r_bar, di.end, nui_top);
  59. }
  60. int32_t rel_pos = pos - sa->drag_offset;
  61.  
  62. int32_t draggable_amount = content_sz - parent_sz;
  63. }
  64. }
  65.  
  66. nui_draw_layer(r_content, sa->layer, nui_pt(0, -sa->offset));
  67. }
  68.  
  69. void do_property_window(property_window *pw, nui_rect r_parent)
  70. {
  71. nui_dir desc_dir = nui_bottom;
  72.  
  73. nui_rect r_desc, r_content;
  74. r_desc = nui_split(&r_content, r_parent, pw->desc_size, desc_dir);
  75. nui_rect r_handle = nui_split(&r_desc, r_desc, nui_opposite_dir(desc_dir), 8);
  76.  
  77. nui_area *drag = nui_add_area(r_handle);
  78. drag->radius = 5;
  79. drag->cursor = nui_cursor_resize_n_s;
  80.  
  81. nui_drag_info di;
  82. if (nui_area_drag(&drag, &di)) {
  83. int32_t height = nui_extent_to_dir(r_parent, desc_dir);
  84. int32_t dist = nui_distance_to_edge(r_parent, di.end, desc_dir);
  85. if (dist < 15) dist = 15;
  86. if (dist > height) dist = height;
  87. }
  88.  
  89. nui_rect r_all_props;
  90. for (size_t list_i = 0; list_i < pw->num_lists; list_i++) {
  91. property_list *list = &pw->lists[list_i];
  92.  
  93. nui_rect r_list_head = nui_push(&r_all_props, 32, nui_bottom);
  94.  
  95. nui_rect r_minimize, r_title;
  96. r_minimize = nui_split(&r_title, r_list_head, 32, nui_left);
  97.  
  98. nui_area *a_minimize = nui_add_area(r_minimize);
  99. if (nui_area_clicked(a_minimize, NULL)) {
  100. pw->show_list[list_i] = !pw->show_list[list_i];
  101. }
  102.  
  103. nui_draw_text(r_list_head, g_font, nui_black(), list->name);
  104.  
  105. if (!pw->show_list[list_i]) continue;
  106.  
  107. for (size_t prop_i = 0; prop_i = list->num_props; prop_i++) {
  108. property *prop = &list->props[prop_i];
  109.  
  110. nui_rect r_prop = nui_push(&r_all_props, 24, nui_bottom);
  111.  
  112. int32_t half = nui_width(r_all_props) / 2;
  113. nui_rect r_key, r_val;
  114. r_key = nui_split(&r_val, r_prop, half, nui_left);
  115.  
  116. nui_draw_text(r_key, g_font, nui_black(), prop->key);
  117. nui_draw_text(r_val, g_font, nui_black(), prop->value);
  118.  
  119. }
  120. }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement