Refactor - Internal ButtonBehavior() removed unnecessary boolean arg, merged into flags using ImGuiButtonFlags_NoKeyModifiers.

This is quite a risky change frankly but I'd rather refactor sooner than
later. Hopefully few people are using the internal functions.
This commit is contained in:
ocornut 2015-10-30 11:36:51 +01:00
parent e858d229a0
commit 3eabad0321
2 changed files with 16 additions and 15 deletions

View file

@ -3851,7 +3851,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
const ImRect resize_rect(br - ImVec2(resize_corner_size * 0.75f, resize_corner_size * 0.75f), br);
const ImGuiID resize_id = window->GetID("#RESIZE");
bool hovered, held;
ButtonBehavior(resize_rect, resize_id, &hovered, &held, true, ImGuiButtonFlags_FlattenChilds);
ButtonBehavior(resize_rect, resize_id, &hovered, &held, ImGuiButtonFlags_FlattenChilds);
resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
if (hovered || held)
@ -4112,7 +4112,7 @@ static void Scrollbar(ImGuiWindow* window, bool horizontal)
bool held = false;
bool hovered = false;
const bool previously_held = (g.ActiveId == id);
ImGui::ButtonBehavior(bb, id, &hovered, &held, true);
ImGui::ButtonBehavior(bb, id, &hovered, &held);
float scroll_max = ImMax(1.0f, win_size_contents_v - win_size_avail_v);
float scroll_ratio = ImSaturate(scroll_v / scroll_max);
@ -5130,7 +5130,7 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window)
return true;
}
bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, ImGuiButtonFlags flags)
bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags)
{
ImGuiState& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
@ -5148,7 +5148,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
if (hovered)
{
SetHoveredID(id);
if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt))
if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt))
{
if (g.IO.MouseClicked[0])
{
@ -5219,7 +5219,7 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags
if (window->DC.ButtonRepeat) flags |= ImGuiButtonFlags_Repeat;
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, true, flags);
bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
// Render
const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
@ -5265,7 +5265,7 @@ bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg)
return false;
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
return pressed;
}
@ -5280,7 +5280,7 @@ static bool CloseWindowButton(bool* p_opened)
const ImRect bb(window->Rect().GetTR() + ImVec2(-2.0f-size,2.0f), window->Rect().GetTR() + ImVec2(-2.0f,2.0f+size));
bool hovered, held;
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, true);
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held);
// Render
const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
@ -5351,7 +5351,7 @@ bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const I
return false;
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
// Render
const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
@ -5557,7 +5557,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
return opened;
bool hovered, held;
bool pressed = ButtonBehavior(interact_bb, id, &hovered, &held, false);
bool pressed = ButtonBehavior(interact_bb, id, &hovered, &held, ImGuiButtonFlags_NoKeyModifiers);
if (pressed)
{
opened = !opened;
@ -6754,7 +6754,7 @@ bool ImGui::Checkbox(const char* label, bool* v)
return false;
bool hovered, held;
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true);
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
if (pressed)
*v = !(*v);
@ -6817,7 +6817,7 @@ bool ImGui::RadioButton(const char* label, bool active)
const float radius = check_bb.GetHeight() * 0.5f;
bool hovered, held;
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held, true);
bool pressed = ButtonBehavior(total_bb, id, &hovered, &held);
window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), 16);
if (active)
@ -8003,7 +8003,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
if (flags & ImGuiSelectableFlags_MenuItem) button_flags |= ImGuiButtonFlags_PressedOnClick|ImGuiButtonFlags_PressedOnRelease;
if (flags & ImGuiSelectableFlags_Disabled) button_flags |= ImGuiButtonFlags_Disabled;
bool hovered, held;
bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, true, button_flags);
bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, button_flags);
if (flags & ImGuiSelectableFlags_Disabled)
selected = false;
@ -8359,7 +8359,7 @@ bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_borde
return false;
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border, style.FrameRounding);
if (hovered)

View file

@ -148,7 +148,8 @@ enum ImGuiButtonFlags_
ImGuiButtonFlags_FlattenChilds = 1 << 3,
ImGuiButtonFlags_DontClosePopups = 1 << 4,
ImGuiButtonFlags_Disabled = 1 << 5,
ImGuiButtonFlags_AlignTextBaseLine = 1 << 6
ImGuiButtonFlags_AlignTextBaseLine = 1 << 6,
ImGuiButtonFlags_NoKeyModifiers = 1 << 7
};
enum ImGuiTreeNodeFlags_
@ -673,7 +674,7 @@ namespace ImGui
IMGUI_API void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col);
IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, ImGuiButtonFlags flags = 0);
IMGUI_API bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags = 0);
IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0);
IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, bool horizontal);