@@ -366,6 +366,10 @@ function addon:generate_keyboard_key_frames()
366366 local cx , cy = addon .keyboard_frame :GetCenter ()
367367 local left , right , top , bottom = cx , cx , cy , cy
368368
369+ -- Variables to track the maximum width and height
370+ local max_width = 0
371+ local max_height = 0
372+
369373 -- Loop through each key in the layout and position it within the frame.
370374 for _ , layout_data in pairs (keyui_settings .layout_current_keyboard ) do
371375 for i = 1 , # layout_data do
@@ -402,7 +406,7 @@ function addon:generate_keyboard_key_frames()
402406
403407 -- Position the key within the frame.
404408 button :SetPoint (" TOPLEFT" , addon .keyboard_frame , " TOPLEFT" , button_data [2 ], button_data [3 ])
405- button .raw_key = button_data [1 ]
409+ button .raw_key = button_data [1 ]
406410 button .is_modifier = modifier_keys [button .raw_key ] or false
407411 button :Show ()
408412
@@ -412,20 +416,29 @@ function addon:generate_keyboard_key_frames()
412416 if r > right then right = r end
413417 if t > top then top = t end
414418 if b < bottom then bottom = b end
419+
420+ -- Update the max width and height based on button position and size
421+ if button_data [2 ] + button_data [4 ] > max_width then
422+ max_width = button_data [2 ] + button_data [4 ]
423+ end
424+ if button_data [3 ] - button_data [5 ] < max_height then
425+ max_height = button_data [3 ] - button_data [5 ]
426+ end
415427 end
416428 end
417429
418- -- Adjust the frame size based on the extreme positions of the keys.
419- addon .keyboard_frame :SetWidth (right - left + 12 )
420- addon .keyboard_frame :SetHeight (top - bottom + 12 )
430+ -- Adjust the frame size based on the maximum width and height.
431+ -- Handle negative Y-values correctly by ensuring proper expansion of the frame
432+ addon .keyboard_frame :SetWidth (max_width + 6 )
433+ addon .keyboard_frame :SetHeight (max_height - 6 )
421434
422- addon .keyboard_frame .edit_frame :SetSize ( addon .keyboard_frame :GetWidth (), addon .keyboard_frame :GetHeight ())
435+ addon .keyboard_frame .edit_frame :SetSize (addon .keyboard_frame :GetWidth (), addon .keyboard_frame :GetHeight ())
423436 else
424437 -- Set a fallback size if the layout is empty.
425438 addon .keyboard_frame :SetWidth (940 )
426439 addon .keyboard_frame :SetHeight (382 )
427440
428- addon .keyboard_frame .edit_frame :SetSize ( addon .keyboard_frame :GetWidth (), addon .keyboard_frame :GetHeight ())
441+ addon .keyboard_frame .edit_frame :SetSize (addon .keyboard_frame :GetWidth (), addon .keyboard_frame :GetHeight ())
429442 end
430443 end
431444end
0 commit comments