Sfoglia il codice sorgente

Prevent UIMenu from going over the screen in the IDE.

cib 12 anni fa
parent
commit
2753d88462

+ 3 - 1
IDE/Contents/Source/PolycodeProjectBrowser.cpp

@@ -126,7 +126,9 @@ void PolycodeProjectBrowser::handleEvent(Event *event) {
 			contextMenu->addOption("Refresh", "refresh");
 			contextMenu->addOption("Rename", "rename");						
 			contextMenu->addOption("----------------", "");		
-			contextMenu->addOption("Remove", "remove");	
+			contextMenu->addOption("Remove", "remove");
+
+			contextMenu->fitToScreenVertical();
 			
 			contextMenu->addEventListener(this, UIEvent::OK_EVENT);
 											

+ 2 - 0
Modules/Contents/UI/Include/PolyUIMenu.h

@@ -52,6 +52,8 @@ namespace Polycode {
 			UIMenuItem *getSelectedItem();
 
 			void handleEvent(Event *event);
+
+			void fitToScreenVertical();
 			
 		protected:
 		

+ 15 - 0
Modules/Contents/UI/Source/PolyUIMenu.cpp

@@ -133,6 +133,20 @@ UIMenuItem *UIMenu::getSelectedItem() {
 void UIMenu::Update() {
 	ignoreMouse = false;
 }
+
+void UIMenu::fitToScreenVertical() {
+	// Make sure the entity doesn't go past the bottom of the screen.
+	if(dropDownBox->getHeight() < CoreServices::getInstance()->getCore()->getYRes()) {
+		// If the entity is as high as the screen, no point trying to fit it in vertically.
+		Vector2 screenPos = this->getScreenPosition();
+		Number exceedScreenBottom = screenPos.y + dropDownBox->getHeight() - CoreServices::getInstance()->getCore()->getYRes();
+		if(exceedScreenBottom > 0) {
+			this->setPosition(this->getPosition().x, this->getPosition().y - exceedScreenBottom);
+		} else if(screenPos.y < 0) {
+			this->setPosition(this->getPosition().x, 0);
+		}
+	}
+}
 				
 void UIMenu::handleEvent(Event *event) {
 
@@ -257,6 +271,7 @@ UIMenu *UIGlobalMenu::showMenu(Number x, Number y, Number width) {
 		
 	addChild(currentMenu);
 	currentMenu->setPosition(x,y);
+
 	return currentMenu;
 	
 }