Skip to content

Commit

Permalink
Merge pull request #11425 from facchinm/scrollable_custommenus
Browse files Browse the repository at this point in the history
Make Custom menus scrollable
  • Loading branch information
cmaglie authored Apr 30, 2021
2 parents 57a931c + cb1b845 commit 488f0d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,7 @@ public void actionPerformed(ActionEvent actionevent) {
customMenu.putClientProperty("platform", getPlatformUniqueId(targetPlatform));
customMenu.putClientProperty("removeOnWindowDeactivation", true);
boardsCustomMenus.add(customMenu);
MenuScroller.setScrollerFor(customMenu);
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/processing/app/tools/MenuScroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.KeyEvent;
import java.util.Arrays;

/**
* A class that provides scrolling capabilities to a long menu dropdown or
Expand All @@ -33,6 +34,7 @@ public class MenuScroller {

private JPopupMenu menu;
private Component[] menuItems;
private Component[] allMenuItems;
private MenuScrollItem upItem;
private MenuScrollItem downItem;
private final MenuScrollListener menuListener = new MenuScrollListener();
Expand Down Expand Up @@ -539,7 +541,8 @@ public void popupMenuCanceled(PopupMenuEvent e) {
}

private void setMenuItems() {
menuItems = menu.getComponents();
allMenuItems = menu.getComponents();
menuItems = Arrays.stream(allMenuItems).filter(x -> x.isVisible()).toArray(Component[]::new);
if (keepVisibleIndex >= topFixedCount
&& keepVisibleIndex <= menuItems.length - bottomFixedCount
&& (keepVisibleIndex > firstIndex + scrollCount
Expand All @@ -554,7 +557,7 @@ private void setMenuItems() {

private void restoreMenuItems() {
menu.removeAll();
for (Component component : menuItems) {
for (Component component : allMenuItems) {
menu.add(component);
}
}
Expand Down

0 comments on commit 488f0d7

Please sign in to comment.