Style: Added style.TabMinWidthForUnselectedCloseButton settings.
Set to 0.0f (default) to always make a close button appear on hover (same as Chrome, VS). Set to FLT_MAX to only display a close button when selected (merely hovering is not enough). Set to an intermediary value to toggle behavior based on width (same as Firefox).
This commit is contained in:
parent
099091280f
commit
b4dd28ffbb
@ -46,6 +46,10 @@ Other Changes:
|
|||||||
flag was also set, and _OpenOnArrow is frequently set along with _OpenOnDoubleClick).
|
flag was also set, and _OpenOnArrow is frequently set along with _OpenOnDoubleClick).
|
||||||
- TreeNode: Fixed bug where dragging a payload over a TreeNode() with either _OpenOnDoubleClick
|
- TreeNode: Fixed bug where dragging a payload over a TreeNode() with either _OpenOnDoubleClick
|
||||||
or _OpenOnArrow would open the node. (#143)
|
or _OpenOnArrow would open the node. (#143)
|
||||||
|
- Style: Added style.TabMinWidthForUnselectedCloseButton settings.
|
||||||
|
Set to 0.0f (default) to always make a close button appear on hover (same as Chrome, VS).
|
||||||
|
Set to FLT_MAX to only display a close button when selected (merely hovering is not enough).
|
||||||
|
Set to an intermediary value to toggle behavior based on width (same as Firefox).
|
||||||
- Backends: Win32: Support for #define NOGDI, won't try to call GetDeviceCaps(). (#3137, #2327)
|
- Backends: Win32: Support for #define NOGDI, won't try to call GetDeviceCaps(). (#3137, #2327)
|
||||||
- Backends: OpenGL: Fixed handling of GL 4.5+ glClipControl(GL_UPPER_LEFT) by inverting the
|
- Backends: OpenGL: Fixed handling of GL 4.5+ glClipControl(GL_UPPER_LEFT) by inverting the
|
||||||
projection matrix top and bottom values. (#3143, #3146) [@u3shit]
|
projection matrix top and bottom values. (#3143, #3146) [@u3shit]
|
||||||
|
@ -1028,6 +1028,7 @@ ImGuiStyle::ImGuiStyle()
|
|||||||
GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
||||||
TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
|
TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
|
||||||
TabBorderSize = 0.0f; // Thickness of border around tabs.
|
TabBorderSize = 0.0f; // Thickness of border around tabs.
|
||||||
|
TabMinWidthForUnselectedCloseButton = 0.0f; // Minimum width for close button to appears on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
|
||||||
ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
|
ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
|
||||||
ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text.
|
ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text.
|
||||||
SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
|
SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
|
||||||
@ -1064,6 +1065,8 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
|
|||||||
GrabMinSize = ImFloor(GrabMinSize * scale_factor);
|
GrabMinSize = ImFloor(GrabMinSize * scale_factor);
|
||||||
GrabRounding = ImFloor(GrabRounding * scale_factor);
|
GrabRounding = ImFloor(GrabRounding * scale_factor);
|
||||||
TabRounding = ImFloor(TabRounding * scale_factor);
|
TabRounding = ImFloor(TabRounding * scale_factor);
|
||||||
|
if (TabMinWidthForUnselectedCloseButton != FLT_MAX)
|
||||||
|
TabMinWidthForUnselectedCloseButton = ImFloor(TabMinWidthForUnselectedCloseButton * scale_factor);
|
||||||
DisplayWindowPadding = ImFloor(DisplayWindowPadding * scale_factor);
|
DisplayWindowPadding = ImFloor(DisplayWindowPadding * scale_factor);
|
||||||
DisplaySafeAreaPadding = ImFloor(DisplaySafeAreaPadding * scale_factor);
|
DisplaySafeAreaPadding = ImFloor(DisplaySafeAreaPadding * scale_factor);
|
||||||
MouseCursorScale = ImFloor(MouseCursorScale * scale_factor);
|
MouseCursorScale = ImFloor(MouseCursorScale * scale_factor);
|
||||||
|
1
imgui.h
1
imgui.h
@ -1393,6 +1393,7 @@ struct ImGuiStyle
|
|||||||
float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
||||||
float TabRounding; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
|
float TabRounding; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
|
||||||
float TabBorderSize; // Thickness of border around tabs.
|
float TabBorderSize; // Thickness of border around tabs.
|
||||||
|
float TabMinWidthForUnselectedCloseButton; // Minimum width for close button to appears on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
|
||||||
ImGuiDir ColorButtonPosition; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
|
ImGuiDir ColorButtonPosition; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
|
||||||
ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered).
|
ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered).
|
||||||
ImVec2 SelectableTextAlign; // Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
|
ImVec2 SelectableTextAlign; // Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
|
||||||
|
@ -1827,7 +1827,7 @@ namespace ImGui
|
|||||||
IMGUI_API bool TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags);
|
IMGUI_API bool TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags);
|
||||||
IMGUI_API ImVec2 TabItemCalcSize(const char* label, bool has_close_button);
|
IMGUI_API ImVec2 TabItemCalcSize(const char* label, bool has_close_button);
|
||||||
IMGUI_API void TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col);
|
IMGUI_API void TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col);
|
||||||
IMGUI_API bool TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImVec2 frame_padding, const char* label, ImGuiID tab_id, ImGuiID close_button_id);
|
IMGUI_API bool TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImVec2 frame_padding, const char* label, ImGuiID tab_id, ImGuiID close_button_id, bool is_contents_visible);
|
||||||
|
|
||||||
// Render helpers
|
// Render helpers
|
||||||
// AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION. THOSE FUNCTIONS ARE A MESS. THEIR SIGNATURE AND BEHAVIOR WILL CHANGE, THEY NEED TO BE REFACTORED INTO SOMETHING DECENT.
|
// AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION. THOSE FUNCTIONS ARE A MESS. THEIR SIGNATURE AND BEHAVIOR WILL CHANGE, THEY NEED TO BE REFACTORED INTO SOMETHING DECENT.
|
||||||
|
@ -7090,6 +7090,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
|
|||||||
tab_bar->NextSelectedTabId = id;
|
tab_bar->NextSelectedTabId = id;
|
||||||
|
|
||||||
// Lock visibility
|
// Lock visibility
|
||||||
|
// (Note: tab_contents_visible != tab_selected... because CTRL+TAB operations may preview some tabs without selecting them!)
|
||||||
bool tab_contents_visible = (tab_bar->VisibleTabId == id);
|
bool tab_contents_visible = (tab_bar->VisibleTabId == id);
|
||||||
if (tab_contents_visible)
|
if (tab_contents_visible)
|
||||||
tab_bar->VisibleTabWasSubmitted = true;
|
tab_bar->VisibleTabWasSubmitted = true;
|
||||||
@ -7195,7 +7196,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
|
|||||||
|
|
||||||
// Render tab label, process close button
|
// Render tab label, process close button
|
||||||
const ImGuiID close_button_id = p_open ? window->GetID((void*)((intptr_t)id + 1)) : 0;
|
const ImGuiID close_button_id = p_open ? window->GetID((void*)((intptr_t)id + 1)) : 0;
|
||||||
bool just_closed = TabItemLabelAndCloseButton(display_draw_list, bb, flags, tab_bar->FramePadding, label, id, close_button_id);
|
bool just_closed = TabItemLabelAndCloseButton(display_draw_list, bb, flags, tab_bar->FramePadding, label, id, close_button_id, tab_contents_visible);
|
||||||
if (just_closed && p_open != NULL)
|
if (just_closed && p_open != NULL)
|
||||||
{
|
{
|
||||||
*p_open = false;
|
*p_open = false;
|
||||||
@ -7270,13 +7271,21 @@ void ImGui::TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabI
|
|||||||
|
|
||||||
// Render text label (with custom clipping) + Unsaved Document marker + Close Button logic
|
// Render text label (with custom clipping) + Unsaved Document marker + Close Button logic
|
||||||
// We tend to lock style.FramePadding for a given tab-bar, hence the 'frame_padding' parameter.
|
// We tend to lock style.FramePadding for a given tab-bar, hence the 'frame_padding' parameter.
|
||||||
bool ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImVec2 frame_padding, const char* label, ImGuiID tab_id, ImGuiID close_button_id)
|
bool ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImVec2 frame_padding, const char* label, ImGuiID tab_id, ImGuiID close_button_id, bool is_contents_visible)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImVec2 label_size = CalcTextSize(label, NULL, true);
|
ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||||
if (bb.GetWidth() <= 1.0f)
|
if (bb.GetWidth() <= 1.0f)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// In Style V2 we'll have full override of all colors per state (e.g. focused, selected)
|
||||||
|
// But right now if you want to alter text color of tabs this is what you need to do.
|
||||||
|
#if 0
|
||||||
|
const float backup_alpha = g.Style.Alpha;
|
||||||
|
if (!is_contents_visible)
|
||||||
|
g.Style.Alpha *= 0.7f;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Render text label (with clipping + alpha gradient) + unsaved marker
|
// Render text label (with clipping + alpha gradient) + unsaved marker
|
||||||
const char* TAB_UNSAVED_MARKER = "*";
|
const char* TAB_UNSAVED_MARKER = "*";
|
||||||
ImRect text_pixel_clip_bb(bb.Min.x + frame_padding.x, bb.Min.y + frame_padding.y, bb.Max.x - frame_padding.x, bb.Max.y);
|
ImRect text_pixel_clip_bb(bb.Min.x + frame_padding.x, bb.Min.y + frame_padding.y, bb.Max.x - frame_padding.x, bb.Max.y);
|
||||||
@ -7296,6 +7305,7 @@ bool ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb,
|
|||||||
bool close_button_pressed = false;
|
bool close_button_pressed = false;
|
||||||
bool close_button_visible = false;
|
bool close_button_visible = false;
|
||||||
if (close_button_id != 0)
|
if (close_button_id != 0)
|
||||||
|
if (is_contents_visible || bb.GetWidth() >= g.Style.TabMinWidthForUnselectedCloseButton)
|
||||||
if (g.HoveredId == tab_id || g.HoveredId == close_button_id || g.ActiveId == close_button_id)
|
if (g.HoveredId == tab_id || g.HoveredId == close_button_id || g.ActiveId == close_button_id)
|
||||||
close_button_visible = true;
|
close_button_visible = true;
|
||||||
if (close_button_visible)
|
if (close_button_visible)
|
||||||
@ -7318,6 +7328,11 @@ bool ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb,
|
|||||||
float ellipsis_max_x = close_button_visible ? text_pixel_clip_bb.Max.x : bb.Max.x - 1.0f;
|
float ellipsis_max_x = close_button_visible ? text_pixel_clip_bb.Max.x : bb.Max.x - 1.0f;
|
||||||
RenderTextEllipsis(draw_list, text_ellipsis_clip_bb.Min, text_ellipsis_clip_bb.Max, text_pixel_clip_bb.Max.x, ellipsis_max_x, label, NULL, &label_size);
|
RenderTextEllipsis(draw_list, text_ellipsis_clip_bb.Min, text_ellipsis_clip_bb.Max, text_pixel_clip_bb.Max.x, ellipsis_max_x, label, NULL, &label_size);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (!is_contents_visible)
|
||||||
|
g.Style.Alpha = backup_alpha;
|
||||||
|
#endif
|
||||||
|
|
||||||
return close_button_pressed;
|
return close_button_pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user