Make the file management menu in edit mode occupy the center of the screen.

This commit is contained in:
Dustin Carlino 2021-01-21 15:36:21 -08:00
parent 02e3235de2
commit dc19d11f64
5 changed files with 26 additions and 39 deletions

View File

@ -226,9 +226,9 @@ impl State<App> for StoryMapEditor {
},
));
return Transition::Push(ChooseSomething::new_below(
return Transition::Push(ChooseSomething::new(
ctx,
self.panel.rect_of("load"),
"Load story",
choices,
Box::new(|story, _, _| {
Transition::Multi(vec![

View File

@ -187,9 +187,9 @@ impl State<App> for EditMode {
Outcome::Clicked(x) => match x.as_ref() {
"manage proposals" => {
let mode = self.mode.clone();
return Transition::Push(ChooseSomething::new_below(
return Transition::Push(ChooseSomething::new(
ctx,
self.changelist.rect_of("manage proposals"),
"Manage proposals",
vec![
Choice::string("rename current proposal"),
Choice::string("open a saved proposal").multikey(lctrl(Key::L)),

View File

@ -12,8 +12,8 @@ use sim::{
VehicleType,
};
use widgetry::{
Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
LinePlot, Outcome, Panel, PlotOptions, Series, TextExt, VerticalAlignment, Widget, ControlState
Checkbox, Color, ControlState, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key,
Line, LinePlot, Outcome, Panel, PlotOptions, Series, TextExt, VerticalAlignment, Widget,
};
use crate::app::{App, Transition};
@ -697,16 +697,25 @@ fn make_tabs(
row.push(
ctx.style()
.btn_primary_dark_text(name)
// We use "disabled" to denote "currently selected", but we want to style it like normal
// We use "disabled" to denote "currently selected", but we want to style it like
// normal
.disabled(current_tab.variant() == link.variant())
.bg_color(ctx.style().btn_primary_dark.bg, ControlState::Disabled)
.label_color(ctx.style().btn_primary_dark.fg, ControlState::Disabled)
.outline(2.0, ctx.style().btn_primary_dark.bg_hover, ControlState::Disabled)
.outline(
2.0,
ctx.style().btn_primary_dark.bg_hover,
ControlState::Disabled,
)
// Hide the hit area for selectable tabs unless hovered
.bg_color(Color::CLEAR, ControlState::Default)
.outline(0.0, Color::CLEAR, ControlState::Default)
.outline(2.0, ctx.style().btn_primary_dark.bg_hover.alpha(0.4), ControlState::Hovered)
.build_def(ctx)
.outline(
2.0,
ctx.style().btn_primary_dark.bg_hover.alpha(0.4),
ControlState::Hovered,
)
.build_def(ctx),
);
hyperlinks.insert(name.to_string(), link);
}

View File

@ -1,9 +1,8 @@
//! Generic UI tools. Some of this should perhaps be lifted to widgetry.
use widgetry::{
hotkeys, Choice, DrawBaselayer, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Key, Line,
Menu, Outcome, Panel, ScreenRectangle, State, StyledButtons, Text, Transition,
VerticalAlignment, Widget,
hotkeys, Choice, DrawBaselayer, Drawable, EventCtx, GfxCtx, Key, Line, Menu, Outcome, Panel,
State, StyledButtons, Text, Transition, Widget,
};
use crate::tools::grey_out_map;
@ -34,23 +33,6 @@ impl<A: AppLike + 'static, T: 'static> ChooseSomething<A, T> {
cb,
})
}
pub fn new_below(
ctx: &mut EventCtx,
rect: &ScreenRectangle,
choices: Vec<Choice<T>>,
cb: Box<dyn Fn(T, &mut EventCtx, &mut A) -> Transition<A>>,
) -> Box<dyn State<A>> {
Box::new(ChooseSomething {
panel: Panel::new(Menu::new(ctx, choices).named("menu").container())
.aligned(
HorizontalAlignment::Centered(rect.center().x),
VerticalAlignment::Below(rect.y2 + 15.0),
)
.build(ctx),
cb,
})
}
}
impl<A: AppLike + 'static, T: 'static> State<A> for ChooseSomething<A, T> {
@ -67,10 +49,6 @@ impl<A: AppLike + 'static, T: 'static> State<A> for ChooseSomething<A, T> {
if ctx.normal_left_click() && ctx.canvas.get_cursor_in_screen_space().is_none() {
return Transition::Pop;
}
// new_below doesn't make an X button
if ctx.input.pressed(Key::Escape) {
return Transition::Pop;
}
Transition::Keep
}
}

View File

@ -211,11 +211,11 @@ impl Settings {
self
}
/// When calling `Widget::draw_svg`, `Btn::svg`, and similar, use this function to transform
/// the filename given to the raw bytes of that SVG file. By default, this just reads the
/// file normally. You may want to override this to more conveniently locate the file
/// (transforming a short filename to a full path) or to handle reading files in WASM (where
/// regular filesystem IO doesn't work).
/// When calling `Widget::draw_svg`, `ButtonBuilder::image_path`, and similar, use this function
/// to transform the filename given to the raw bytes of that SVG file. By default, this just
/// reads the file normally. You may want to override this to more conveniently locate the
/// file (transforming a short filename to a full path) or to handle reading files in WASM
/// (where regular filesystem IO doesn't work).
pub fn read_svg(mut self, function: Box<dyn Fn(&str) -> Vec<u8>>) -> Self {
self.read_svg = function;
self