mirror of https://github.com/ocornut/imgui
Added ArrowButton(). Exposed ImGuiDir.
This commit is contained in:
parent
1549c5cf5e
commit
8a4093f38b
|
@ -92,6 +92,7 @@ Other Changes:
|
|||
- Window: Added SetNextWindowBgAlpha() helper. Particularly helpul since the legacy 5-parameters version of Begin() has been marked as obsolete in 1.53. (#1567)
|
||||
- Window: Fixed SetNextWindowContentSize() with 0.0f on Y axis (or SetNextWindowContentWidth()) overwriting the contents size. Got broken on Dec 10 (1.53). (#1363)
|
||||
- Window: CloseButton: Fixed cross positioning being a little off.
|
||||
- ArrowButton: Added ArrowButton() given a cardinal direction (e.g. ImGuiDir_Left).
|
||||
- InputText: Added alternative clipboard shortcuts: Shift+Delete (cut), Ctrl+Insert (copy), Shift+Insert (paste). (#1541)
|
||||
- InputText: Fixed losing Cursor X position when clicking outside on an item that's submitted after the InputText(). It was only noticeable when restoring focus programmatically. (#1418, #1554)
|
||||
- Style: Enable window border by default. (#707)
|
||||
|
|
38
imgui.cpp
38
imgui.cpp
|
@ -4306,7 +4306,7 @@ void ImGui::RenderArrow(ImVec2 p_min, ImGuiDir dir, float scale)
|
|||
c = ImVec2(-0.500f,-0.866f) * r;
|
||||
break;
|
||||
case ImGuiDir_None:
|
||||
case ImGuiDir_Count_:
|
||||
case ImGuiDir_COUNT:
|
||||
IM_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
|
@ -5200,8 +5200,8 @@ static ImVec2 FindBestWindowPosForPopup(const ImVec2& ref_pos, const ImVec2& siz
|
|||
// Combo Box policy (we want a connecting edge)
|
||||
if (policy == ImGuiPopupPositionPolicy_ComboBox)
|
||||
{
|
||||
const ImGuiDir dir_prefered_order[ImGuiDir_Count_] = { ImGuiDir_Down, ImGuiDir_Right, ImGuiDir_Left, ImGuiDir_Up };
|
||||
for (int n = (*last_dir != ImGuiDir_None) ? -1 : 0; n < ImGuiDir_Count_; n++)
|
||||
const ImGuiDir dir_prefered_order[ImGuiDir_COUNT] = { ImGuiDir_Down, ImGuiDir_Right, ImGuiDir_Left, ImGuiDir_Up };
|
||||
for (int n = (*last_dir != ImGuiDir_None) ? -1 : 0; n < ImGuiDir_COUNT; n++)
|
||||
{
|
||||
const ImGuiDir dir = (n == -1) ? *last_dir : dir_prefered_order[n];
|
||||
if (n != -1 && dir == *last_dir) // Already tried this direction?
|
||||
|
@ -5219,8 +5219,8 @@ static ImVec2 FindBestWindowPosForPopup(const ImVec2& ref_pos, const ImVec2& siz
|
|||
}
|
||||
|
||||
// Default popup policy
|
||||
const ImGuiDir dir_prefered_order[ImGuiDir_Count_] = { ImGuiDir_Right, ImGuiDir_Down, ImGuiDir_Up, ImGuiDir_Left };
|
||||
for (int n = (*last_dir != ImGuiDir_None) ? -1 : 0; n < ImGuiDir_Count_; n++)
|
||||
const ImGuiDir dir_prefered_order[ImGuiDir_COUNT] = { ImGuiDir_Right, ImGuiDir_Down, ImGuiDir_Up, ImGuiDir_Left };
|
||||
for (int n = (*last_dir != ImGuiDir_None) ? -1 : 0; n < ImGuiDir_COUNT; n++)
|
||||
{
|
||||
const ImGuiDir dir = (n == -1) ? *last_dir : dir_prefered_order[n];
|
||||
if (n != -1 && dir == *last_dir) // Already tried this direction?
|
||||
|
@ -7663,6 +7663,32 @@ bool ImGui::SmallButton(const char* label)
|
|||
return pressed;
|
||||
}
|
||||
|
||||
bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiID id = window->GetID(str_id);
|
||||
float sz = ImGui::GetFrameHeight();
|
||||
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(sz, sz));
|
||||
ItemSize(bb);
|
||||
if (!ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb, id, &hovered, &held);
|
||||
|
||||
// Render
|
||||
const ImU32 col = GetColorU32((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
|
||||
RenderNavHighlight(bb, id);
|
||||
RenderFrame(bb.Min, bb.Max, col, true, g.Style.FrameRounding);
|
||||
RenderArrow(bb.Min + g.Style.FramePadding, dir);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
// Tip: use ImGui::PushID()/PopID() to push indices or pointers in the ID stack.
|
||||
// Then you can keep 'str_id' empty or the same for all your buttons (instead of creating a string based on a non-string id)
|
||||
bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg)
|
||||
|
@ -11734,7 +11760,7 @@ static void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGui
|
|||
case ImGuiDir_Right: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), pos, col); return;
|
||||
case ImGuiDir_Up: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), pos, col); return;
|
||||
case ImGuiDir_Down: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), pos, col); return;
|
||||
case ImGuiDir_None: case ImGuiDir_Count_: break; // Fix warnings
|
||||
case ImGuiDir_None: case ImGuiDir_COUNT: break; // Fix warnings
|
||||
}
|
||||
}
|
||||
|
||||
|
|
15
imgui.h
15
imgui.h
|
@ -78,11 +78,12 @@ struct ImGuiContext; // ImGui context (opaque)
|
|||
typedef void* ImTextureID; // user data to identify a texture (this is whatever to you want it to be! read the FAQ about ImTextureID in imgui.cpp)
|
||||
#endif
|
||||
|
||||
// Typedefs and Enumerations (declared as int for compatibility and to not pollute the top of this file)
|
||||
// Typedefs and Enumerations (declared as int for compatibility with old C++ and to not pollute the top of this file)
|
||||
typedef unsigned int ImU32; // 32-bit unsigned integer (typically used to store packed colors)
|
||||
typedef unsigned int ImGuiID; // unique ID used by widgets (typically hashed from a stack of string)
|
||||
typedef unsigned short ImWchar; // character for keyboard input/display
|
||||
typedef int ImGuiCol; // enum: a color identifier for styling // enum ImGuiCol_
|
||||
typedef int ImGuiDir; // enum: a cardinal direction // enum ImGuiDir_
|
||||
typedef int ImGuiCond; // enum: a condition for Set*() // enum ImGuiCond_
|
||||
typedef int ImGuiKey; // enum: a key identifier (ImGui-side enum) // enum ImGuiKey_
|
||||
typedef int ImGuiNavInput; // enum: an input identifier for navigation // enum ImGuiNavInput_
|
||||
|
@ -312,6 +313,7 @@ namespace ImGui
|
|||
// Widgets: Main
|
||||
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0)); // button
|
||||
IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text
|
||||
IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir);
|
||||
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); // button behavior without the visuals, useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.)
|
||||
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));
|
||||
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding
|
||||
|
@ -687,6 +689,17 @@ enum ImGuiDragDropFlags_
|
|||
#define IMGUI_PAYLOAD_TYPE_COLOR_3F "_COL3F" // float[3] // Standard type for colors, without alpha. User code may use this type.
|
||||
#define IMGUI_PAYLOAD_TYPE_COLOR_4F "_COL4F" // float[4] // Standard type for colors. User code may use this type.
|
||||
|
||||
// A direction
|
||||
enum ImGuiDir_
|
||||
{
|
||||
ImGuiDir_None = -1,
|
||||
ImGuiDir_Left = 0,
|
||||
ImGuiDir_Right = 1,
|
||||
ImGuiDir_Up = 2,
|
||||
ImGuiDir_Down = 3,
|
||||
ImGuiDir_COUNT
|
||||
};
|
||||
|
||||
// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
|
||||
enum ImGuiKey_
|
||||
{
|
||||
|
|
|
@ -300,6 +300,12 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
|||
ImGui::PopID();
|
||||
}
|
||||
|
||||
// Arrow buttons
|
||||
float spacing = ImGui::GetStyle().ItemInnerSpacing.x;
|
||||
if (ImGui::ArrowButton("##left", ImGuiDir_Left)) {}
|
||||
ImGui::SameLine(0.0f, spacing);
|
||||
if (ImGui::ArrowButton("##left", ImGuiDir_Right)) {}
|
||||
|
||||
ImGui::Text("Hover over me");
|
||||
if (ImGui::IsItemHovered())
|
||||
ImGui::SetTooltip("I am a tooltip");
|
||||
|
|
|
@ -260,16 +260,6 @@ enum ImGuiDataType
|
|||
ImGuiDataType_Float2
|
||||
};
|
||||
|
||||
enum ImGuiDir
|
||||
{
|
||||
ImGuiDir_None = -1,
|
||||
ImGuiDir_Left = 0,
|
||||
ImGuiDir_Right = 1,
|
||||
ImGuiDir_Up = 2,
|
||||
ImGuiDir_Down = 3,
|
||||
ImGuiDir_Count_
|
||||
};
|
||||
|
||||
enum ImGuiInputSource
|
||||
{
|
||||
ImGuiInputSource_None = 0,
|
||||
|
|
Loading…
Reference in New Issue