mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-01 21:52:12 +01:00
Merge pull request #11425 from facchinm/scrollable_custommenus
Make Custom menus scrollable
This commit is contained in:
commit
488f0d7ab2
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
@ -33,6 +34,7 @@ public class MenuScroller {
|
|||||||
|
|
||||||
private JPopupMenu menu;
|
private JPopupMenu menu;
|
||||||
private Component[] menuItems;
|
private Component[] menuItems;
|
||||||
|
private Component[] allMenuItems;
|
||||||
private MenuScrollItem upItem;
|
private MenuScrollItem upItem;
|
||||||
private MenuScrollItem downItem;
|
private MenuScrollItem downItem;
|
||||||
private final MenuScrollListener menuListener = new MenuScrollListener();
|
private final MenuScrollListener menuListener = new MenuScrollListener();
|
||||||
@ -539,7 +541,8 @@ public class MenuScroller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setMenuItems() {
|
private void setMenuItems() {
|
||||||
menuItems = menu.getComponents();
|
allMenuItems = menu.getComponents();
|
||||||
|
menuItems = Arrays.stream(allMenuItems).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
|
||||||
@ -554,7 +557,7 @@ public class MenuScroller {
|
|||||||
|
|
||||||
private void restoreMenuItems() {
|
private void restoreMenuItems() {
|
||||||
menu.removeAll();
|
menu.removeAll();
|
||||||
for (Component component : menuItems) {
|
for (Component component : allMenuItems) {
|
||||||
menu.add(component);
|
menu.add(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user