Skip to content

Commit ed8419b

Browse files
committed
layout: 5/N
1 parent ee750f8 commit ed8419b

2 files changed

Lines changed: 38 additions & 34 deletions

File tree

src/ndbl/gui/Graph_View.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void ndbl::_graphview_do_layout_element(Graph_View* graph_view, Node_View* nodev
505505

506506
if( nodeview->state.has_flags(View_Flag_PINNED) )
507507
{
508-
layout_pin_element_at_position(rect.top_left());
508+
layout_set_floating_at_position(rect.top_left());
509509
}
510510
}
511511

@@ -565,41 +565,45 @@ void ndbl::_graphview_do_layout_recursively(Graph_View* graph_view, Node_View* n
565565
{
566566
if( nodeview->node() == graph_root( graph_view->graph() ) )
567567
{
568-
layout_pin_element_at_position(nodeview->shape.position());
568+
layout_set_floating_at_position(nodeview->shape.position());
569569
}
570570

571571
_graphview_do_layout_recursively_on_expressions_only(graph_view, nodeview);
572572

573+
// propagate on switch branches
574+
// TODO: the container must be centered horizontally, we cannot do that currently with layout
575+
if( node_has_switch_behavior(node))
576+
{
577+
if( node->switch_data.branch_count > 1)
578+
{
579+
Rect parent_rect = nodeview_get_rect(nodeview);
580+
layout_begin_row();
581+
layout_set_padding(500.f,0,0,0);
582+
layout_set_gap( cfg->ui_node_gap(tools::Size_SM).x );
583+
584+
// TODO: There is an issue with Scope, its partition is never set and therefore is empty.
585+
// In the past, I've been implemented partitions to represent nested Scopes. But,
586+
// I don't know if this is the right method. I guess it could be also interested
587+
// to get special links to go from parent to child nodes.
588+
for( Scope* partition : node->internal_scope->partition )
589+
{
590+
Node* partition_node = partition->node();
591+
Node_View* partition_nodeview = node_component<Node_View>(partition->node());
592+
593+
_graphview_do_layout_recursively(graph_view, partition_nodeview);
594+
}
595+
layout_end();
596+
}
597+
}
598+
599+
// propagate on internal scope backbone
573600
for( Node* backbone_node : scope_get_backbone(node->internal_scope) )
574601
{
575602
Node_View* backbone_nodeview = node_component<Node_View>(backbone_node);
576-
_graphview_do_layout_recursively_on_expressions_only(graph_view, backbone_nodeview);
603+
_graphview_do_layout_recursively(graph_view, backbone_nodeview);
577604
}
578605
}
579606
layout_end();
580-
581-
// // Create a row with each branch
582-
// if( node_has_switch_behavior(node))
583-
// {
584-
// if( node->switch_data.branch_count > 1)
585-
// {
586-
// Rect parent_rect = nodeview_get_rect(node_view);
587-
// layout_set_cursor( parent_rect.bottom_left() + cfg->ui_node_gap() * Vec2(1.f, 1.f) );
588-
// layout_begin( Container_Config::Row );
589-
// layout_set_container_gap( cfg->ui_node_gap(tools::Size_SM).x );
590-
591-
// for( Scope* partition : node->internal_scope->partition )
592-
// {
593-
// Node* partition_node = partition->node();
594-
// Node_View* partition_nodeview = node_component<Node_View>(partition->node());
595-
596-
// Rect partition_rect = partition_nodeview->shape.rect(WORLD_SPACE);
597-
598-
// layout_push(partition_rect.width(), partition_rect.height(), partition_nodeview);
599-
// }
600-
// layout_end();
601-
// }
602-
// }
603607
};
604608

605609
void ndbl::graphview_update(Graph_View* graph_view, float dt)
@@ -618,7 +622,7 @@ void ndbl::graphview_update(Graph_View* graph_view, float dt)
618622
{
619623
Node* root_node = graph_root(graph_view->graph());
620624
auto* root_nodeview = node_component<Node_View>(root_node);
621-
layout_pin_element_at_position(root_nodeview->shape.position(tools::WORLD_SPACE) + get_config()->ui_textview_padding );
625+
layout_set_floating_at_position(root_nodeview->shape.position(tools::WORLD_SPACE) + get_config()->ui_textview_padding );
622626
_graphview_do_layout_recursively(graph_view, root_nodeview);
623627
}
624628
layout_end();

src/tools/gui/Layout.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace tools
4545
typedef int Position_Mode;
4646
enum Relative_To_ {
4747
Position_Mode_RELATIVE = 0,
48-
Position_Mode_STATIC = 1,
48+
Position_Mode_FLOATING = 1,
4949
};
5050

5151
struct Element
@@ -358,7 +358,7 @@ namespace tools
358358
Element* child = element.first_child;
359359
while(child != nullptr)
360360
{
361-
if( child->position_mode != Position_Mode_STATIC )
361+
if( child->position_mode != Position_Mode_FLOATING )
362362
{
363363
child->position = cursor;
364364
}
@@ -371,7 +371,7 @@ namespace tools
371371
{
372372
cursor.x += element.container.gap;
373373
}
374-
cursor.x += child->dimension.width;
374+
cursor.x += child->dimension.width + child->padding.left;
375375
break;
376376
}
377377

@@ -415,17 +415,17 @@ namespace tools
415415
elem_push_back(parent, new_element);
416416
}
417417

418-
inline void layout_pin_element()
418+
inline void layout_set_floating()
419419
{
420420
Element* elem = layout_current_element();
421-
elem->position_mode = Position_Mode_STATIC;
421+
elem->position_mode = Position_Mode_FLOATING;
422422
}
423423

424-
inline void layout_pin_element_at_position(Vec2 position)
424+
inline void layout_set_floating_at_position(Vec2 position)
425425
{
426426
Element* elem = layout_current_element();
427427
elem->position = position;
428-
elem->position_mode = Position_Mode_STATIC;
428+
elem->position_mode = Position_Mode_FLOATING;
429429
}
430430

431431
inline void layout_append_element(float width, float height, void* userdata)

0 commit comments

Comments
 (0)