replace Btn::text_bg2 w/ regex

In case I have to revisit, here's the regex I used:
    Btn::text_bg2\(([^)]*)\)*.build_def\(ctx, ([^()]*)\)
    ctx.style().btn_primary_dark_text($1).hotkey($2).build_def(ctx)

And something like this for the "no hotkey" case
    Btn::text_bg2\(([^)]*)\)*.build_def\(ctx, None\)
    ctx.style().btn_primary_dark_text($1).build_def(ctx)
This commit is contained in:
Michael Kirk 2021-01-20 17:17:03 -06:00 committed by Dustin Carlino
parent 7270ff31af
commit a5b6dca62a
22 changed files with 170 additions and 54 deletions

View File

@ -5,8 +5,8 @@ use geom::Percent;
use map_gui::tools::PopupMsg;
use map_model::{AmenityType, BuildingID};
use widgetry::{
Btn, Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
Panel, SimpleState, State, StyledButtons, TextExt, Transition, VerticalAlignment, Widget,
Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Panel,
SimpleState, State, StyledButtons, TextExt, Transition, VerticalAlignment, Widget,
};
use crate::isochrone::Options;
@ -34,7 +34,10 @@ impl FindHome {
.collect(),
)
.flex_wrap(ctx, Percent::int(50)),
Btn::text_bg2("Search").build_def(ctx, Key::Enter),
ctx.style()
.btn_primary_dark_text("Search")
.hotkey(Key::Enter)
.build_def(ctx),
]))
.build(ctx);
@ -149,7 +152,10 @@ impl Results {
.join(", ")
)
.draw_text(ctx),
Btn::text_bg2("Back").build_def(ctx, Key::Escape),
ctx.style()
.btn_primary_dark_text("Back")
.hotkey(Key::Escape)
.build_def(ctx),
]))
.aligned(HorizontalAlignment::RightInset, VerticalAlignment::TopInset)
.build(ctx);

View File

@ -161,7 +161,12 @@ impl ChallengesPicker {
{
flex_row.push(Btn::text_bg2(&name).inactive(ctx));
} else {
flex_row.push(Btn::text_bg2(&name).build_def(ctx, Key::NUM_KEYS[idx]));
flex_row.push(
ctx.style()
.btn_primary_dark_text(&name)
.hotkey(Key::NUM_KEYS[idx])
.build_def(ctx),
);
links.insert(name.clone(), (name, 0));
}
}

View File

@ -163,7 +163,10 @@ impl BulkEdit {
])
},
Widget::row(vec![
Btn::text_bg2("Finish").build_def(ctx, Key::Enter),
ctx.style()
.btn_primary_dark_text("Finish")
.hotkey(Key::Enter)
.build_def(ctx),
ctx.style()
.btn_plain_destructive_text("Cancel")
.hotkey(Key::Escape)

View File

@ -101,7 +101,10 @@ impl LaneEditor {
])
},
Btn::text_fg("Change access restrictions").build_def(ctx, Key::A),
Btn::text_bg2("Finish").build_def(ctx, Key::Escape),
ctx.style()
.btn_primary_dark_text("Finish")
.hotkey(Key::Escape)
.build_def(ctx),
];
let panel = Panel::new(Widget::col(col))
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)

View File

@ -457,7 +457,10 @@ impl SaveEdits {
self.panel.replace(
ctx,
"Save",
Btn::text_bg2("Save").build_def(ctx, Key::Enter),
ctx.style()
.btn_primary_dark_text("Save")
.hotkey(Key::Enter)
.build_def(ctx),
);
self.panel.replace(ctx, "warning", Text::new().draw(ctx));
}

View File

@ -1,7 +1,7 @@
use geom::{Duration, Time};
use map_model::{BusRouteID, EditCmd};
use widgetry::{
Btn, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, Spinner, State,
EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, Spinner, State,
StyledButtons, TextExt, VerticalAlignment, Widget,
};
@ -31,7 +31,10 @@ impl RouteEditor {
"Frequency in minutes".draw_text(ctx),
Spinner::new(ctx, (1, 120), 60).named("freq_mins"),
]),
Btn::text_bg2("Apply").build_def(ctx, Key::Enter),
ctx.style()
.btn_primary_dark_text("Apply")
.hotkey(Key::Enter)
.build_def(ctx),
]))
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
.build(ctx),

View File

@ -4,7 +4,7 @@ use map_model::{
ControlStopSign, ControlTrafficSignal, EditCmd, EditIntersection, IntersectionID, StageType,
};
use widgetry::{
Btn, Checkbox, Choice, DrawBaselayer, EventCtx, Key, Line, Panel, SimpleState, Spinner, State,
Checkbox, Choice, DrawBaselayer, EventCtx, Key, Line, Panel, SimpleState, Spinner, State,
StyledButtons, TextExt, Widget,
};
@ -94,7 +94,10 @@ impl ChangeDuration {
Line("Minimum time is set by the time required for crosswalk")
.secondary()
.draw(ctx),
Btn::text_bg2("Apply").build_def(ctx, Key::Enter),
ctx.style()
.btn_primary_dark_text("Apply")
.hotkey(Key::Enter)
.build_def(ctx),
]))
.build(ctx);
SimpleState::new(panel, Box::new(ChangeDuration { idx }))

View File

@ -494,7 +494,10 @@ impl State<App> for TrafficSignalEditor {
fn make_top_panel(ctx: &mut EventCtx, app: &App, can_undo: bool, can_redo: bool) -> Panel {
let row = vec![
Btn::text_bg2("Finish").build_def(ctx, Key::Enter),
ctx.style()
.btn_primary_dark_text("Finish")
.hotkey(Key::Enter)
.build_def(ctx),
Btn::text_bg2("Preview").build_def(ctx, lctrl(Key::P)),
(if can_undo {
ctx.style()
@ -611,9 +614,19 @@ fn make_side_panel(
);
if members.len() == 1 {
col.push(Btn::text_bg2("Edit entire signal").build_def(ctx, Key::E));
col.push(
ctx.style()
.btn_primary_dark_text("Edit entire signal")
.hotkey(Key::E)
.build_def(ctx),
);
} else {
col.push(Btn::text_bg2("Tune offsets between signals").build_def(ctx, Key::O));
col.push(
ctx.style()
.btn_primary_dark_text("Tune offsets between signals")
.hotkey(Key::O)
.build_def(ctx),
);
}
let translations = squish_polygons_together(

View File

@ -6,7 +6,7 @@ use geom::{Distance, Duration};
use map_model::IntersectionID;
use sim::Scenario;
use widgetry::{
Btn, Color, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Panel, RewriteColor,
Color, Drawable, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Panel, RewriteColor,
SimpleState, Spinner, State, StyledButtons, Text, TextExt, VerticalAlignment, Widget,
};
@ -252,7 +252,10 @@ impl TuneRelative {
Spinner::new(ctx, (0, 90), (offset2 - offset1).inner_seconds() as isize)
.named("offset"),
]),
Btn::text_bg2("Update offset").build_def(ctx, Key::Enter),
ctx.style()
.btn_primary_dark_text("Update offset")
.hotkey(Key::Enter)
.build_def(ctx),
]))
.build(ctx);
SimpleState::new(

View File

@ -698,7 +698,12 @@ fn make_tabs(
row.push(Btn::text_bg2(name).inactive(ctx).centered_vert());
} else {
hyperlinks.insert(name.to_string(), link);
row.push(Btn::text_bg2(name).build_def(ctx, None).centered_vert());
row.push(
ctx.style()
.btn_primary_dark_text(name)
.build_def(ctx)
.centered_vert(),
);
}
}
// TODO Centered, but actually, we need to set the padding of each button to divide the

View File

@ -503,7 +503,11 @@ pub fn parked_car(
// TODO prev trips, next trips, etc
let p = app.primary.sim.get_owner_of_car(id).unwrap();
rows.push(Btn::text_bg2(format!("Owned by {}", p)).build_def(ctx, None));
rows.push(
ctx.style()
.btn_primary_dark_text(&format!("Owned by {}", p))
.build_def(ctx),
);
details.hyperlinks.insert(
format!("Owned by {}", p),
Tab::PersonTrips(p, BTreeMap::new()),

View File

@ -10,8 +10,8 @@ use geom::Duration;
use map_model::{EditCmd, EditIntersection, MapEdits};
use sim::{OrigPersonID, Scenario, ScenarioGenerator, ScenarioModifier};
use widgetry::{
lctrl, Btn, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome, Panel, State,
StyledButtons, TextExt, Widget,
lctrl, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome, Panel, State, StyledButtons,
TextExt, Widget,
};
pub use self::freeform::spawn_agents_around;
@ -267,14 +267,22 @@ impl FinalScore {
Widget::col(vec![
msg.draw_text(ctx),
// TODO Adjust wording
Btn::text_bg2("Keep simulating").build_def(ctx, None),
Btn::text_bg2("Try again").build_def(ctx, None),
ctx.style()
.btn_primary_dark_text("Keep simulating")
.build_def(ctx),
ctx.style()
.btn_primary_dark_text("Try again")
.build_def(ctx),
if next_mode.is_some() {
Btn::text_bg2("Next challenge").build_def(ctx, None)
ctx.style()
.btn_primary_dark_text("Next challenge")
.build_def(ctx)
} else {
Widget::nothing()
},
Btn::text_bg2("Back to challenges").build_def(ctx, None),
ctx.style()
.btn_primary_dark_text("Back to challenges")
.build_def(ctx),
])
.outline(10.0, Color::BLACK)
.padding(10),

View File

@ -6,8 +6,8 @@ use map_gui::theme::StyledButtons;
use map_gui::tools::{grey_out_map, nice_map_name, ChooseSomething, CityPicker, PopupMsg};
use sim::{ScenarioModifier, TripMode};
use widgetry::{
lctrl, Btn, Choice, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel,
Slider, Spinner, State, Text, TextExt, VerticalAlignment, Widget,
lctrl, Choice, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, Slider,
Spinner, State, Text, TextExt, VerticalAlignment, Widget,
};
use crate::app::{App, Transition};
@ -192,17 +192,33 @@ impl EditScenarioModifiers {
.outline(2.0, Color::WHITE),
);
}
rows.push(Btn::text_bg2("Change trip mode").build_def(ctx, None));
rows.push(Btn::text_bg2("Add extra new trips").build_def(ctx, None));
rows.push(
ctx.style()
.btn_primary_dark_text("Change trip mode")
.build_def(ctx),
);
rows.push(
ctx.style()
.btn_primary_dark_text("Add extra new trips")
.build_def(ctx),
);
rows.push(Widget::row(vec![
Spinner::new(ctx, (2, 14), 2).named("repeat_days"),
Btn::text_bg2("Repeat schedule multiple days").build_def(ctx, None),
ctx.style()
.btn_primary_dark_text("Repeat schedule multiple days")
.build_def(ctx),
]));
rows.push(Widget::horiz_separator(ctx, 0.5));
rows.push(
Widget::row(vec![
Btn::text_bg2("Apply").build_def(ctx, Key::Enter),
Btn::text_bg2("Discard changes").build_def(ctx, Key::Escape),
ctx.style()
.btn_primary_dark_text("Apply")
.hotkey(Key::Enter)
.build_def(ctx),
ctx.style()
.btn_primary_dark_text("Discard changes")
.hotkey(Key::Escape)
.build_def(ctx),
])
.centered(),
);
@ -358,8 +374,14 @@ impl ChangeMode {
}),
]),
Widget::row(vec![
Btn::text_bg2("Apply").build_def(ctx, Key::Enter),
Btn::text_bg2("Discard changes").build_def(ctx, Key::Escape),
ctx.style()
.btn_primary_dark_text("Apply")
.hotkey(Key::Enter)
.build_def(ctx),
ctx.style()
.btn_primary_dark_text("Discard changes")
.hotkey(Key::Escape)
.build_def(ctx),
])
.centered(),
]))

View File

@ -12,8 +12,8 @@ use map_gui::tools::{ChooseSomething, Minimap, PopupMsg, TurnExplorer};
use map_gui::{AppLike, ID};
use sim::{Analytics, Scenario};
use widgetry::{
lctrl, Btn, Choice, Color, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
Outcome, Panel, State, Text, TextExt, UpdateType, VerticalAlignment, Widget,
lctrl, Choice, Color, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Outcome,
Panel, State, Text, TextExt, UpdateType, VerticalAlignment, Widget,
};
pub use self::gameplay::{spawn_agents_around, GameplayMode, TutorialPointer, TutorialState};
@ -452,7 +452,10 @@ impl AgentMeter {
)
.centered_vert(),
format!("{} trips captured", prettyprint_usize(n)).draw_text(ctx),
Btn::text_bg2("Stop").build_def(ctx, None).align_right(),
ctx.style()
.btn_primary_dark_text("Stop")
.build_def(ctx)
.align_right(),
]));
}

View File

@ -36,7 +36,10 @@ impl JumpToTime {
ctx.style().btn_close_widget(ctx),
Widget::custom_row(vec![
Btn::text_bg2("Jump to time").inactive(ctx),
Btn::text_bg2("Jump to delay").build_def(ctx, Key::D),
ctx.style()
.btn_primary_dark_text("Jump to delay")
.hotkey(Key::D)
.build_def(ctx),
])
.bg(Color::WHITE),
Line("Jump to what time?").small_heading().draw(ctx),
@ -164,7 +167,10 @@ impl JumpToDelay {
panel: Panel::new(Widget::col(vec![
ctx.style().btn_close_widget(ctx),
Widget::custom_row(vec![
Btn::text_bg2("Jump to time").build_def(ctx, Key::T),
ctx.style()
.btn_primary_dark_text("Jump to time")
.hotkey(Key::T)
.build_def(ctx),
Btn::text_bg2("Jump to delay").inactive(ctx),
])
.bg(Color::WHITE),

View File

@ -94,7 +94,12 @@ impl<A: AppLike + 'static> CityPicker<A> {
other_cities.push(Btn::text_fg(city).no_tooltip().build_def(ctx, None));
}
}
other_cities.push(Btn::text_bg2("Search all maps").build_def(ctx, Key::Tab));
other_cities.push(
ctx.style()
.btn_primary_dark_text("Search all maps")
.hotkey(Key::Tab)
.build_def(ctx),
);
Transition::Replace(Box::new(CityPicker {
regions,

View File

@ -6,8 +6,8 @@ use anyhow::Result;
use abstio::{DataPacks, Manifest};
use abstutil::Timer;
use widgetry::{
Btn, Checkbox, EventCtx, GfxCtx, Line, Outcome, Panel, State, StyledButtons, TextExt,
Transition, Widget,
Checkbox, EventCtx, GfxCtx, Line, Outcome, Panel, State, StyledButtons, TextExt, Transition,
Widget,
};
use crate::tools::PopupMsg;
@ -48,7 +48,11 @@ impl<A: AppLike + 'static> Picker<A> {
prettyprint_bytes(bytes).draw_text(ctx).centered_vert(),
]));
}
col.push(Btn::text_bg2("Sync files").build_def(ctx, None));
col.push(
ctx.style()
.btn_primary_dark_text("Sync files")
.build_def(ctx),
);
Box::new(Picker {
panel: Panel::new(Widget::col(col)).build(ctx),

View File

@ -73,7 +73,10 @@ impl Viewer {
if let Some(ref b) = self.businesses {
biz_search_panel.unwrap_or_else(|| b.render(ctx).named("Search for businesses"))
} else {
Btn::text_bg2("Search for businesses").build_def(ctx, Key::Tab)
ctx.style()
.btn_primary_dark_text("Search for businesses")
.hotkey(Key::Tab)
.build_def(ctx)
},
]))
.aligned(HorizontalAlignment::Left, VerticalAlignment::Top)
@ -446,7 +449,12 @@ impl BusinessSearch {
fn render(&self, ctx: &mut EventCtx) -> Widget {
let mut col = Vec::new();
col.push(Btn::text_bg2("Hide business search").build_def(ctx, Key::Tab));
col.push(
ctx.style()
.btn_primary_dark_text("Hide business search")
.hotkey(Key::Tab)
.build_def(ctx),
);
col.push(
format!("{} businesses total", prettyprint_usize(self.counts.sum())).draw_text(ctx),
);

View File

@ -2,8 +2,8 @@ use abstutil::prettyprint_usize;
use geom::{Distance, PolyLine, Polygon, Pt2D};
use map_gui::tools::{ColorLegend, PopupMsg};
use widgetry::{
Btn, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Panel,
SimpleState, State, Text, VerticalAlignment, Widget,
Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line, Panel,
SimpleState, State, StyledButtons, Text, VerticalAlignment, Widget,
};
use crate::buildings::{BldgState, Buildings};
@ -95,7 +95,10 @@ impl Strategize {
let panel = Panel::new(Widget::col(vec![
txt.draw(ctx),
Btn::text_bg2("Back to title screen").build_def(ctx, Key::Enter),
ctx.style()
.btn_primary_dark_text("Back to title screen")
.hotkey(Key::Enter)
.build_def(ctx),
Widget::row(vec![
ColorLegend::row(ctx, app.session.colors.house, "house"),
ColorLegend::row(ctx, app.session.colors.apartment, "apartment"),
@ -193,7 +196,10 @@ impl Results {
SimpleState::new(
Panel::new(Widget::col(vec![
txt.draw(ctx),
Btn::text_bg2("OK").build_def(ctx, Key::Enter),
ctx.style()
.btn_primary_dark_text("OK")
.hotkey(Key::Enter)
.build_def(ctx),
]))
.build(ctx),
Box::new(Results),

View File

@ -342,7 +342,10 @@ fn make_upzone_panel(ctx: &mut EventCtx, app: &App, num_picked: usize) -> Panel
.align_right(),
]),
if num_picked == app.session.upzones_unlocked {
Btn::text_bg2("Start game").build_def(ctx, Key::Enter)
ctx.style()
.btn_primary_dark_text("Start game")
.hotkey(Key::Enter)
.build_def(ctx)
} else {
Btn::text_bg2("Finish upzoning before playing").inactive(ctx)
},

View File

@ -1,8 +1,8 @@
use geom::Percent;
use map_gui::tools::open_browser;
use widgetry::{
Btn, ButtonBuilder, Color, ControlState, EdgeInsets, EventCtx, GeomBatch, GfxCtx, Key, Line,
Panel, RewriteColor, SimpleState, State, StyledButtons, Text, TextExt, Widget,
ButtonBuilder, Color, ControlState, EdgeInsets, EventCtx, GeomBatch, GfxCtx, Key, Line, Panel,
RewriteColor, SimpleState, State, StyledButtons, Text, TextExt, Widget,
};
use crate::levels::Level;
@ -180,7 +180,7 @@ impl Credits {
link(ctx, "Music from various sources", "https://github.com/dabreegster/abstreet/tree/master/data/system/assets/music/sources.md"),
link(ctx, "Fonts and icons by various sources", "https://dabreegster.github.io/abstreet/howto/#data-source-licensing"),
"Playtesting by Fridgehaus".draw_text(ctx),
Btn::text_bg2("Back").build_def(ctx, Key::Enter).centered_horiz(),
ctx.style().btn_primary_dark_text("Back").hotkey(Key::Enter).build_def(ctx).centered_horiz(),
]))
.build(ctx), Box::new(Credits))
}

View File

@ -107,7 +107,7 @@ impl<A, T, F> Table<A, T, F> {
))
.build(ctx, &col.name, None)
} else if let Col::Sortable(_) = col.col {
Btn::text_bg2(&col.name).build_def(ctx, None)
ctx.style().btn_primary_dark_text(&col.name).build_def(ctx)
} else {
Line(&col.name).draw(ctx).centered_vert()
}