mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 13:11:05 +01:00 
			
		
		
		
	Expose BeginDisabled()/EndDisabled() in public API. Add to demo. (#211)
This commit is contained in:
		| @@ -533,6 +533,10 @@ static void ShowDemoWindowWidgets() | ||||
|     if (!ImGui::CollapsingHeader("Widgets")) | ||||
|         return; | ||||
|  | ||||
|     static bool disable_all = false; // The Checkbox for that is inside the "Disabled" section at the bottom | ||||
|     if (disable_all) | ||||
|         ImGui::BeginDisabled(); | ||||
|  | ||||
|     if (ImGui::TreeNode("Basic")) | ||||
|     { | ||||
|         static int clicked = 0; | ||||
| @@ -2181,7 +2185,7 @@ static void ShowDemoWindowWidgets() | ||||
|         ImGui::TreePop(); | ||||
|     } | ||||
|  | ||||
|     if (ImGui::TreeNode("Querying Status (Edited/Active/Focused/Hovered etc.)")) | ||||
|     if (ImGui::TreeNode("Querying Status (Edited/Active/Hovered etc.)")) | ||||
|     { | ||||
|         // Select an item type | ||||
|         const char* item_names[] = | ||||
| @@ -2189,16 +2193,20 @@ static void ShowDemoWindowWidgets() | ||||
|             "Text", "Button", "Button (w/ repeat)", "Checkbox", "SliderFloat", "InputText", "InputFloat", | ||||
|             "InputFloat3", "ColorEdit4", "Selectable", "MenuItem", "TreeNode", "TreeNode (w/ double-click)", "Combo", "ListBox" | ||||
|         }; | ||||
|         static int item_type = 1; | ||||
|         static int item_type = 4; | ||||
|         static bool item_disabled = false; | ||||
|         ImGui::Combo("Item Type", &item_type, item_names, IM_ARRAYSIZE(item_names), IM_ARRAYSIZE(item_names)); | ||||
|         ImGui::SameLine(); | ||||
|         HelpMarker("Testing how various types of items are interacting with the IsItemXXX functions. Note that the bool return value of most ImGui function is generally equivalent to calling ImGui::IsItemHovered()."); | ||||
|         ImGui::Checkbox("Item Disabled",  &item_disabled); | ||||
|  | ||||
|         // Submit selected item item so we can query their status in the code following it. | ||||
|         bool ret = false; | ||||
|         static bool b = false; | ||||
|         static float col4f[4] = { 1.0f, 0.5, 0.0f, 1.0f }; | ||||
|         static char str[16] = {}; | ||||
|         if (item_disabled) | ||||
|             ImGui::BeginDisabled(true); | ||||
|         if (item_type == 0) { ImGui::Text("ITEM: Text"); }                                              // Testing text items with no identifier/interaction | ||||
|         if (item_type == 1) { ret = ImGui::Button("ITEM: Button"); }                                    // Testing button | ||||
|         if (item_type == 2) { ImGui::PushButtonRepeat(true); ret = ImGui::Button("ITEM: Button"); ImGui::PopButtonRepeat(); } // Testing button (with repeater) | ||||
| @@ -2226,6 +2234,7 @@ static void ShowDemoWindowWidgets() | ||||
|             "IsItemHovered(_AllowWhenBlockedByPopup) = %d\n" | ||||
|             "IsItemHovered(_AllowWhenBlockedByActiveItem) = %d\n" | ||||
|             "IsItemHovered(_AllowWhenOverlapped) = %d\n" | ||||
|             "IsItemHovered(_AllowWhenDisabled) = %d\n" | ||||
|             "IsItemHovered(_RectOnly) = %d\n" | ||||
|             "IsItemActive() = %d\n" | ||||
|             "IsItemEdited() = %d\n" | ||||
| @@ -2244,6 +2253,7 @@ static void ShowDemoWindowWidgets() | ||||
|             ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup), | ||||
|             ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem), | ||||
|             ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlapped), | ||||
|             ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled), | ||||
|             ImGui::IsItemHovered(ImGuiHoveredFlags_RectOnly), | ||||
|             ImGui::IsItemActive(), | ||||
|             ImGui::IsItemEdited(), | ||||
| @@ -2258,6 +2268,9 @@ static void ShowDemoWindowWidgets() | ||||
|             ImGui::GetItemRectSize().x, ImGui::GetItemRectSize().y | ||||
|         ); | ||||
|  | ||||
|         if (item_disabled) | ||||
|             ImGui::EndDisabled(); | ||||
|  | ||||
|         static bool embed_all_inside_a_child_window = false; | ||||
|         ImGui::Checkbox("Embed everything inside a child window (for additional testing)", &embed_all_inside_a_child_window); | ||||
|         if (embed_all_inside_a_child_window) | ||||
| @@ -2327,6 +2340,18 @@ static void ShowDemoWindowWidgets() | ||||
|  | ||||
|         ImGui::TreePop(); | ||||
|     } | ||||
|  | ||||
|     // Demonstrate BeginDisabled/EndDisabled using a checkbox located at the bottom of the section (which is a bit odd: | ||||
|     // logically we'd have this checkbox at the top of the section, but we don't want this feature to steal that space) | ||||
|     if (disable_all) | ||||
|         ImGui::EndDisabled(); | ||||
|  | ||||
|     if (ImGui::TreeNode("Disable block")) | ||||
|     { | ||||
|         ImGui::Checkbox("Disable entire section above", &disable_all); | ||||
|         ImGui::SameLine(); HelpMarker("Demonstrate using BeginDisabled()/EndDisabled() across this section."); | ||||
|         ImGui::TreePop(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| static void ShowDemoWindowLayout() | ||||
| @@ -2396,7 +2421,7 @@ static void ShowDemoWindowLayout() | ||||
|         //   You can also call SetNextWindowPos() to position the child window. The parent window will effectively | ||||
|         //   layout from this position. | ||||
|         // - Using ImGui::GetItemRectMin/Max() to query the "item" state (because the child window is an item from | ||||
|         //   the POV of the parent window). See 'Demo->Querying Status (Active/Focused/Hovered etc.)' for details. | ||||
|         //   the POV of the parent window). See 'Demo->Querying Status (Edited/Active/Hovered etc.)' for details. | ||||
|         { | ||||
|             static int offset_x = 0; | ||||
|             ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); | ||||
| @@ -6041,6 +6066,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) | ||||
|             HelpMarker("When drawing circle primitives with \"num_segments == 0\" tesselation will be calculated automatically."); | ||||
|  | ||||
|             ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero. | ||||
|             ImGui::DragFloat("Disabled Alpha", &style.DisabledAlpha, 0.005f, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); HelpMarker("Additional alpha multiplier for disabled items (multiply over current value of Alpha)."); | ||||
|             ImGui::PopItemWidth(); | ||||
|  | ||||
|             ImGui::EndTabItem(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user