@@ -6,7 +6,7 @@ namespace Tetragrama::Helpers {
66
77 void DrawVec4Control (
88 std::string_view label, ZEngine::Maths::Vector4& values, const std::function<void (ZEngine::Maths::Vector4&)>& callback, float default_value, float column_width) {
9- ImGui::PushID (label.data ());
9+ ImGui::PushID (label.data (), (label. data () + label. size ()) );
1010
1111 ImGui::Columns (2 );
1212
@@ -108,7 +108,7 @@ namespace Tetragrama::Helpers {
108108
109109 void DrawVec3Control (
110110 std::string_view label, ZEngine::Maths::Vector3& values, const std::function<void (ZEngine::Maths::Vector3&)>& callback, float default_value, float column_width) {
111- ImGui::PushID (label.data ());
111+ ImGui::PushID (label.data (), (label. data () + label. size ()) );
112112
113113 ImGui::Columns (2 );
114114
@@ -192,7 +192,7 @@ namespace Tetragrama::Helpers {
192192
193193 void DrawVec2Control (
194194 std::string_view label, ZEngine::Maths::Vector2& values, const std::function<void (ZEngine::Maths::Vector2&)>& callback, float default_value, float column_width) {
195- ImGui::PushID (label.data ());
195+ ImGui::PushID (label.data (), (label. data () + label. size ()) );
196196
197197 ImGui::Columns (2 );
198198
@@ -252,7 +252,7 @@ namespace Tetragrama::Helpers {
252252
253253
254254 void DrawInputTextControl (std::string_view label, std::string_view content, const std::function<void (std::string_view)>& callback, bool read_only_mode, float column_width) {
255- ImGui::PushID (label.data ());
255+ ImGui::PushID (label.data (), (label. data () + label. size ()) );
256256 ImGui::Columns (2 );
257257
258258 ImGui::SetColumnWidth (0 , column_width);
@@ -262,9 +262,6 @@ namespace Tetragrama::Helpers {
262262 ImGui::PushMultiItemsWidths (1 , ImGui::CalcItemWidth () + 60 .f );
263263 ImGui::PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2{0 .5f , 0 });
264264
265- float line_height = GImGui->Font ->FontSize + GImGui->Style .FramePadding .y * 2 .0f ;
266- ImVec2 input_control_size = {line_height + 3 .0f , line_height};
267-
268265 char buffer[1024 ];
269266 memset (buffer, 0 , sizeof (buffer));
270267 auto raw_entity_name = content.data ();
@@ -288,7 +285,7 @@ namespace Tetragrama::Helpers {
288285
289286 void DrawDragFloatControl (std::string_view label, float value, float increment_speed, float min_value, float max_value, std::string_view fmt,
290287 const std::function<void (float )>& callback, float column_width) {
291- ImGui::PushID (label.data ());
288+ ImGui::PushID (label.data (), (label. data () + label. size ()) );
292289 ImGui::Columns (2 );
293290
294291 ImGui::SetColumnWidth (0 , column_width);
@@ -298,9 +295,6 @@ namespace Tetragrama::Helpers {
298295 ImGui::PushMultiItemsWidths (1 , ImGui::CalcItemWidth () + 60 .f );
299296 ImGui::PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2{0 .5f , 0 });
300297
301- float line_height = GImGui->Font ->FontSize + GImGui->Style .FramePadding .y * 2 .0f ;
302- ImVec2 input_control_size = {line_height + 3 .0f , line_height};
303-
304298 if (ImGui::DragFloat (" ##DragFloat" , &value, increment_speed, min_value, max_value, fmt.data ())) {
305299 if (callback) {
306300 callback (value);
@@ -314,7 +308,7 @@ namespace Tetragrama::Helpers {
314308
315309 void DrawCenteredButtonControl (std::string_view label, const std::function<void (void )>& callback) {
316310
317- ImGui::PushID (label.data ());
311+ ImGui::PushID (label.data (), (label. data () + label. size ()) );
318312
319313 ImGui::BeginTable (" ##table" , 3 );
320314
@@ -335,4 +329,72 @@ namespace Tetragrama::Helpers {
335329 ImGui::EndTable ();
336330 ImGui::PopID ();
337331 }
332+
333+ void DrawColorEdit4Control (
334+ std::string_view label, ZEngine::Maths::Vector4& values, const std::function<void (ZEngine::Maths::Vector4&)>& callback, float default_value, float column_width) {
335+ ImGui::PushID (label.data (), (label.data () + label.size ()));
336+
337+ ImGui::Columns (2 );
338+
339+ ImGui::SetColumnWidth (0 , column_width);
340+ ImGui::Text (label.data ());
341+ ImGui::NextColumn ();
342+
343+ ImGui::PushMultiItemsWidths (1 , ImGui::CalcItemWidth () + 60 .f );
344+ ImGui::PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2{0 .5f , 0 });
345+
346+ if (ImGui::ColorEdit4 (" ##TintColor" , ZEngine::Maths::value_ptr (values))) {
347+ if (callback) {
348+ callback (values);
349+ }
350+ }
351+
352+ ImGui::PopItemWidth ();
353+ ImGui::PopStyleVar ();
354+ ImGui::Columns (1 );
355+ ImGui::PopID ();
356+ }
357+
358+ void DrawTextureColorControl (std::string_view label, ImTextureID texture_id, ZEngine::Maths::Vector4& tint_color, bool enable_zoom,
359+ const std::function<void (void )>& image_click_callback, const std::function<void(ZEngine::Maths::Vector4&)>& tint_color_change_callback, float column_width) {
360+ ImGui::PushID (label.data (), (label.data () + label.size ()));
361+ ImGui::Columns (2 );
362+
363+ ImGui::SetColumnWidth (0 , column_width);
364+ ImGui::Text (label.data ());
365+ ImGui::NextColumn ();
366+
367+ ImGui::PushMultiItemsWidths (1 , ImGui::CalcItemWidth () + 60 .f );
368+ ImGui::PushStyleVar (ImGuiStyleVar_ItemSpacing, ImVec2{0 .5f , 0 });
369+
370+ float line_height = GImGui->Font ->FontSize + GImGui->Style .FramePadding .y * 2 .0f ;
371+ ImVec2 button_size = {line_height + 3 .0f , line_height};
372+
373+ if (ImGui::ImageButton (texture_id, button_size, ImVec2 (0 , 0 ), ImVec2 (1 , 1 ), 1 , ImVec4 (0 , 0 , 0 , 0 ), ImVec4{tint_color.x , tint_color.y , tint_color.z , tint_color.w })) {
374+ if (image_click_callback) {
375+ image_click_callback ();
376+ }
377+ }
378+ if (enable_zoom) {
379+ if (ImGui::IsItemHovered ()) {
380+ ImGui::BeginTooltip ();
381+ ImGui::Image (texture_id, ImVec2 (200 , 200 ), {0 , 0 }, {1 , 1 }, ImVec4{tint_color.x , tint_color.y , tint_color.z , tint_color.w });
382+ ImGui::EndTooltip ();
383+ }
384+ }
385+ ImGui::PopItemWidth ();
386+
387+ ImGui::SameLine ();
388+ ImGui::PushStyleVar (ImGuiStyleVar_FramePadding, ImVec2 (1 , 4 ));
389+ if (ImGui::ColorEdit4 (" ##TintColor" , ZEngine::Maths::value_ptr (tint_color))) {
390+ if (tint_color_change_callback) {
391+ tint_color_change_callback (tint_color);
392+ }
393+ }
394+ ImGui::PopItemWidth ();
395+
396+ ImGui::PopStyleVar (2 );
397+ ImGui::Columns (1 );
398+ ImGui::PopID ();
399+ }
338400} // namespace Tetragrama::Helpers
0 commit comments