Add an about button to LTN

This commit is contained in:
Dustin Carlino 2022-03-21 12:09:52 +00:00
parent b22e560abd
commit a45eeb3ede

View File

@ -1,8 +1,9 @@
use geom::CornerRadii;
use widgetry::tools::PopupMsg;
use map_gui::tools::grey_out_map;
use widgetry::tools::{open_browser, PopupMsg};
use widgetry::{
lctrl, CornerRounding, EventCtx, HorizontalAlignment, Key, Line, Outcome, Panel, PanelBuilder,
PanelDims, VerticalAlignment, Widget,
lctrl, CornerRounding, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel,
PanelBuilder, PanelDims, SimpleState, State, TextExt, VerticalAlignment, Widget,
};
use crate::{App, BrowseNeighborhoods, Transition};
@ -15,18 +16,26 @@ pub fn app_top_panel(ctx: &mut EventCtx, app: &App) -> Panel {
.small_heading()
.into_widget(ctx)
.centered_vert(),
ctx.style()
.btn_plain
.icon("system/assets/tools/info.svg")
.build_widget(ctx, "about this tool")
.centered_vert(),
map_gui::tools::change_map_btn(ctx, app).centered_vert(),
ctx.style()
.btn_plain
.icon("system/assets/tools/search.svg")
.hotkey(lctrl(Key::F))
.build_widget(ctx, "search")
.centered_vert(),
ctx.style()
.btn_plain
.icon("system/assets/tools/help.svg")
.build_widget(ctx, "help")
.centered_vert(),
Widget::row(vec![
ctx.style()
.btn_plain
.icon("system/assets/tools/search.svg")
.hotkey(lctrl(Key::F))
.build_widget(ctx, "search")
.centered_vert(),
ctx.style()
.btn_plain
.icon("system/assets/tools/help.svg")
.build_widget(ctx, "help")
.centered_vert(),
])
.align_right(),
])
.corner_rounding(CornerRounding::CornerRadii(CornerRadii {
top_left: 0.0,
@ -65,6 +74,7 @@ pub fn handle_top_panel<F: Fn() -> Vec<&'static str>>(
ctx, app,
))),
"help" => Some(Transition::Push(PopupMsg::new_state(ctx, "Help", help()))),
"about this tool" => Some(Transition::Push(About::new_state(ctx))),
_ => unreachable!(),
}
} else {
@ -90,3 +100,40 @@ pub fn left_panel_builder(ctx: &EventCtx, top_panel: &Panel, contents: Widget) -
ctx.canvas.window_height - top_height,
))
}
struct About;
impl About {
fn new_state(ctx: &mut EventCtx) -> Box<dyn State<App>> {
let panel = Panel::new_builder(Widget::col(vec![
Widget::row(vec![
Line("About the LTN tool").small_heading().into_widget(ctx),
ctx.style().btn_close_widget(ctx),
]),
"Created by Dustin Carlino & Cindy Huang".text_widget(ctx),
"Data from OpenStreetMap".text_widget(ctx),
"See below for full credits and more info".text_widget(ctx),
ctx.style()
.btn_outline
.text("ltn.abstreet.org")
.build_def(ctx),
]))
.build(ctx);
<dyn SimpleState<_>>::new_state(panel, Box::new(About))
}
}
impl SimpleState<App> for About {
fn on_click(&mut self, _: &mut EventCtx, _: &mut App, x: &str, _: &mut Panel) -> Transition {
if x == "close" {
return Transition::Pop;
} else if x == "ltn.abstreet.org" {
open_browser("http://ltn.abstreet.org");
}
Transition::Keep
}
fn draw(&self, g: &mut GfxCtx, app: &App) {
grey_out_map(g, app);
}
}