1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-01 21:52:12 +01:00

Make Custom menus scrollable

Fixes #11416

The patch on MenuScroller.java is needed to avoid a clash between custom menus with the same label.
This behaviour artificially increases the amount of objects that the scroller will calculate.
Eg. if two boards share the same custom menu, that menu will contain the properties for both the boards (since it's parsed twice).
This commit is contained in:
Martino Facchin 2021-04-12 13:02:08 +02:00
parent 57a931c9c4
commit 6c3c1c09b1
2 changed files with 3 additions and 1 deletions

View File

@ -1473,6 +1473,7 @@ public class Base {
customMenu.putClientProperty("platform", getPlatformUniqueId(targetPlatform)); customMenu.putClientProperty("platform", getPlatformUniqueId(targetPlatform));
customMenu.putClientProperty("removeOnWindowDeactivation", true); customMenu.putClientProperty("removeOnWindowDeactivation", true);
boardsCustomMenus.add(customMenu); boardsCustomMenus.add(customMenu);
MenuScroller.setScrollerFor(customMenu);
} }
} }
} }

View File

@ -16,6 +16,7 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener; import java.awt.event.MouseWheelListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.Arrays;
/** /**
* A class that provides scrolling capabilities to a long menu dropdown or * A class that provides scrolling capabilities to a long menu dropdown or
@ -539,7 +540,7 @@ public class MenuScroller {
} }
private void setMenuItems() { private void setMenuItems() {
menuItems = menu.getComponents(); menuItems = Arrays.stream(menu.getComponents()).filter(x -> x.isVisible()).toArray(Component[]::new);
if (keepVisibleIndex >= topFixedCount if (keepVisibleIndex >= topFixedCount
&& keepVisibleIndex <= menuItems.length - bottomFixedCount && keepVisibleIndex <= menuItems.length - bottomFixedCount
&& (keepVisibleIndex > firstIndex + scrollCount && (keepVisibleIndex > firstIndex + scrollCount