@@ -1506,24 +1506,21 @@ static void ShowDemoWindowWidgets()
1506
1506
1507
1507
if (ImGui::TreeNode (" Drag and Drop" ))
1508
1508
{
1509
+ if (ImGui::TreeNode (" Drag and drop in standard widgets" ))
1509
1510
{
1510
1511
// ColorEdit widgets automatically act as drag source and drag target.
1511
1512
// They are using standardized payload strings IMGUI_PAYLOAD_TYPE_COLOR_3F and IMGUI_PAYLOAD_TYPE_COLOR_4F to allow your own widgets
1512
1513
// to use colors in their drag and drop interaction. Also see the demo in Color Picker -> Palette demo.
1513
- ImGui::BulletText (" Drag and drop in standard widgets" );
1514
- ImGui::SameLine ();
1515
1514
HelpMarker (" You can drag from the colored squares." );
1516
- ImGui::Indent ();
1517
- static float col1[3 ] = { 1 .0f ,0 .0f ,0 .2f };
1518
- static float col2[4 ] = { 0 .4f ,0 .7f ,0 .0f ,0 .5f };
1515
+ static float col1[3 ] = { 1 .0f , 0 .0f , 0 .2f };
1516
+ static float col2[4 ] = { 0 .4f , 0 .7f , 0 .0f , 0 .5f };
1519
1517
ImGui::ColorEdit3 (" color 1" , col1);
1520
1518
ImGui::ColorEdit4 (" color 2" , col2);
1521
- ImGui::Unindent ();
1519
+ ImGui::TreePop ();
1522
1520
}
1523
1521
1522
+ if (ImGui::TreeNode (" Drag and drop to copy/swap items" ))
1524
1523
{
1525
- ImGui::BulletText (" Drag and drop to copy/swap items" );
1526
- ImGui::Indent ();
1527
1524
enum Mode
1528
1525
{
1529
1526
Mode_Copy,
@@ -1577,7 +1574,31 @@ static void ShowDemoWindowWidgets()
1577
1574
}
1578
1575
ImGui::PopID ();
1579
1576
}
1580
- ImGui::Unindent ();
1577
+ ImGui::TreePop ();
1578
+ }
1579
+
1580
+ if (ImGui::TreeNode (" Drag to reorder items (simple)" ))
1581
+ {
1582
+ // Simple reordering
1583
+ HelpMarker (" We don't use the drag and drop api at all here! Instead we query when the item is held but not hovered, and order items accordingly." );
1584
+ static const char * item_names[] = { " Item One" , " Item Two" , " Item Three" , " Item Four" , " Item Five" };
1585
+ for (int n = 0 ; n < IM_ARRAYSIZE (item_names); n++)
1586
+ {
1587
+ const char * item = item_names[n];
1588
+ ImGui::Selectable (item);
1589
+
1590
+ if (ImGui::IsItemActive () && !ImGui::IsItemHovered ())
1591
+ {
1592
+ int n_next = n + (ImGui::GetMouseDragDelta (0 ).y < 0 .f ? -1 : 1 );
1593
+ if (n_next >= 0 && n_next < IM_ARRAYSIZE (item_names))
1594
+ {
1595
+ item_names[n] = item_names[n_next];
1596
+ item_names[n_next] = item;
1597
+ ImGui::ResetMouseDragDelta ();
1598
+ }
1599
+ }
1600
+ }
1601
+ ImGui::TreePop ();
1581
1602
}
1582
1603
1583
1604
ImGui::TreePop ();
@@ -1607,10 +1628,10 @@ static void ShowDemoWindowWidgets()
1607
1628
if (item_type == 10 ){ ret = ImGui::TreeNodeEx (" ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick" , ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy.
1608
1629
if (item_type == 11 ){ const char * items[] = { " Apple" , " Banana" , " Cherry" , " Kiwi" }; static int current = 1 ; ret = ImGui::ListBox (" ITEM: ListBox" , ¤t, items, IM_ARRAYSIZE (items), IM_ARRAYSIZE (items)); }
1609
1630
1610
- // Display the value of IsItemHovered() and other common item state functions.
1631
+ // Display the value of IsItemHovered() and other common item state functions.
1611
1632
// Note that the ImGuiHoveredFlags_XXX flags can be combined.
1612
- // Because BulletText is an item itself and that would affect the output of IsItemXXX functions,
1613
- // we query every state in a single call to avoid storing them and to simplify the code
1633
+ // Because BulletText is an item itself and that would affect the output of IsItemXXX functions,
1634
+ // we query every state in a single call to avoid storing them and to simplify the code
1614
1635
ImGui::BulletText (
1615
1636
" Return value = %d\n "
1616
1637
" IsItemFocused() = %d\n "
@@ -1653,7 +1674,7 @@ static void ShowDemoWindowWidgets()
1653
1674
if (embed_all_inside_a_child_window)
1654
1675
ImGui::BeginChild (" outer_child" , ImVec2 (0 , ImGui::GetFontSize () * 20 ), true );
1655
1676
1656
- // Testing IsWindowFocused() function with its various flags.
1677
+ // Testing IsWindowFocused() function with its various flags.
1657
1678
// Note that the ImGuiFocusedFlags_XXX flags can be combined.
1658
1679
ImGui::BulletText (
1659
1680
" IsWindowFocused() = %d\n "
0 commit comments