Skip to content

Commit

Permalink
PopUpMenu fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZILtoid1991 committed May 25, 2024
1 parent a0f28b9 commit b0b522b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
4 changes: 4 additions & 0 deletions docs/changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.11.0-alpha.5

Fixed a bug related to submenus in popup menus, also a bug related to missing `onDraw` calls.

# 0.11.0-alpha.4

Fixed a critical bug regarding of the insert and edit function of ListView.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ public class PopUpMenu : PopUpElement {
}
if (num >= elements.length) return;
if (elements[num].source == "\\submenu\\") {
PopUpMenu m = new PopUpMenu(elements[mce.y].subElements, this.source, onMenuSelect);
PopUpMenu m = new PopUpMenu(elements[num].subElements, this.source, onMenuSelect);
m.onMouseClick = onMouseClick;
//parent.getAbsolutePosition()
parent.addPopUpElement(m, position.left + width, position.top + vPos - text.getHeight);
parent.addPopUpElement(m, position.left + width, position.top + vPos - elements[num].text.getHeight);
//parent.closePopUp(this);
} else if (elements[num].text !is null) {
//invokeActionEvent(new Event(elements[offsetY].source, source, null, null, null, offsetY, EventType.CLICK));
Expand Down
23 changes: 4 additions & 19 deletions pixelperfectengine/src/pixelperfectengine/concrete/windowhandler.d
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,16 @@ public class WindowHandler : InputListener, MouseListener, PopUpHandler {
for ( ; numOfPopUpElements < 0 ; numOfPopUpElements++){
spriteLayer.removeSprite(numOfPopUpElements);
}
/+foreach (key ; popUpElements) {
key.destroy;
}+/
///Why didn't I add a method to clear linked lists? (slams head into wall)
popUpElements = PopUpSet(new PopUpElement[](0));
/+while (popUpElements.length) {
popUpElements.remove(0);
}+/
if (PopUpElement.onDraw !is null) PopUpElement.onDraw();
}
/**
* Removes the pop-up element with the highest priority.
*/
private void removeTopPopUp(){

spriteLayer.removeSprite(numOfPopUpElements++);

popUpElements.remove(popUpElements.length - 1);
if (PopUpElement.onDraw !is null) PopUpElement.onDraw();
}
/**
* Returns the default stylesheet (popup).
Expand All @@ -375,23 +368,15 @@ public class WindowHandler : InputListener, MouseListener, PopUpHandler {
*/
public void endPopUpSession(PopUpElement p){
removeAllPopUps();
if (PopUpElement.onDraw !is null) PopUpElement.onDraw();
}
/**
* Removes the given popup element.
*/
public void closePopUp(PopUpElement p){
popUpElements.removeByElem(p);
if (PopUpElement.onDraw !is null) PopUpElement.onDraw();
}


/*public Coordinate getAbsolutePosition(PopUpElement sender){
for(int i ; i < popUpElements.length ; i++){
if(popUpElements[i] = sender){
}
}
return Coordinate();
}*/
//implementation of the `InputListener` interface
/**
* Called when a keybinding event is generated.
Expand Down
21 changes: 21 additions & 0 deletions test3/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class TestElements : InputListener, SystemEventListener {
ih.inputListener = this;
ih.systemEventListener = this;
ih.mouseListener = wh;
PopUpElement.onDraw = &rasterRefresh;
WindowElement.onDraw = &rasterRefresh;
WindowElement.inputHandler = ih;
Window.onDrawUpdate = &rasterRefresh;
Expand Down Expand Up @@ -105,6 +106,7 @@ public class TestWindow : Window {
Button btn_fileDialog;
Button btn_messageDialog;
Button btn_addElem;
Button btn_subMenu;
VertScrollBar vScrollBarTest;
Label singleLineLabel;
Label multiLineLabel;
Expand Down Expand Up @@ -156,6 +158,9 @@ public class TestWindow : Window {
btn_addElem = new Button("Add Elem", "", Box.bySize(300, 70, 70, 20));
btn_addElem.onMouseLClick = &btn_addElem_onClick;
addElement(btn_addElem);
btn_subMenu = new Button("Submenu test", "", Box.bySize(300, 95, 70, 20));
btn_subMenu.onMouseLClick = &btn_subMenu_onClick;
addElement(btn_subMenu);

multiLineDialog = lang["multilinedialog"];
}
Expand All @@ -170,6 +175,22 @@ public class TestWindow : Window {
listViewTest.insertAndEdit(2, new ListViewItem(16, ["Fifth", "000000000000000000000"], [TextInputFieldType.Text,
TextInputFieldType.Text]));
}
private void btn_subMenu_onClick(Event ev) {
PopUpMenuElement[] menutree;
menutree ~= new PopUpMenuElement("\\submenu\\", "Rootmenu 1");
menutree[0] ~= new PopUpMenuElement("", "Submenu 1/1");
menutree[0] ~= new PopUpMenuElement("", "Submenu 1/2");
menutree[0] ~= new PopUpMenuElement("", "Submenu 1/3");
menutree ~= new PopUpMenuElement("\\submenu\\", "Rootmenu 2");
menutree[1] ~= new PopUpMenuElement("", "Submenu 2/1");
menutree[1] ~= new PopUpMenuElement("", "Submenu 2/2");
menutree[1] ~= new PopUpMenuElement("", "Submenu 2/3");
menutree ~= new PopUpMenuElement("\\submenu\\", "Rootmenu 3");
menutree[2] ~= new PopUpMenuElement("", "Submenu 3/1");
menutree[2] ~= new PopUpMenuElement("", "Submenu 3/2");
menutree[2] ~= new PopUpMenuElement("", "Submenu 3/3");
handler.addPopUpElement(new PopUpMenu(menutree, "", null));
}
private void fileDialogEvent(Event ev) {
FileEvent fe = cast(FileEvent)ev;
writeln(fe.path);
Expand Down

0 comments on commit b0b522b

Please sign in to comment.