mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
place the context menu onscreen, be smart about going OOB
This commit is contained in:
parent
96c3907655
commit
08e1d3f353
@ -29,7 +29,6 @@
|
||||
- X on all menus
|
||||
- when dragging, dont give mouse movement to UI elements
|
||||
- start context menu when left click releases and we're not dragging
|
||||
- dont draw context menu off-screen
|
||||
- can we change labels in modal or top menu? show/hide
|
||||
- bold hotkey letters
|
||||
|
||||
|
@ -41,7 +41,7 @@ impl ContextMenu {
|
||||
.collect(),
|
||||
false,
|
||||
false,
|
||||
Position::TopLeftAt(origin),
|
||||
Position::SomeCornerAt(origin),
|
||||
canvas,
|
||||
))
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ struct Geometry {
|
||||
#[derive(Clone)]
|
||||
pub enum Position {
|
||||
ScreenCenter,
|
||||
TopLeftAt(ScreenPt),
|
||||
SomeCornerAt(ScreenPt),
|
||||
TopRightOfScreen,
|
||||
}
|
||||
|
||||
@ -51,7 +51,28 @@ impl Position {
|
||||
let (total_width, total_height) = canvas.text_dims(&txt);
|
||||
|
||||
let top_left = match self {
|
||||
Position::TopLeftAt(pt) => *pt,
|
||||
Position::SomeCornerAt(pt) => {
|
||||
// TODO Ideally also avoid covered canvas areas (modal menu)
|
||||
if pt.x + total_width < canvas.window_width {
|
||||
// pt.x is the left corner
|
||||
if pt.y + total_height < canvas.window_height {
|
||||
// pt.y is the top corner
|
||||
*pt
|
||||
} else {
|
||||
// pt.y is the bottom corner
|
||||
ScreenPt::new(pt.x, pt.y - total_height)
|
||||
}
|
||||
} else {
|
||||
// pt.x is the right corner
|
||||
if pt.y + total_height < canvas.window_height {
|
||||
// pt.y is the top corner
|
||||
ScreenPt::new(pt.x - total_width, pt.y)
|
||||
} else {
|
||||
// pt.y is the bottom corner
|
||||
ScreenPt::new(pt.x - total_width, pt.y - total_height)
|
||||
}
|
||||
}
|
||||
}
|
||||
Position::ScreenCenter => {
|
||||
let mut pt = canvas.center_to_screen_pt();
|
||||
pt.x -= total_width / 2.0;
|
||||
|
Loading…
Reference in New Issue
Block a user