more button progress and fixups (#465)

* replace Btn::txt with new ButtonBuilder styles

* fixup! replace Btn::text_bg1 with ButtonBuilder (btn_primary_light)
This commit is contained in:
Michael Kirk 2021-01-20 16:11:28 -06:00 committed by GitHub
parent 11ffef5716
commit 5b6c88d3b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 55 additions and 35 deletions

View File

@ -6,7 +6,7 @@ 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, TextExt, Transition, VerticalAlignment, Widget,
Panel, SimpleState, State, StyledButtons, TextExt, Transition, VerticalAlignment, Widget,
};
use crate::isochrone::Options;

View File

@ -13,8 +13,8 @@ use map_model::{AmenityType, Building, BuildingID, LaneType};
use widgetry::table::{Col, Filter, Table};
use widgetry::{
lctrl, Btn, Cached, Checkbox, Choice, Color, Drawable, EventCtx, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, Outcome, Panel, RewriteColor, State, Text, TextExt, Transition,
VerticalAlignment, Widget,
HorizontalAlignment, Key, Line, Outcome, Panel, RewriteColor, State, StyledButtons, Text,
TextExt, Transition, VerticalAlignment, Widget,
};
use crate::find_home::FindHome;
@ -327,7 +327,11 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc
rows.push(Widget::horiz_separator(ctx, 0.3).margin_above(10));
rows.push(options_to_controls(ctx, &isochrone.options));
rows.push(Btn::text_bg1("Find your perfect home").build_def(ctx, None));
rows.push(
ctx.style()
.btn_primary_light_text("Find your perfect home")
.build_def(ctx),
);
rows.push(Widget::row(vec![
Btn::plaintext("About").build_def(ctx, None),
Btn::svg_def("system/assets/tools/search.svg").build(ctx, "search", lctrl(Key::F)),

View File

@ -1,8 +1,7 @@
use map_gui::theme::StyledButtons;
use map_gui::tools::grey_out_map;
use widgetry::{
hotkeys, Btn, Color, ControlState, DrawBaselayer, EventCtx, GeomBatch, GfxCtx, Key, Line,
Outcome, Panel, State, Text, Widget,
hotkeys, Color, ControlState, DrawBaselayer, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome,
Panel, State, StyledButtons, Text, Widget,
};
use crate::app::App;
@ -290,8 +289,10 @@ impl FYI {
panel: Panel::new(
Widget::custom_col(vec![
contents,
Btn::txt("Okay", Text::from(Line("Okay").fg(Color::BLACK)))
.build_def(ctx, hotkeys(vec![Key::Escape, Key::Space, Key::Enter]))
ctx.style()
.btn_primary_dark_text("Okay")
.hotkey(hotkeys(vec![Key::Escape, Key::Space, Key::Enter]))
.build_def(ctx)
.centered_horiz()
.align_bottom(),
])

View File

@ -60,17 +60,18 @@ impl<A: AppLike + 'static> CityPicker<A> {
for (name, polygon) in city.regions {
let color = app.cs().rotating_color_agents(regions.len());
let btn = Btn::txt(
name.path(),
Text::from(Line(nice_map_name(&name)).fg(color)),
)
.no_tooltip();
let btn = ctx
.style()
.btn_secondary_light_text(nice_map_name(&name))
.label_color(color, ControlState::Default)
.no_tooltip();
let action = name.path();
if &name == app.map().get_name() {
this_city.push(btn.inactive(ctx));
batch.push(color.alpha(0.5), polygon.clone());
let btn = btn.disabled();
this_city.push(btn.build_widget(ctx, &action));
} else {
this_city.push(btn.build_def(ctx, None));
this_city.push(btn.build_widget(ctx, &action));
batch.push(color, polygon.to_outline(Distance::meters(200.0)).unwrap());
regions.push((name, color, polygon.scale(zoom)));
}

View File

@ -12,8 +12,8 @@ use map_gui::{SimpleApp, ID};
use map_model::osm;
use widgetry::{
lctrl, Btn, Checkbox, Color, DrawBaselayer, Drawable, EventCtx, GeomBatch, GfxCtx,
HorizontalAlignment, Key, Line, Outcome, Panel, State, Text, TextExt, Transition,
VerticalAlignment, Widget,
HorizontalAlignment, Key, Line, Outcome, Panel, State, StyledButtons, Text, TextExt,
Transition, VerticalAlignment, Widget,
};
type App = SimpleApp<()>;

View File

@ -2,7 +2,7 @@ use geom::Percent;
use map_gui::tools::open_browser;
use widgetry::{
Btn, Color, EdgeInsets, EventCtx, GeomBatch, GfxCtx, Key, Line, Panel, RewriteColor,
SimpleState, State, Text, TextExt, Widget,
SimpleState, State, StyledButtons, Text, TextExt, Widget,
};
use crate::levels::Level;
@ -51,11 +51,13 @@ impl TitleScreen {
.centered_horiz(),
Widget::custom_row(level_buttons).flex_wrap(ctx, Percent::int(80)),
Widget::row(vec![
Btn::text_bg1("Credits").build_def(ctx, None),
ctx.style().btn_primary_light_text("Credits").build_def(ctx),
"Created by Dustin Carlino, Yuwen Li, & Michael Kirk"
.draw_text(ctx)
.container()
.padding(16)
.padding(6)
// cheat this to lineup with button text
.padding_bottom(2)
.bg(app.cs.fade_map_dark),
])
.centered_horiz()

View File

@ -68,7 +68,7 @@ impl Style {
fg_disabled: hex("#F2F2F2").alpha(0.3),
bg: Color::CLEAR,
bg_hover: hex("#F2F2F2").alpha(0.1),
bg_disabled: Color::grey(0.9),
bg_disabled: Color::grey(0.5),
outline: hex("#F2F2F2"),
},
btn_primary_destructive: ButtonStyle {

View File

@ -180,10 +180,6 @@ impl Btn {
BtnBuilder::TextFG(action.clone(), Text::from(Line(action)), None)
}
pub fn txt<I: Into<String>>(action: I, txt: Text) -> BtnBuilder {
BtnBuilder::TextFG(action.into(), txt, None)
}
pub fn text_bg<I: Into<String>>(
action: I,
text: Text,

View File

@ -1,6 +1,7 @@
use crate::{
Btn, Button, Color, EventCtx, GeomBatch, GfxCtx, Line, MultiKey, Outcome, RewriteColor,
ScreenDims, ScreenPt, Text, TextExt, TextSpan, Widget, WidgetImpl, WidgetOutput,
Btn, Button, Color, ControlState, EventCtx, GeomBatch, GfxCtx, Line, MultiKey, Outcome,
RewriteColor, ScreenDims, ScreenPt, StyledButtons, Text, TextExt, TextSpan, Widget, WidgetImpl,
WidgetOutput,
};
pub struct Checkbox {
@ -101,18 +102,27 @@ impl Checkbox {
enabled: bool,
) -> Widget {
let label = label.into();
let hotkey = hotkey.into();
// TODO: get an svg checkbox! and use a image+text button
let mut off = vec![Line("[ ] ")];
let mut on = vec![Line("[X] ")];
off.extend(spans.clone());
on.extend(spans);
let mut button = ctx.style().btn_secondary_light();
if let Some(hotkey) = hotkey.into() {
button = button.hotkey(hotkey);
}
Checkbox::new(
enabled,
Btn::txt(&label, Text::from_all(off)).build_def(ctx, hotkey.clone()),
Btn::txt(&label, Text::from_all(on)).build_def(ctx, hotkey),
button
.clone()
.label_styled_text(Text::from_all(off), ControlState::Default)
.build_widget(ctx, &label),
button
.label_styled_text(Text::from_all(on), ControlState::Default)
.build_widget(ctx, &label),
)
.outline(ctx.style().outline_thickness, ctx.style().outline_color)
.named(label)
}

View File

@ -375,8 +375,14 @@ fn make_controls(ctx: &mut EventCtx) -> Panel {
Widget::row(vec![
Checkbox::new(
false,
Btn::text_bg1("Pause").build(ctx, "pause the stopwatch", Key::Space),
Btn::text_bg1("Resume").build(ctx, "resume the stopwatch", Key::Space),
ctx.style()
.btn_primary_light_text("Pause")
.hotkey(Key::Space)
.build_widget(ctx, "pause the stopwatch"),
ctx.style()
.btn_primary_light_text("Resume")
.hotkey(Key::Space)
.build_widget(ctx, "resume the stopwatch"),
)
.named("paused"),
PersistentSplit::widget(