@@ -181,12 +181,11 @@ void init()
181
181
textureR->update ( data );
182
182
}
183
183
184
- bool buttonEx ( const char * label, bool active, const Vector2f& size_arg /* = Vector2f( 0, 0 )*/ ,
185
- ImGuiButtonFlags flags /* = ImGuiButtonFlags_None*/ , const ButtonCustomizationParams& custmParams )
184
+ bool buttonEx ( const char * label, const Vector2f& size_arg /* = Vector2f( 0, 0 )*/ , const ButtonCustomizationParams& customParams )
186
185
{
187
- bool simulateClick = custmParams .enableTestEngine && TestEngine::createButton ( label );
188
- assert ( ( simulateClick <= active ) && " Trying to programmatically press a button, but it's inactive!" );
189
- if ( !active )
186
+ bool simulateClick = customParams .enableTestEngine && TestEngine::createButton ( label );
187
+ assert ( ( simulateClick <= customParams. enabled ) && " Trying to programmatically press a button, but it's inactive!" );
188
+ if ( !customParams. enabled )
190
189
simulateClick = false ;
191
190
192
191
// copy from ImGui::ButtonEx and replaced visualize part
@@ -199,6 +198,8 @@ bool buttonEx( const char* label, bool active, const Vector2f& size_arg /*= Vect
199
198
const ImGuiID id = window->GetID ( label );
200
199
const ImVec2 label_size = ImGui::CalcTextSize ( label, NULL , true );
201
200
201
+ auto flags = customParams.flags ;
202
+
202
203
ImVec2 pos = window->DC .CursorPos ;
203
204
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)
204
205
pos.y += window->DC .CurrLineTextBaseOffset - style.FramePadding .y ;
@@ -220,38 +221,46 @@ bool buttonEx( const char* label, bool active, const Vector2f& size_arg /*= Vect
220
221
221
222
// replaced part
222
223
// potential fail. need check that customTexture is good
223
- auto texture = ( custmParams .customTexture || custmParams .forceImGuiBackground ) ? custmParams .customTexture : getTexture ( TextureType::GradientBtn ).get ();
224
+ auto texture = ( customParams .customTexture || customParams .forceImGuiBackground ) ? customParams .customTexture : getTexture ( TextureType::GradientBtn ).get ();
224
225
if ( texture )
225
226
{
226
- const float textureU = 0 .125f + ( !active ? 0 .75f : ( held && hovered ) ? 0 .5f : hovered ? 0 .25f : 0 .f );
227
+ const float textureU = 0 .125f + ( !customParams. enabled ? 0 .75f : ( held && hovered ) ? 0 .5f : hovered ? 0 .25f : 0 .f );
227
228
window->DrawList ->AddImageRounded (
228
229
texture->getImTextureId (),
229
230
bb.Min , bb.Max ,
230
231
ImVec2 ( textureU, 0 .25f ), ImVec2 ( textureU, 0 .75f ),
231
232
Color::white ().getUInt32 (), style.FrameRounding );
232
- if ( custmParams .border )
233
+ if ( customParams .border )
233
234
ImGui::RenderFrameBorder ( bb.Min , bb.Max , style.FrameRounding );
234
235
}
235
236
else
236
237
{
237
- const ImGuiCol colIdx = ( !active ? ImGuiCol_TextDisabled : ( held && hovered ) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button );
238
+ const ImGuiCol colIdx = ( !customParams. enabled ? ImGuiCol_TextDisabled : ( held && hovered ) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button );
238
239
const ImU32 col = ImGui::GetColorU32 ( colIdx );
239
240
ImGui::RenderFrame ( bb.Min , bb.Max , col, true , style.FrameRounding );
240
241
}
241
242
242
243
if ( g.LogEnabled )
243
244
ImGui::LogSetNextTextDecoration ( " [" , " ]" );
244
245
StyleParamHolder sh;
245
- if ( !custmParams .forceImguiTextColor )
246
+ if ( !customParams .forceImguiTextColor )
246
247
sh.addColor ( ImGuiCol_Text, ColorTheme::getRibbonColor ( ColorTheme::RibbonColorsType::GradBtnText ) );
247
248
ImGui::RenderTextClipped ( bb.Min , bb.Max , label, NULL , &label_size, style.ButtonTextAlign , &bb );
248
249
249
- if ( custmParams .underlineFirstLetter )
250
+ if ( customParams .underlineFirstLetter )
250
251
ImGui::RenderTextClipped ( bb.Min , bb.Max , " _" , NULL , &label_size, style.ButtonTextAlign , &bb);
251
252
252
253
IMGUI_TEST_ENGINE_ITEM_INFO ( id, label, g.LastItemData .StatusFlags );
253
254
254
- return ( pressed || simulateClick ) && active;
255
+ return ( pressed || simulateClick ) && customParams.enabled ;
256
+ }
257
+
258
+ bool buttonEx ( const char * label, bool active, const Vector2f& size /* = Vector2f( 0, 0 )*/ , ImGuiButtonFlags flags /* = ImGuiButtonFlags_None*/ , const ButtonCustomizationParams& customParams /* = {} */ )
259
+ {
260
+ auto paramscpy = customParams;
261
+ paramscpy.enabled = active;
262
+ paramscpy.flags = flags;
263
+ return buttonEx ( label, size, paramscpy );
255
264
}
256
265
257
266
bool button ( const char * label, bool active, const Vector2f& size /* = Vector2f( 0, 0 )*/ , ImGuiKey key /* = ImGuiKey_None */ )
@@ -263,13 +272,13 @@ bool button( const char* label, bool active, const Vector2f& size /*= Vector2f(
263
272
sh.addVar ( ImGuiStyleVar_FramePadding, ImVec2 ( style.FramePadding .x , cGradientButtonFramePadding * scaling ) );
264
273
265
274
bool sameKey = std::string_view ( ImGui::GetKeyName ( key ) ) == std::string_view ( label, 1 );
266
- return buttonEx ( label, active, size, 0 , { .underlineFirstLetter = sameKey } ) || ( active && checkKey ( key ) );
275
+ return buttonEx ( label, size, { . enabled = active, .underlineFirstLetter = sameKey } ) || ( active && checkKey ( key ) );
267
276
}
268
277
269
278
bool buttonCommonSize ( const char * label, const Vector2f& size /* = Vector2f( 0, 0 )*/ , ImGuiKey key /* = ImGuiKey_None */ )
270
279
{
271
280
bool sameKey = std::string_view ( ImGui::GetKeyName ( key ) ) == std::string_view ( label, 1 );
272
- return buttonEx ( label, true , size, 0 , { .underlineFirstLetter = sameKey } ) || checkKey ( key );
281
+ return buttonEx ( label, size, { .underlineFirstLetter = sameKey } ) || checkKey ( key );
273
282
}
274
283
275
284
bool buttonUnique ( const char * label, int * value, int ownValue, const Vector2f& size /* = Vector2f( 0, 0 )*/ , ImGuiKey key /* = ImGuiKey_None*/ )
@@ -293,7 +302,7 @@ bool buttonUnique( const char* label, int* value, int ownValue, const Vector2f&
293
302
params.forceImguiTextColor = true ;
294
303
params.underlineFirstLetter = std::string_view ( ImGui::GetKeyName ( key ) ) == std::string_view ( label, 1 );
295
304
296
- auto res = buttonEx ( label, true , ImVec2 ( size.x , size.y ), 0 , params ) || checkKey ( key );
305
+ auto res = buttonEx ( label, ImVec2 ( size.x , size.y ), params ) || checkKey ( key );
297
306
if ( res )
298
307
value[0 ] = ownValue;
299
308
@@ -420,12 +429,12 @@ bool buttonIconEx(
420
429
if ( params.flatBackgroundColor )
421
430
{
422
431
res = ImGui::Button ( buttonText.c_str (), buttonSize );
423
- if ( params.enableTestEngine )
432
+ if ( params.baseParams . enableTestEngine )
424
433
res = UI::TestEngine::createButton ( buttonText ) || res;
425
434
}
426
435
else
427
436
{
428
- res = UI::buttonEx ( buttonText.c_str (), params. active , Vector2f ( buttonSize.x , buttonSize.y ), params.flags , params );
437
+ res = UI::buttonEx ( buttonText.c_str (), Vector2f ( buttonSize.x , buttonSize.y ), params.baseParams );
429
438
}
430
439
ImGui::SameLine ();
431
440
@@ -539,7 +548,7 @@ bool buttonIconEx(
539
548
auto icon = RibbonIcons::findByName ( name, maxSize, RibbonIcons::ColorType::White, RibbonIcons::IconType::IndependentIcons );
540
549
541
550
StyleParamHolder sh;
542
- if ( !params.forceImguiTextColor )
551
+ if ( !params.baseParams . forceImguiTextColor )
543
552
sh.addColor ( ImGuiCol_Text, ColorTheme::getRibbonColor ( ColorTheme::RibbonColorsType::GradBtnText ) );
544
553
545
554
ImVec4 multColor = ImGui::GetStyleColorVec4 ( ImGuiCol_Text );
@@ -570,7 +579,7 @@ bool buttonIconEx(
570
579
color,
571
580
detail.start ,
572
581
detail.end );
573
- if ( numStr == 0 && params.underlineFirstLetter )
582
+ if ( numStr == 0 && params.baseParams . underlineFirstLetter )
574
583
ImGui::GetWindowDrawList ()->AddText ( font, cFontSize, screenPos, color, " _" );
575
584
576
585
numStr++;
0 commit comments