Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stddef.h>
- #include <stdint.h>
- #include "../../../src/nui.h"
- nui_font g_font;
- typedef struct {
- nui_layer *layer;
- int32_t offset;
- int32_t drag_offset;
- } scroll_area;
- typedef struct {
- const char *key;
- const char *value;
- const char *description;
- } property;
- typedef struct {
- const char *name;
- property *props;
- size_t num_props;
- } property_list;
- typedef struct {
- property_list *lists;
- int *show_list;
- size_t num_lists;
- int32_t desc_size;
- scroll_area scroll;
- } property_window;
- void do_scroll_area(scroll_area *sa, nui_rect r_parent)
- {
- nui_rect r_gutter, r_content;
- r_gutter = nui_split(&r_content, r_parent, 16, nui_right);
- int32_t parent_sz = nui_height(r_parent);
- int32_t content_sz = nui_height(nui_layer_rect(sa->layer));
- double ratio = (double)parent_sz / (double)content_sz;
- if (ratio > 1.0) {
- sa->offset = 0;
- } else {
- double top = (double)sa->offset / (double)content_sz;
- double bot = (double)(sa->offset + content_sz) / (double)content_sz;
- nui_rect r_bar = nui_relative(r_gutter, 0.0, top, 1.0, bot);
- nui_area *a_bar = nui_add_area(r_bar);
- nui_drag_info di;
- if (nui_area_drag(a_bar, &di)) {
- int32_t pos = nui_distance_to_edge(r_gutter, di.end, nui_top);
- if (di.state == nui_drag_begin) {
- sa->drag_offset = nui_distance_to_edge(r_bar, di.end, nui_top);
- }
- int32_t rel_pos = pos - sa->drag_offset;
- int32_t draggable_amount = content_sz - parent_sz;
- }
- }
- nui_draw_layer(r_content, sa->layer, nui_pt(0, -sa->offset));
- }
- void do_property_window(property_window *pw, nui_rect r_parent)
- {
- nui_dir desc_dir = nui_bottom;
- nui_rect r_desc, r_content;
- r_desc = nui_split(&r_content, r_parent, pw->desc_size, desc_dir);
- nui_rect r_handle = nui_split(&r_desc, r_desc, nui_opposite_dir(desc_dir), 8);
- nui_area *drag = nui_add_area(r_handle);
- drag->radius = 5;
- drag->cursor = nui_cursor_resize_n_s;
- nui_drag_info di;
- if (nui_area_drag(&drag, &di)) {
- int32_t height = nui_extent_to_dir(r_parent, desc_dir);
- int32_t dist = nui_distance_to_edge(r_parent, di.end, desc_dir);
- if (dist < 15) dist = 15;
- if (dist > height) dist = height;
- }
- nui_rect r_all_props;
- for (size_t list_i = 0; list_i < pw->num_lists; list_i++) {
- property_list *list = &pw->lists[list_i];
- nui_rect r_list_head = nui_push(&r_all_props, 32, nui_bottom);
- nui_rect r_minimize, r_title;
- r_minimize = nui_split(&r_title, r_list_head, 32, nui_left);
- nui_area *a_minimize = nui_add_area(r_minimize);
- if (nui_area_clicked(a_minimize, NULL)) {
- pw->show_list[list_i] = !pw->show_list[list_i];
- }
- nui_draw_text(r_list_head, g_font, nui_black(), list->name);
- if (!pw->show_list[list_i]) continue;
- for (size_t prop_i = 0; prop_i = list->num_props; prop_i++) {
- property *prop = &list->props[prop_i];
- nui_rect r_prop = nui_push(&r_all_props, 24, nui_bottom);
- int32_t half = nui_width(r_all_props) / 2;
- nui_rect r_key, r_val;
- r_key = nui_split(&r_val, r_prop, half, nui_left);
- nui_draw_text(r_key, g_font, nui_black(), prop->key);
- nui_draw_text(r_val, g_font, nui_black(), prop->value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement