mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-24 00:26:36 +00:00
Added PushButtonRepeat() / PopButtonRepeat(). REMOVED third 'repeat_if_held' parameter of Button() !
This commit is contained in:
parent
d69f2f57ee
commit
3d36c81241
37
imgui.cpp
37
imgui.cpp
@ -136,6 +136,7 @@
|
||||
Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix.
|
||||
Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
|
||||
|
||||
- 2015/05/27 (1.39) - removed the third 'repeat_if_held' parameter from Button() - sorry! it was rarely used and inconsistent. Use PushButtonRepeat(true) / PopButtonRepeat() to enable repeat on desired buttons.
|
||||
- 2015/05/11 (1.39) - changed BeginPopup() API, takes a string identifier instead of a bool. ImGui needs to manage the open/closed state of popups. Call OpenPopup() to actually set the "opened" state of a popup. BeginPopup() returns true if the popup is opened.
|
||||
- 2015/05/03 (1.39) - removed style.AutoFitPadding, using style.WindowPadding makes more sense (the default values were already the same).
|
||||
- 2015/04/13 (1.38) - renamed IsClipped() to IsRectClipped(). Kept inline redirection function (will obsolete).
|
||||
@ -1104,13 +1105,16 @@ struct ImGuiDrawContext
|
||||
bool MenuBarAppending;
|
||||
float MenuBarOffsetX;
|
||||
ImVector<ImGuiWindow*> ChildWindows;
|
||||
ImGuiStorage* StateStorage;
|
||||
ImGuiLayoutType LayoutType;
|
||||
|
||||
bool ButtonRepeat; // == ButtonRepeatStack.back() [false]
|
||||
ImVector<bool> ButtonRepeatStack;
|
||||
ImVector<bool> AllowKeyboardFocus;
|
||||
ImVector<float> ItemWidth; // 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
|
||||
ImVector<float> TextWrapPos;
|
||||
ImVector<ImGuiGroupData> GroupStack;
|
||||
ImGuiColorEditMode ColorEditMode;
|
||||
ImGuiStorage* StateStorage;
|
||||
int StackSizesBackup[6]; // Store size of various stacks for asserting
|
||||
|
||||
float ColumnsStartX; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.)
|
||||
@ -1136,9 +1140,9 @@ struct ImGuiDrawContext
|
||||
LastItemHoveredAndUsable = LastItemHoveredRect = false;
|
||||
MenuBarAppending = false;
|
||||
MenuBarOffsetX = 0.0f;
|
||||
StateStorage = NULL;
|
||||
LayoutType = ImGuiLayoutType_Vertical;
|
||||
ColorEditMode = ImGuiColorEditMode_RGB;
|
||||
StateStorage = NULL;
|
||||
memset(StackSizesBackup, 0, sizeof(StackSizesBackup));
|
||||
|
||||
ColumnsStartX = 0.0f;
|
||||
@ -3785,6 +3789,8 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
|
||||
window->DC.ItemWidth.resize(0);
|
||||
window->DC.ItemWidth.push_back(window->ItemWidthDefault);
|
||||
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
||||
window->DC.ButtonRepeat = false;
|
||||
window->DC.ButtonRepeatStack.resize(0);
|
||||
window->DC.AllowKeyboardFocus.resize(0);
|
||||
window->DC.AllowKeyboardFocus.push_back(true);
|
||||
window->DC.TextWrapPos.resize(0);
|
||||
@ -4076,6 +4082,20 @@ void ImGui::PopAllowKeyboardFocus()
|
||||
window->DC.AllowKeyboardFocus.pop_back();
|
||||
}
|
||||
|
||||
void ImGui::PushButtonRepeat(bool repeat)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
window->DC.ButtonRepeat = repeat;
|
||||
window->DC.ButtonRepeatStack.push_back(repeat);
|
||||
}
|
||||
|
||||
void ImGui::PopButtonRepeat()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
window->DC.ButtonRepeatStack.pop_back();
|
||||
window->DC.ButtonRepeat = window->DC.ButtonRepeatStack.empty() ? false : window->DC.ButtonRepeatStack.back();
|
||||
}
|
||||
|
||||
void ImGui::PushTextWrapPos(float wrap_x)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
@ -4868,7 +4888,7 @@ static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
|
||||
return pressed;
|
||||
}
|
||||
|
||||
static bool ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags flags)
|
||||
static bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
@ -4885,6 +4905,7 @@ static bool ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags
|
||||
if (!ItemAdd(bb, &id))
|
||||
return false;
|
||||
|
||||
if (window->DC.ButtonRepeat) flags |= ImGuiButtonFlags_Repeat;
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held, true, flags);
|
||||
|
||||
@ -4900,22 +4921,18 @@ static bool ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags
|
||||
return pressed;
|
||||
}
|
||||
|
||||
bool ImGui::Button(const char* label, const ImVec2& size_arg, bool repeat_when_held)
|
||||
bool ImGui::Button(const char* label, const ImVec2& size_arg)
|
||||
{
|
||||
return ButtonEx(label, size_arg, repeat_when_held ? ImGuiButtonFlags_Repeat : 0);
|
||||
return ButtonEx(label, size_arg, 0);
|
||||
}
|
||||
|
||||
// Small buttons fits within text without additional vertical spacing.
|
||||
bool ImGui::SmallButton(const char* label)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiState& g = *GImGui;
|
||||
float backup_padding_y = g.Style.FramePadding.y;
|
||||
g.Style.FramePadding.y = 0.0f;
|
||||
bool pressed = ButtonEx(label, ImVec2(0,0), 0);
|
||||
bool pressed = ButtonEx(label);
|
||||
g.Style.FramePadding.y = backup_padding_y;
|
||||
return pressed;
|
||||
}
|
||||
|
4
imgui.h
4
imgui.h
@ -157,6 +157,8 @@ namespace ImGui
|
||||
IMGUI_API void PopAllowKeyboardFocus();
|
||||
IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space
|
||||
IMGUI_API void PopTextWrapPos();
|
||||
IMGUI_API void PushButtonRepeat(bool repeat); // in 'repeat' mode, Button*() functions return true multiple times as you hold them (uses io.KeyRepeatDelay/io.KeyRepeatRate for now)
|
||||
IMGUI_API void PopButtonRepeat();
|
||||
|
||||
// Tooltip
|
||||
IMGUI_API void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins
|
||||
@ -225,7 +227,7 @@ namespace ImGui
|
||||
IMGUI_API void Bullet();
|
||||
IMGUI_API void BulletText(const char* fmt, ...);
|
||||
IMGUI_API void BulletTextV(const char* fmt, va_list args);
|
||||
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0), bool repeat_when_held = false);
|
||||
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0));
|
||||
IMGUI_API bool SmallButton(const char* label);
|
||||
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size);
|
||||
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
|
||||
|
Loading…
Reference in New Issue
Block a user