2021-01-26 23:00:20 +00:00
# include <imgui_imhex_extensions.h>
# include <imgui.h>
2021-01-27 11:04:42 +00:00
# include <imgui_freetype.h>
2021-01-26 23:00:20 +00:00
# define IMGUI_DEFINE_MATH_OPERATORS
# include <imgui_internal.h>
# undef IMGUI_DEFINE_MATH_OPERATORS
2021-01-27 11:04:42 +00:00
# include <string>
2021-01-26 23:00:20 +00:00
namespace ImGui {
2021-01-27 11:04:42 +00:00
bool Hyperlink ( const char * label , const ImVec2 & size_arg , ImGuiButtonFlags flags ) {
2021-01-26 23:00:20 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
ImGuiContext & g = * GImGui ;
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
const ImVec2 label_size = CalcTextSize ( label , NULL , true ) ;
ImVec2 pos = window - > DC . CursorPos ;
ImVec2 size = CalcItemSize ( size_arg , label_size . x , label_size . y ) ;
const ImRect bb ( pos , pos + size ) ;
if ( ! ItemAdd ( bb , id ) )
return false ;
if ( window - > DC . ItemFlags & ImGuiItemFlags_ButtonRepeat )
flags | = ImGuiButtonFlags_Repeat ;
bool hovered , held ;
bool pressed = ButtonBehavior ( bb , id , & hovered , & held , flags ) ;
// Render
2021-01-27 11:04:42 +00:00
const ImU32 col = hovered ? GetColorU32 ( ImGuiCol_ButtonHovered ) : GetColorU32 ( ImGuiCol_ButtonActive ) ;
2021-01-26 23:00:20 +00:00
PushStyleColor ( ImGuiCol_Text , ImU32 ( col ) ) ;
TextEx ( label , NULL , ImGuiTextFlags_NoWidthForLargeClippedText ) ; // Skip formatting
2021-01-27 13:26:24 +00:00
GetWindowDrawList ( ) - > AddLine ( ImVec2 ( pos . x , pos . y + size . y ) , pos + size , ImU32 ( col ) ) ;
2021-01-26 23:00:20 +00:00
PopStyleColor ( ) ;
IMGUI_TEST_ENGINE_ITEM_INFO ( id , label , window - > DC . LastItemStatusFlags ) ;
return pressed ;
}
2021-01-27 11:04:42 +00:00
bool BulletHyperlink ( const char * label , const ImVec2 & size_arg , ImGuiButtonFlags flags ) {
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
ImGuiContext & g = * GImGui ;
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
const ImVec2 label_size = CalcTextSize ( label , NULL , true ) ;
ImVec2 pos = window - > DC . CursorPos ;
2021-01-30 22:02:03 +00:00
ImVec2 size = CalcItemSize ( size_arg , label_size . x , label_size . y ) + ImVec2 ( g . FontSize + style . FramePadding . x * 2 , 0.0f ) ;
2021-01-27 11:04:42 +00:00
const ImRect bb ( pos , pos + size ) ;
if ( ! ItemAdd ( bb , id ) )
return false ;
if ( window - > DC . ItemFlags & ImGuiItemFlags_ButtonRepeat )
flags | = ImGuiButtonFlags_Repeat ;
bool hovered , held ;
bool pressed = ButtonBehavior ( bb , id , & hovered , & held , flags ) ;
// Render
const ImU32 col = hovered ? GetColorU32 ( ImGuiCol_ButtonHovered ) : GetColorU32 ( ImGuiCol_ButtonActive ) ;
PushStyleColor ( ImGuiCol_Text , ImU32 ( col ) ) ;
RenderBullet ( window - > DrawList , bb . Min + ImVec2 ( style . FramePadding . x + g . FontSize * 0.5f , g . FontSize * 0.5f ) , col ) ;
RenderText ( bb . Min + ImVec2 ( g . FontSize + style . FramePadding . x * 2 , 0.0f ) , label , nullptr , false ) ;
2021-01-30 22:02:03 +00:00
GetWindowDrawList ( ) - > AddLine ( bb . Min + ImVec2 ( style . FramePadding . x , size . y ) , pos + size , ImU32 ( col ) ) ;
2021-01-27 11:04:42 +00:00
ImGui : : NewLine ( ) ;
PopStyleColor ( ) ;
IMGUI_TEST_ENGINE_ITEM_INFO ( id , label , window - > DC . LastItemStatusFlags ) ;
return pressed ;
}
bool DescriptionButton ( const char * label , const char * description , const ImVec2 & size_arg , ImGuiButtonFlags flags ) {
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
ImGuiContext & g = * GImGui ;
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
const ImVec2 text_size = CalcTextSize ( ( std : : string ( label ) + " \n " + std : : string ( description ) ) . c_str ( ) , NULL , true ) ;
const ImVec2 label_size = CalcTextSize ( label , NULL , true ) ;
ImVec2 pos = window - > DC . CursorPos ;
if ( ( flags & ImGuiButtonFlags_AlignTextBaseLine ) & & style . FramePadding . y < window - > DC . CurrLineTextBaseOffset ) // Try to vertically align buttons that are smaller/have no padding so that text baseline matches (bit hacky, since it shouldn't be a flag)
pos . y + = window - > DC . CurrLineTextBaseOffset - style . FramePadding . y ;
ImVec2 size = CalcItemSize ( size_arg , text_size . x + style . FramePadding . x * 4.0f , text_size . y + style . FramePadding . y * 4.0f ) ;
const ImRect bb ( pos , pos + size ) ;
ItemSize ( size , style . FramePadding . y ) ;
if ( ! ItemAdd ( bb , id ) )
return false ;
if ( window - > DC . ItemFlags & ImGuiItemFlags_ButtonRepeat )
flags | = ImGuiButtonFlags_Repeat ;
bool hovered , held ;
bool pressed = ButtonBehavior ( bb , id , & hovered , & held , flags ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_ButtonTextAlign , ImVec2 ( 0.0 , 0.5 ) ) ;
// Render
2021-02-18 11:09:19 +00:00
const ImU32 col = GetColorU32 ( ( held & & hovered ) ? ImGuiCol_TableHeaderBg : hovered ? ImGuiCol_TableBorderLight : ImGuiCol_TableBorderStrong ) ;
2021-01-27 11:04:42 +00:00
RenderNavHighlight ( bb , id ) ;
RenderFrame ( bb . Min , bb . Max , col , true , style . FrameRounding ) ;
PushStyleColor ( ImGuiCol_Text , GetColorU32 ( ImGuiCol_ButtonActive ) ) ;
RenderTextClipped ( bb . Min + style . FramePadding * 2 , bb . Max - style . FramePadding * 2 , label , NULL , & text_size , style . ButtonTextAlign , & bb ) ;
PopStyleColor ( ) ;
PushStyleColor ( ImGuiCol_Text , GetColorU32 ( ImGuiCol_Text ) ) ;
RenderTextClipped ( bb . Min + style . FramePadding * 2 + ImVec2 ( style . FramePadding . x * 2 , label_size . y ) , bb . Max - style . FramePadding , description , NULL , & text_size , style . ButtonTextAlign , & bb ) ;
PopStyleColor ( ) ;
ImGui : : PopStyleVar ( ) ;
// Automatically close popups
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
// CloseCurrentPopup();
IMGUI_TEST_ENGINE_ITEM_INFO ( id , label , window - > DC . LastItemStatusFlags ) ;
return pressed ;
}
void UnderlinedText ( const char * label , ImColor color , const ImVec2 & size_arg ) {
ImGuiWindow * window = GetCurrentWindow ( ) ;
const ImVec2 label_size = CalcTextSize ( label , NULL , true ) ;
ImVec2 pos = window - > DC . CursorPos ;
ImVec2 size = CalcItemSize ( size_arg , label_size . x , label_size . y ) ;
PushStyleColor ( ImGuiCol_Text , ImU32 ( color ) ) ;
TextEx ( label , NULL , ImGuiTextFlags_NoWidthForLargeClippedText ) ; // Skip formatting
2021-01-27 13:26:24 +00:00
GetWindowDrawList ( ) - > AddLine ( ImVec2 ( pos . x , pos . y + size . y ) , pos + size , ImU32 ( color ) ) ;
2021-01-27 11:04:42 +00:00
PopStyleColor ( ) ;
}
2021-02-20 21:38:31 +00:00
void Disabled ( std : : function < void ( ) > widgets , bool disabled ) {
if ( disabled ) {
ImGui : : PushItemFlag ( ImGuiItemFlags_Disabled , true ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_Alpha , ImGui : : GetStyle ( ) . Alpha * 0.5F ) ;
widgets ( ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : PopItemFlag ( ) ;
} else {
widgets ( ) ;
}
}
2021-01-26 23:00:20 +00:00
}