From 0972ecb538ab1a85f59b5ec17a34d14c943d09ed Mon Sep 17 00:00:00 2001 From: Patrik Plihal Date: Thu, 18 Apr 2024 21:24:12 +0200 Subject: [PATCH] feature: use avaliable space if first sub is too large by shifting sideways and lifting/lowering --- packages/smartmenus-configurator/src/App.vue | 50 ++++++++++++++++++++ packages/smartmenus/src/js/index.js | 29 +++++++----- 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/packages/smartmenus-configurator/src/App.vue b/packages/smartmenus-configurator/src/App.vue index 89f65a3..d061778 100644 --- a/packages/smartmenus-configurator/src/App.vue +++ b/packages/smartmenus-configurator/src/App.vue @@ -130,6 +130,56 @@ const navbarContentHTML = computed(() => {
  • Disabled
  • +
  • Long-Sub + +
  • Link
  • Link
  • Link diff --git a/packages/smartmenus/src/js/index.js b/packages/smartmenus/src/js/index.js index 8f7c117..468c3cb 100644 --- a/packages/smartmenus/src/js/index.js +++ b/packages/smartmenus/src/js/index.js @@ -980,19 +980,24 @@ class SmartMenus { x = -parentItemX } - if (!horizontalParent) { - if (subHeight < viewportHeight) { - if (parentItemY + y + subHeight > viewportHeight) { - // Align against the opposite edge of the viewport - y = viewportHeight - subHeight - parentItemY - } else if (parentItemY + y < 0) { - // Align against the same edge of the viewport - y = -parentItemY - } - } else { - // If the sub cannot fit inside the viewport, align it against the top edge of the viewport - y = downToUp ? viewportHeight - subHeight - parentItemY : -parentItemY + if (horizontalParent) { + const overHang = subHeight - (viewportHeight - (parentItemY + y)) + if (overHang > 0) { + const liftBy = Math.max(y - overHang, -parentItemY) // at most lift to edge + x = parentItemWidth // align sub to the side + y = liftBy // lift sub + } + } else if (subHeight < viewportHeight) { + if (parentItemY + y + subHeight > viewportHeight) { + // Align against the opposite edge of the viewport + y = viewportHeight - subHeight - parentItemY + } else if (parentItemY + y < 0) { + // Align against the same edge of the viewport + y = -parentItemY } + } else { + // If the sub cannot fit inside the viewport, align it against the top edge of the viewport + y = downToUp ? viewportHeight - subHeight - parentItemY : -parentItemY } }