Dhewm3SettingsMenu: Add button to copy current style to clipboard as C++

This commit is contained in:
Daniel Gibson 2024-05-25 18:16:00 +02:00
parent 99b65a3edf
commit 894aa67a8f
3 changed files with 18 additions and 0 deletions

View file

@ -1602,6 +1602,11 @@ static void DrawOtherOptionsMenu()
} }
AddTooltip( "Writes the current style settings (incl. colors) as userstyle" ); AddTooltip( "Writes the current style settings (incl. colors) as userstyle" );
if ( ImGui::Button( "Copy style code to clipboard" ) ) {
D3::ImGuiHooks::CopyCurrentStyle();
}
AddTooltip( "Generates C++ code for the current style settings (incl. colors) and copies it into the clipboard" );
ImGui::Spacing(); ImGui::Spacing();
if ( ImGui::Button( "Show ImGui Demo" ) ) { if ( ImGui::Button( "Show ImGui Demo" ) ) {

View file

@ -39,6 +39,10 @@ namespace DG {
// style to a sane default before calling that function. // style to a sane default before calling that function.
// returns true on success, false if opening the file failed // returns true on success, false if opening the file failed
extern bool ReadImGuiStyle( ImGuiStyle& style, const char* filename ); extern bool ReadImGuiStyle( ImGuiStyle& style, const char* filename );
// generate C++ code that replicates the given style into a text buffer
// (that you can either write to a file or set the clipboard from or whatever)
extern ImGuiTextBuffer WriteImGuiStyleToCode( const ImGuiStyle& s );
} //namespace DG } //namespace DG
namespace D3 { namespace D3 {
@ -522,4 +526,10 @@ bool WriteUserStyle()
return true; return true;
} }
void CopyCurrentStyle()
{
ImGuiTextBuffer buf = DG::WriteImGuiStyleToCode( ImGui::GetStyle() );
Sys_SetClipboardData( buf.c_str() );
}
}} //namespace D3::ImGuiHooks }} //namespace D3::ImGuiHooks

View file

@ -77,6 +77,9 @@ extern void SetUserStyleColors();
// write current style settings (incl. colors) as userStyle // write current style settings (incl. colors) as userStyle
extern bool WriteUserStyle(); extern bool WriteUserStyle();
// copy current style to clipboard
extern void CopyCurrentStyle();
#else // IMGUI_DISABLE - just stub out everything #else // IMGUI_DISABLE - just stub out everything
inline bool IsImguiEnabled() inline bool IsImguiEnabled()