Open a menu with the mouse
This commit is contained in:
parent
bbe37eab97
commit
d50f6701f4
|
@ -86,6 +86,13 @@ class Display:
|
||||||
def display(self) -> None:
|
def display(self) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def handle_click(self, y: int, x: int) -> None:
|
||||||
|
"""
|
||||||
|
A mouse click was performed on the coordinates (y, x) of the pad.
|
||||||
|
Maybe it can do something.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rows(self) -> int:
|
def rows(self) -> int:
|
||||||
return curses.LINES if self.screen else 42
|
return curses.LINES if self.screen else 42
|
||||||
|
|
|
@ -64,7 +64,8 @@ class DisplayManager:
|
||||||
# The click coordinates correspond to the coordinates
|
# The click coordinates correspond to the coordinates
|
||||||
# of that display
|
# of that display
|
||||||
display = d
|
display = d
|
||||||
raise Exception(f"click at ({y}, {x})", display)
|
if display:
|
||||||
|
display.handle_click(y - display.y, x - display.x)
|
||||||
|
|
||||||
def refresh(self) -> List[Display]:
|
def refresh(self) -> List[Display]:
|
||||||
displays = []
|
displays = []
|
||||||
|
|
|
@ -41,6 +41,13 @@ class MenuDisplay(Display):
|
||||||
self.height - 2 + self.y,
|
self.height - 2 + self.y,
|
||||||
self.width - 2 + self.x)
|
self.width - 2 + self.x)
|
||||||
|
|
||||||
|
def handle_click(self, y: int, x: int) -> None:
|
||||||
|
"""
|
||||||
|
We can select a menu item with the mouse.
|
||||||
|
"""
|
||||||
|
self.menu.position = y - 1
|
||||||
|
curses.ungetch('\n')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def truewidth(self) -> int:
|
def truewidth(self) -> int:
|
||||||
return max([len(str(a)) for a in self.values])
|
return max([len(str(a)) for a in self.values])
|
||||||
|
@ -99,6 +106,14 @@ class MainMenuDisplay(Display):
|
||||||
menuy, menux, min(self.menudisplay.preferred_height,
|
menuy, menux, min(self.menudisplay.preferred_height,
|
||||||
self.height - menuy), menuwidth)
|
self.height - menuy), menuwidth)
|
||||||
|
|
||||||
|
def handle_click(self, y: int, x: int) -> None:
|
||||||
|
menuwidth = min(self.menudisplay.preferred_width, self.width)
|
||||||
|
menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1
|
||||||
|
menuheight = min(self.menudisplay.preferred_height, self.height - menuy)
|
||||||
|
|
||||||
|
if menuy <= y < menuy + menuheight and menux <= x < menux + menuwidth:
|
||||||
|
self.menudisplay.handle_click(y - menuy, x - menux)
|
||||||
|
|
||||||
|
|
||||||
class InventoryDisplay(MenuDisplay):
|
class InventoryDisplay(MenuDisplay):
|
||||||
def update_pad(self) -> None:
|
def update_pad(self) -> None:
|
||||||
|
|
Loading…
Reference in New Issue