mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 16:36:02 +03:00
declare extra space needed by modal menus. dont stretch menus to cover
that amount... yet.
This commit is contained in:
parent
5ef73ee8eb
commit
37c9d01a6f
@ -19,17 +19,22 @@ impl Legend {
|
||||
|
||||
pub fn start(input: &mut UserInput, canvas: &Canvas) -> Legend {
|
||||
Legend {
|
||||
top_left: input.set_mode("Legend", canvas),
|
||||
// Size needed for the legend was manually tuned. :\
|
||||
top_left: input.set_mode_with_extra(
|
||||
"Legend",
|
||||
"Legend".to_string(),
|
||||
canvas,
|
||||
220.0,
|
||||
300.0,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Plugin for Legend {
|
||||
fn nonblocking_event(&mut self, ctx: &mut PluginCtx) -> bool {
|
||||
self.top_left = ctx.input.set_mode("Legend", &ctx.canvas);
|
||||
*self = Legend::start(ctx.input, ctx.canvas);
|
||||
|
||||
// TODO Hack
|
||||
self.top_left.x -= 150.0;
|
||||
if ctx.input.modal_action("quit") {
|
||||
return false;
|
||||
}
|
||||
|
@ -231,11 +231,13 @@ impl UserInput {
|
||||
|
||||
// Returns the bottom left of the modal menu.
|
||||
// TODO It'd be nice to scope the return value to the next draw()s only.
|
||||
pub fn set_mode_with_prompt(
|
||||
pub fn set_mode_with_extra(
|
||||
&mut self,
|
||||
mode: &str,
|
||||
prompt: String,
|
||||
canvas: &Canvas,
|
||||
extra_width: f64,
|
||||
_extra_height: f64,
|
||||
) -> ScreenPt {
|
||||
self.set_mode_called.insert(mode.to_string());
|
||||
self.current_mode = Some(mode.to_string());
|
||||
@ -252,7 +254,7 @@ impl UserInput {
|
||||
.map(|(key, action)| (Some(*key), action.to_string(), *key))
|
||||
.collect(),
|
||||
false,
|
||||
Position::TopRightOfScreen,
|
||||
Position::TopRightOfScreen(extra_width),
|
||||
canvas,
|
||||
);
|
||||
menu.mark_all_inactive();
|
||||
@ -265,6 +267,15 @@ impl UserInput {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_mode_with_prompt(
|
||||
&mut self,
|
||||
mode: &str,
|
||||
prompt: String,
|
||||
canvas: &Canvas,
|
||||
) -> ScreenPt {
|
||||
self.set_mode_with_extra(mode, prompt, canvas, 0.0, 0.0)
|
||||
}
|
||||
|
||||
pub fn set_mode(&mut self, mode: &str, canvas: &Canvas) -> ScreenPt {
|
||||
self.set_mode_with_prompt(mode, mode.to_string(), canvas)
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ pub struct Menu<T: Clone> {
|
||||
pub enum Position {
|
||||
ScreenCenter,
|
||||
TopLeftAt(ScreenPt),
|
||||
TopRightOfScreen,
|
||||
// Extra width needed -- if more than the natural menu length, this'll pad the menu.
|
||||
TopRightOfScreen(f64),
|
||||
}
|
||||
|
||||
impl<T: Clone> Menu<T> {
|
||||
@ -59,8 +60,13 @@ impl<T: Clone> Menu<T> {
|
||||
pt.y -= total_height / 2.0;
|
||||
pt
|
||||
}
|
||||
Position::TopRightOfScreen => {
|
||||
ScreenPt::new(canvas.window_width - total_width, LINE_HEIGHT)
|
||||
Position::TopRightOfScreen(extra_width) => {
|
||||
let w = if extra_width > total_width {
|
||||
extra_width
|
||||
} else {
|
||||
total_width
|
||||
};
|
||||
ScreenPt::new(canvas.window_width - w, LINE_HEIGHT)
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user