From 9ed7d82d09d171a375cfb1a7dab9b5a2e37b7f58 Mon Sep 17 00:00:00 2001 From: Patrick Jakobsen Date: Mon, 25 Sep 2023 18:30:25 +0200 Subject: [PATCH] WIP subtree offsetting The current wip code is problematic because it relies on the computed_size of the nodes, which conflicts with dirty-redrawing because it is always be a frame behind. --- gui/gui.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gui/gui.c b/gui/gui.c index d117c1a..eba6461 100644 --- a/gui/gui.c +++ b/gui/gui.c @@ -170,6 +170,9 @@ struct GUI_Subtree { GUI_Subtree *structural_parent; RDIC_Node_Reference relative_to; + int flat_offset_x; + int flat_offset_y; + GUI_Draw_Command *first_draw_command; int num_draw_commands; Pixel_Buffer *pixel_buffer; @@ -639,6 +642,8 @@ void gui_generate_draw_commands( y_offset = relative_rectangle->y0; //printf("%.*s: %d, %d\n", relative_node->debug_string.length, relative_node->debug_string.cstring, x_offset, y_offset); } + x_offset += subtree->flat_offset_x; + y_offset += subtree->flat_offset_y; GUI_Node *root = (GUI_Node*)subtree->rdic.root; assert(root != NULL); @@ -1386,6 +1391,7 @@ void test_gui__subtree( static RDIC_Node_Reference middle = {0}; static RDIC_Node_Reference bottom = {0}; + static RDIC_Node_Reference slider = {0}; static float slider_value = 0.25f; top = gui_layout( context, top, GUI_LAYOUT_HORIZONTAL, &outer_style, top_bottom_size); @@ -1396,7 +1402,7 @@ void test_gui__subtree( static GUI_Size slider_size[2] = { {GUI_SIZERULE_PIXELS, 200, 100}, {GUI_SIZERULE_PIXELS, 40, 100}}; - static RDIC_Node_Reference slider = {0}; + //static RDIC_Node_Reference slider = {0}; static RDIC_Node_Reference slider_inner = {0}; // NOTE(Zelaven): This line is not good because it causes jankyness when // using the slider, and the slider behaves properly without it. @@ -1436,6 +1442,23 @@ void test_gui__subtree( inner_top = gui_dumb_block(context, inner_top, &outer_style, element_size); ((GUI_Node*)inner_top.node)->image = &test_image; } gui_pop_subtree(context); + int middle_height = + ((GUI_Node*)middle.node)->computed_size[GUI_AXIS2_Y]; + int subtree_height = + ((GUI_Node*)middle_subtree_root.node)->computed_size[GUI_AXIS2_Y]; + int overfill = subtree_height - middle_height; + printf("\n%d = %d - %d\n", overfill, subtree_height, middle_height); + if(overfill >= 0) + { + printf("?\n"); + middle_subtree.flat_offset_y = -(slider_value * overfill); + printf("%d\n", middle_subtree.flat_offset_x); + } + else + { + middle_subtree.flat_offset_y = 0; + } + ((GUI_Node*)middle_subtree_root.node)->dirty = ((GUI_Node*)slider.node)->dirty; bottom = gui_dumb_block(context, bottom, &outer_style, top_bottom_size);