mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 10:44:56 +03:00
consolidating other button styles, and adjusting signal editor colors
This commit is contained in:
parent
76f5cde433
commit
89a269a59e
@ -237,7 +237,7 @@ impl Button {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn text(
|
||||
pub fn text_bg(
|
||||
text: Text,
|
||||
unselected_bg_color: Color,
|
||||
selected_bg_color: Color,
|
||||
@ -275,27 +275,30 @@ impl Button {
|
||||
selected_text: Text,
|
||||
hotkey: Option<MultiKey>,
|
||||
tooltip: &str,
|
||||
padding: bool,
|
||||
ctx: &EventCtx,
|
||||
) -> Button {
|
||||
const HORIZ_PADDING: f64 = 15.0;
|
||||
const VERT_PADDING: f64 = 8.0;
|
||||
// TODO Padding here is unfortunate, but I don't understand when the flexbox padding
|
||||
// actually works.
|
||||
let horiz_padding = if padding { 15.0 } else { 0.0 };
|
||||
let vert_padding = if padding { 8.0 } else { 0.0 };
|
||||
|
||||
let dims = ctx.text_dims(&unselected_text);
|
||||
assert_eq!(dims, ctx.text_dims(&selected_text));
|
||||
let geom = Polygon::rectangle(
|
||||
dims.width + 2.0 * HORIZ_PADDING,
|
||||
dims.height + 2.0 * VERT_PADDING,
|
||||
dims.width + 2.0 * horiz_padding,
|
||||
dims.height + 2.0 * vert_padding,
|
||||
);
|
||||
|
||||
let normal = DrawBoth::new(
|
||||
ctx,
|
||||
GeomBatch::new(),
|
||||
vec![(unselected_text, ScreenPt::new(HORIZ_PADDING, VERT_PADDING))],
|
||||
vec![(unselected_text, ScreenPt::new(horiz_padding, vert_padding))],
|
||||
);
|
||||
let hovered = DrawBoth::new(
|
||||
ctx,
|
||||
GeomBatch::new(),
|
||||
vec![(selected_text, ScreenPt::new(HORIZ_PADDING, VERT_PADDING))],
|
||||
vec![(selected_text, ScreenPt::new(horiz_padding, vert_padding))],
|
||||
);
|
||||
|
||||
Button::new(normal, hovered, hotkey, tooltip, geom)
|
||||
|
@ -388,7 +388,7 @@ impl<'a, 'b> WrappedWizard<'a, 'b> {
|
||||
Composite::new(
|
||||
ManagedWidget::col(vec![
|
||||
ManagedWidget::draw_text(self.ctx, txt),
|
||||
ManagedWidget::btn(Button::text(
|
||||
ManagedWidget::btn(Button::text_bg(
|
||||
Text::from(Line("OK")),
|
||||
Color::grey(0.6),
|
||||
Color::ORANGE,
|
||||
|
@ -5,7 +5,7 @@ use crate::sandbox::{GameplayMode, SandboxMode};
|
||||
use crate::ui::UI;
|
||||
use abstutil::Timer;
|
||||
use ezgui::{
|
||||
hotkey, Choice, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line,
|
||||
hotkey, Button, Choice, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Line,
|
||||
ManagedWidget, ModalMenu, Text, VerticalAlignment,
|
||||
};
|
||||
use geom::{Duration, Time};
|
||||
@ -138,12 +138,14 @@ pub fn challenges_picker(ctx: &mut EventCtx) -> Box<dyn State> {
|
||||
|
||||
let mut flex_row = Vec::new();
|
||||
for (idx, (name, _)) in all_challenges().into_iter().enumerate() {
|
||||
flex_row.push(WrappedComposite::detailed_text_button(
|
||||
ctx,
|
||||
flex_row.push(ManagedWidget::btn(Button::text_bg(
|
||||
Text::from(Line(&name).size(40).fg(Color::BLACK)),
|
||||
Color::WHITE,
|
||||
Color::ORANGE,
|
||||
hotkey(Key::NUM_KEYS[idx]),
|
||||
&name,
|
||||
));
|
||||
ctx,
|
||||
)));
|
||||
}
|
||||
col.push(ManagedWidget::row(flex_row).flex_wrap(ctx, 80));
|
||||
|
||||
|
@ -63,7 +63,7 @@ impl InfoPanel {
|
||||
let mut txt = Text::new();
|
||||
txt.append(Line(key.describe()).fg(ezgui::HOTKEY_COLOR));
|
||||
txt.append(Line(format!(" - {}", label)));
|
||||
col.push(ManagedWidget::btn(Button::text(
|
||||
col.push(ManagedWidget::btn(Button::text_bg(
|
||||
txt,
|
||||
Color::grey(0.5),
|
||||
Color::ORANGE,
|
||||
|
@ -407,14 +407,12 @@ fn make_viz_panel(ctx: &mut EventCtx, acs: &AgentColorScheme) -> ManagedWidget {
|
||||
]),
|
||||
// TODO Too wide most of the time...
|
||||
ManagedWidget::draw_text(ctx, Text::prompt(&acs.title)),
|
||||
ManagedWidget::btn(Button::text(
|
||||
WrappedComposite::nice_text_button(
|
||||
ctx,
|
||||
Text::from(Line("change")),
|
||||
Color::grey(0.6),
|
||||
Color::ORANGE,
|
||||
hotkey(Key::Semicolon),
|
||||
"change agent colorscheme",
|
||||
ctx,
|
||||
)),
|
||||
),
|
||||
];
|
||||
for (label, color, enabled) in &acs.rows {
|
||||
col.push(
|
||||
|
@ -13,7 +13,7 @@ use ezgui::{
|
||||
GfxCtx, HorizontalAlignment, Key, Line, ManagedWidget, ModalMenu, Outcome, RewriteColor, Text,
|
||||
VerticalAlignment,
|
||||
};
|
||||
use geom::{Duration, Polygon};
|
||||
use geom::{Distance, Duration, Polygon};
|
||||
use map_model::{ControlTrafficSignal, EditCmd, IntersectionID, Phase, TurnGroupID, TurnPriority};
|
||||
use sim::Sim;
|
||||
use std::collections::BTreeSet;
|
||||
@ -474,7 +474,7 @@ fn make_diagram(i: IntersectionID, selected: usize, ui: &UI, ctx: &mut EventCtx)
|
||||
if idx == selected {
|
||||
normal.push(Color::RED.alpha(0.15), bbox.clone());
|
||||
} else {
|
||||
normal.push(Color::CYAN.alpha(0.05), bbox.clone());
|
||||
normal.push(Color::BLACK, bbox.clone());
|
||||
}
|
||||
// Move to the origin and apply zoom
|
||||
for (color, poly) in orig_batch.consume() {
|
||||
@ -485,14 +485,14 @@ fn make_diagram(i: IntersectionID, selected: usize, ui: &UI, ctx: &mut EventCtx)
|
||||
}
|
||||
|
||||
let mut hovered = GeomBatch::new();
|
||||
hovered.push(Color::RED.alpha(0.95), bbox.clone());
|
||||
hovered.append(normal.clone());
|
||||
hovered.push(Color::RED, bbox.to_outline(Distance::meters(5.0)));
|
||||
|
||||
let mut move_phase = Vec::new();
|
||||
if idx != 0 {
|
||||
move_phase.push(WrappedComposite::detailed_text_button(
|
||||
move_phase.push(WrappedComposite::nice_text_button(
|
||||
ctx,
|
||||
Text::from(Line("↑").fg(Color::BLACK)),
|
||||
Text::from(Line("↑")),
|
||||
if selected == idx {
|
||||
hotkey(Key::K)
|
||||
} else {
|
||||
@ -502,9 +502,9 @@ fn make_diagram(i: IntersectionID, selected: usize, ui: &UI, ctx: &mut EventCtx)
|
||||
));
|
||||
}
|
||||
if idx != signal.phases.len() - 1 {
|
||||
move_phase.push(WrappedComposite::detailed_text_button(
|
||||
move_phase.push(WrappedComposite::nice_text_button(
|
||||
ctx,
|
||||
Text::from(Line("↓").fg(Color::BLACK)),
|
||||
Text::from(Line("↓")),
|
||||
if selected == idx {
|
||||
hotkey(Key::J)
|
||||
} else {
|
||||
@ -514,17 +514,20 @@ fn make_diagram(i: IntersectionID, selected: usize, ui: &UI, ctx: &mut EventCtx)
|
||||
));
|
||||
}
|
||||
|
||||
col.push(ManagedWidget::row(vec![
|
||||
ManagedWidget::btn(Button::new(
|
||||
DrawBoth::new(ctx, normal, Vec::new()),
|
||||
DrawBoth::new(ctx, hovered, Vec::new()),
|
||||
None,
|
||||
&format!("phase {}", idx + 1),
|
||||
bbox.clone(),
|
||||
))
|
||||
col.push(
|
||||
ManagedWidget::row(vec![
|
||||
ManagedWidget::btn(Button::new(
|
||||
DrawBoth::new(ctx, normal, Vec::new()),
|
||||
DrawBoth::new(ctx, hovered, Vec::new()),
|
||||
None,
|
||||
&format!("phase {}", idx + 1),
|
||||
bbox.clone(),
|
||||
))
|
||||
.margin(5),
|
||||
ManagedWidget::col(move_phase),
|
||||
])
|
||||
.margin(5),
|
||||
ManagedWidget::col(move_phase),
|
||||
]));
|
||||
);
|
||||
col.push(WrappedComposite::text_button(
|
||||
ctx,
|
||||
&format!("add new phase after #{}", idx + 1),
|
||||
|
@ -90,29 +90,19 @@ impl WrappedComposite {
|
||||
txt.change_fg(Color::ORANGE),
|
||||
hotkey,
|
||||
label,
|
||||
true,
|
||||
ctx,
|
||||
))
|
||||
.outline(2.0, Color::WHITE)
|
||||
}
|
||||
|
||||
pub fn text_button(ctx: &EventCtx, label: &str, hotkey: Option<MultiKey>) -> ManagedWidget {
|
||||
WrappedComposite::detailed_text_button(
|
||||
ctx,
|
||||
Text::from(Line(label).fg(Color::BLACK)),
|
||||
hotkey,
|
||||
label,
|
||||
)
|
||||
WrappedComposite::nice_text_button(ctx, Text::from(Line(label)), hotkey, label)
|
||||
}
|
||||
|
||||
pub fn detailed_text_button(
|
||||
ctx: &EventCtx,
|
||||
txt: Text,
|
||||
hotkey: Option<MultiKey>,
|
||||
label: &str,
|
||||
) -> ManagedWidget {
|
||||
// TODO Default style. Lots of variations.
|
||||
ManagedWidget::btn(Button::text(
|
||||
txt,
|
||||
pub fn text_bg_button(ctx: &EventCtx, label: &str, hotkey: Option<MultiKey>) -> ManagedWidget {
|
||||
ManagedWidget::btn(Button::text_bg(
|
||||
Text::from(Line(label).fg(Color::BLACK)),
|
||||
Color::WHITE,
|
||||
Color::ORANGE,
|
||||
hotkey,
|
||||
|
@ -33,7 +33,7 @@ impl TitleScreen {
|
||||
.bg(Color::GREEN.alpha(0.2)),
|
||||
// TODO that nicer font
|
||||
// TODO Any key
|
||||
ManagedWidget::btn(Button::text(
|
||||
ManagedWidget::btn(Button::text_bg(
|
||||
Text::from(Line("PLAY")),
|
||||
Color::BLUE,
|
||||
Color::ORANGE,
|
||||
@ -104,11 +104,15 @@ pub fn main_menu(ctx: &mut EventCtx, ui: &UI) -> Box<dyn State> {
|
||||
];
|
||||
if ui.opts.dev {
|
||||
col.push(ManagedWidget::row(vec![
|
||||
WrappedComposite::text_button(ctx, "INTERNAL DEV TOOLS", hotkey(Key::M)),
|
||||
WrappedComposite::text_button(ctx, "INTERNAL A/B TEST MODE", hotkey(Key::A)),
|
||||
WrappedComposite::text_bg_button(ctx, "INTERNAL DEV TOOLS", hotkey(Key::M)),
|
||||
WrappedComposite::text_bg_button(ctx, "INTERNAL A/B TEST MODE", hotkey(Key::A)),
|
||||
]));
|
||||
}
|
||||
col.push(WrappedComposite::text_button(ctx, "About A/B Street", None));
|
||||
col.push(WrappedComposite::text_bg_button(
|
||||
ctx,
|
||||
"About A/B Street",
|
||||
None,
|
||||
));
|
||||
|
||||
let mut c = WrappedComposite::new(
|
||||
Composite::new(ManagedWidget::row(vec![
|
||||
|
@ -123,6 +123,7 @@ impl SpeedControls {
|
||||
Text::from(Line("+0.1s").fg(Color::ORANGE).size(21).roboto()),
|
||||
hotkey(Key::M),
|
||||
"step forwards 0.1 seconds",
|
||||
false,
|
||||
ctx,
|
||||
)),
|
||||
ManagedWidget::btn(Button::text_no_bg(
|
||||
@ -130,6 +131,7 @@ impl SpeedControls {
|
||||
Text::from(Line("+1h").fg(Color::ORANGE).size(21).roboto()),
|
||||
hotkey(Key::N),
|
||||
"step forwards 1 hour",
|
||||
false,
|
||||
ctx,
|
||||
)),
|
||||
ManagedWidget::btn(Button::rectangle_svg(
|
||||
|
Loading…
Reference in New Issue
Block a user