mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
change how inactive buttons are created, finally completing the grand button refactor
This commit is contained in:
parent
b3028fd69c
commit
1abddda18b
@ -32,7 +32,8 @@ pub use crate::runner::{run, EventLoopMode, Settings, GUI};
|
||||
pub use crate::screen_geom::{ScreenDims, ScreenPt, ScreenRectangle};
|
||||
pub use crate::text::{Line, Text, TextExt, TextSpan, HOTKEY_COLOR};
|
||||
pub use crate::widgets::autocomplete::Autocomplete;
|
||||
pub use crate::widgets::button::{Btn, Button};
|
||||
pub use crate::widgets::button::Btn;
|
||||
pub(crate) use crate::widgets::button::Button;
|
||||
pub use crate::widgets::checkbox::Checkbox;
|
||||
pub(crate) use crate::widgets::dropdown::Dropdown;
|
||||
pub use crate::widgets::filler::Filler;
|
||||
|
@ -117,51 +117,6 @@ impl WidgetImpl for Button {
|
||||
}
|
||||
}
|
||||
|
||||
// Stuff to construct different types of buttons
|
||||
|
||||
// TODO Simplify all of these APIs!
|
||||
impl Button {
|
||||
// TODO Extreme wackiness.
|
||||
pub fn inactive_button<S: Into<String>>(ctx: &mut EventCtx, label: S) -> Widget {
|
||||
let txt_batch = Text::from(Line(label).fg(Color::grey(0.5))).render_ctx(ctx);
|
||||
let dims = txt_batch.get_dims();
|
||||
|
||||
let horiz_padding = 15.0;
|
||||
let vert_padding = 8.0;
|
||||
let mut batch = GeomBatch::new();
|
||||
batch.add_translated(txt_batch, horiz_padding, vert_padding);
|
||||
Widget::just_draw(JustDraw {
|
||||
draw: ctx.upload(batch),
|
||||
top_left: ScreenPt::new(0.0, 0.0),
|
||||
dims: ScreenDims::new(
|
||||
dims.width + 2.0 * horiz_padding,
|
||||
dims.height + 2.0 * vert_padding,
|
||||
),
|
||||
})
|
||||
.outline(2.0, Color::WHITE)
|
||||
}
|
||||
// With a background
|
||||
pub fn inactive_selected_button<S: Into<String>>(ctx: &EventCtx, label: S) -> Widget {
|
||||
const HORIZ_PADDING: f64 = 30.0;
|
||||
const VERT_PADDING: f64 = 10.0;
|
||||
|
||||
let txt = Text::from(Line(label).fg(Color::BLACK)).render_ctx(ctx);
|
||||
let dims = txt.get_dims();
|
||||
let mut batch = GeomBatch::from(vec![(
|
||||
Color::WHITE,
|
||||
Polygon::rounded_rectangle(
|
||||
dims.width + 2.0 * HORIZ_PADDING,
|
||||
dims.height + 2.0 * VERT_PADDING,
|
||||
VERT_PADDING,
|
||||
),
|
||||
)]);
|
||||
batch.add_translated(txt, HORIZ_PADDING, VERT_PADDING);
|
||||
JustDraw::wrap(ctx, batch)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Experimental new refactoring
|
||||
|
||||
pub struct Btn {}
|
||||
|
||||
impl Btn {
|
||||
@ -386,4 +341,35 @@ impl BtnBuilder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inactive(mut self, ctx: &EventCtx) -> Widget {
|
||||
match self {
|
||||
BtnBuilder::TextFG(_, txt, _) => {
|
||||
let btn = Btn::custom_text_fg(txt.change_fg(Color::grey(0.5)))
|
||||
.build(ctx, "dummy", None)
|
||||
.take_btn();
|
||||
Widget::just_draw(JustDraw {
|
||||
draw: btn.draw_normal,
|
||||
top_left: btn.top_left,
|
||||
dims: btn.dims,
|
||||
})
|
||||
.outline(2.0, Color::WHITE)
|
||||
}
|
||||
// TODO This'll only work reasonably for text_bg2
|
||||
BtnBuilder::TextBG {
|
||||
ref mut unselected_bg_color,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(*unselected_bg_color, Color::WHITE);
|
||||
*unselected_bg_color = Color::grey(0.5);
|
||||
let btn = self.build(ctx, "dummy", None).take_btn();
|
||||
Widget::just_draw(JustDraw {
|
||||
draw: btn.draw_normal,
|
||||
top_left: btn.top_left,
|
||||
dims: btn.dims,
|
||||
})
|
||||
}
|
||||
_ => panic!("Can't use inactive on this kind of button"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use crate::game::{State, Transition};
|
||||
use crate::managed::{Callback, ManagedGUIState, WrappedComposite};
|
||||
use crate::sandbox::{GameplayMode, SandboxMode, TutorialState};
|
||||
use abstutil::Timer;
|
||||
use ezgui::{hotkey, Btn, Button, Color, Composite, EventCtx, Key, Line, Text, Widget};
|
||||
use ezgui::{hotkey, Btn, Color, Composite, EventCtx, Key, Line, Text, Widget};
|
||||
use geom::{Duration, Time};
|
||||
use map_model::Map;
|
||||
use sim::{Scenario, Sim, SimFlags, SimOptions, TripMode};
|
||||
@ -157,7 +157,7 @@ impl Tab {
|
||||
Tab::ChallengeStage(ref n, _) => &name == n,
|
||||
};
|
||||
if current {
|
||||
flex_row.push(Button::inactive_button(ctx, name).margin(10));
|
||||
flex_row.push(Btn::text_bg2(&name).inactive(ctx).margin(10));
|
||||
} else {
|
||||
flex_row.push(
|
||||
Btn::text_bg2(&name)
|
||||
@ -195,7 +195,7 @@ impl Tab {
|
||||
.enumerate()
|
||||
{
|
||||
if current == idx {
|
||||
col.push(Button::inactive_button(ctx, &stage.title).margin(10));
|
||||
col.push(Btn::text_fg(&stage.title).inactive(ctx).margin(10));
|
||||
} else {
|
||||
col.push(Btn::text_fg(&stage.title).build_def(ctx, None).margin(10));
|
||||
let name = name.to_string();
|
||||
|
@ -8,7 +8,7 @@ use crate::managed::{ManagedGUIState, WrappedComposite, WrappedOutcome};
|
||||
use crate::render::MIN_ZOOM_FOR_DETAIL;
|
||||
use abstutil::{prettyprint_usize, Counter};
|
||||
use ezgui::{
|
||||
hotkey, Btn, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, Histogram,
|
||||
hotkey, Btn, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, Histogram,
|
||||
HorizontalAlignment, JustDraw, Key, Line, Outcome, Plot, PlotOptions, RewriteColor, Series,
|
||||
Text, TextExt, VerticalAlignment, Widget,
|
||||
};
|
||||
@ -275,7 +275,7 @@ impl Overlays {
|
||||
} {
|
||||
for btn in &mut choices {
|
||||
if btn.is_btn(name) {
|
||||
*btn = Button::inactive_button(ctx, name).outline(2.0, Color::GREEN);
|
||||
*btn = Btn::text_fg(name).inactive(ctx).outline(2.0, Color::GREEN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ use crate::game::{DrawBaselayer, State, Transition};
|
||||
use crate::helpers::ID;
|
||||
use crate::render::{dashed_lines, draw_signal_phase, make_signal_diagram, DrawOptions, DrawTurn};
|
||||
use ezgui::{
|
||||
hotkey, Btn, Button, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx,
|
||||
HorizontalAlignment, Key, Line, Outcome, Text, VerticalAlignment, Widget,
|
||||
hotkey, Btn, Color, Composite, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key,
|
||||
Line, Outcome, Text, VerticalAlignment, Widget,
|
||||
};
|
||||
use geom::{Distance, Polygon, Time};
|
||||
use map_model::{IntersectionID, LaneID, TurnType};
|
||||
@ -267,13 +267,13 @@ impl TurnExplorer {
|
||||
.margin(5)
|
||||
.centered_vert(),
|
||||
if idx == 0 {
|
||||
Button::inactive_button(ctx, "<")
|
||||
Btn::text_fg("<").inactive(ctx)
|
||||
} else {
|
||||
Btn::text_fg("<").build(ctx, "previous turn", hotkey(Key::LeftArrow))
|
||||
}
|
||||
.margin(5),
|
||||
if idx == num_turns {
|
||||
Button::inactive_button(ctx, ">")
|
||||
Btn::text_fg(">").inactive(ctx)
|
||||
} else {
|
||||
Btn::text_fg(">").build(ctx, "next turn", hotkey(Key::RightArrow))
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ use crate::game::{msg, State, Transition, WizardState};
|
||||
use crate::helpers::ID;
|
||||
use crate::render::Renderable;
|
||||
use ezgui::{
|
||||
hotkey, Btn, Button, Choice, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key,
|
||||
Outcome, RewriteColor, TextExt, VerticalAlignment, Widget,
|
||||
hotkey, Btn, Choice, Color, Composite, EventCtx, GfxCtx, HorizontalAlignment, Key, Outcome,
|
||||
RewriteColor, TextExt, VerticalAlignment, Widget,
|
||||
};
|
||||
use map_model::{EditCmd, LaneID, LaneType, Map, RoadID};
|
||||
use std::collections::BTreeSet;
|
||||
@ -92,7 +92,7 @@ impl LaneEditor {
|
||||
{
|
||||
Btn::text_fg("Revert").build_def(ctx, hotkey(Key::R))
|
||||
} else {
|
||||
Button::inactive_button(ctx, "Revert")
|
||||
Btn::text_fg("Revert").inactive(ctx)
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -16,9 +16,9 @@ use crate::render::{DrawIntersection, DrawLane, DrawRoad, MIN_ZOOM_FOR_DETAIL};
|
||||
use crate::sandbox::{GameplayMode, SandboxMode};
|
||||
use abstutil::Timer;
|
||||
use ezgui::{
|
||||
hotkey, lctrl, Btn, Button, Choice, Color, Composite, EventCtx, GeomBatch, GfxCtx,
|
||||
HorizontalAlignment, Key, Line, Outcome, RewriteColor, ScreenRectangle, Text,
|
||||
VerticalAlignment, Widget, WrappedWizard,
|
||||
hotkey, lctrl, Btn, Choice, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment,
|
||||
Key, Line, Outcome, RewriteColor, ScreenRectangle, Text, VerticalAlignment, Widget,
|
||||
WrappedWizard,
|
||||
};
|
||||
use geom::Polygon;
|
||||
use map_model::{
|
||||
@ -371,10 +371,11 @@ fn make_topcenter(ctx: &mut EventCtx, app: &App) -> Composite {
|
||||
})
|
||||
.margin(15),
|
||||
if !app.primary.map.get_edits().commands.is_empty() {
|
||||
Btn::text_fg("reset edits").build_def(ctx, None).margin(5)
|
||||
Btn::text_fg("reset edits").build_def(ctx, None)
|
||||
} else {
|
||||
Button::inactive_button(ctx, "reset edits").margin(5)
|
||||
},
|
||||
Btn::text_fg("reset edits").inactive(ctx)
|
||||
}
|
||||
.margin(5),
|
||||
])
|
||||
.centered(),
|
||||
Btn::text_fg("finish editing")
|
||||
|
@ -6,8 +6,8 @@ use crate::game::{State, Transition};
|
||||
use crate::render::DrawIntersection;
|
||||
use abstutil::Timer;
|
||||
use ezgui::{
|
||||
hotkey, Btn, Button, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key,
|
||||
Line, Outcome, Text, TextExt, VerticalAlignment, Widget,
|
||||
hotkey, Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, Line,
|
||||
Outcome, Text, TextExt, VerticalAlignment, Widget,
|
||||
};
|
||||
use geom::Polygon;
|
||||
use map_model::{
|
||||
@ -57,7 +57,7 @@ impl StopSignEditor {
|
||||
{
|
||||
Btn::text_fg("reset to default").build_def(ctx, hotkey(Key::R))
|
||||
} else {
|
||||
Button::inactive_button(ctx, "reset to default")
|
||||
Btn::text_fg("reset to default").inactive(ctx)
|
||||
},
|
||||
Btn::text_fg("close intersection for construction").build_def(ctx, None),
|
||||
Btn::text_fg("convert to traffic signal").build_def(ctx, None),
|
||||
|
@ -9,8 +9,8 @@ use crate::sandbox::SandboxMode;
|
||||
use abstutil::prettyprint_usize;
|
||||
use abstutil::Counter;
|
||||
use ezgui::{
|
||||
hotkey, Btn, Button, Color, Composite, EventCtx, Histogram, Key, Line, Plot, PlotOptions,
|
||||
Series, Text, TextExt, Widget,
|
||||
hotkey, Btn, Color, Composite, EventCtx, Histogram, Key, Line, Plot, PlotOptions, Series, Text,
|
||||
TextExt, Widget,
|
||||
};
|
||||
use geom::{Duration, Statistic, Time};
|
||||
use map_model::BusRouteID;
|
||||
@ -41,9 +41,9 @@ pub fn make(ctx: &mut EventCtx, app: &App, tab: Tab) -> Box<dyn State> {
|
||||
.iter()
|
||||
.map(|(t, label)| {
|
||||
if *t == tab {
|
||||
Button::inactive_selected_button(ctx, *label)
|
||||
Btn::text_bg2(*label).inactive(ctx)
|
||||
} else {
|
||||
Btn::text_fg(*label).build_def(ctx, None)
|
||||
Btn::text_bg2(*label).build_def(ctx, None)
|
||||
}
|
||||
.margin(5)
|
||||
})
|
||||
|
@ -11,7 +11,7 @@ use crate::sandbox::{
|
||||
};
|
||||
use abstutil::Timer;
|
||||
use ezgui::{
|
||||
hotkey, hotkeys, lctrl, Btn, Button, Color, Composite, EventCtx, GeomBatch, GfxCtx,
|
||||
hotkey, hotkeys, lctrl, Btn, Color, Composite, EventCtx, GeomBatch, GfxCtx,
|
||||
HorizontalAlignment, Key, Line, Outcome, RewriteColor, ScreenPt, Text, TextExt,
|
||||
VerticalAlignment, Widget,
|
||||
};
|
||||
@ -894,7 +894,7 @@ impl TutorialState {
|
||||
)
|
||||
.margin(5),
|
||||
if self.current.stage == 0 {
|
||||
Button::inactive_button(ctx, "<")
|
||||
Btn::text_fg("<").inactive(ctx)
|
||||
} else {
|
||||
Btn::text_fg("<").build(ctx, "previous tutorial", None)
|
||||
}
|
||||
@ -906,7 +906,7 @@ impl TutorialState {
|
||||
txt.draw(ctx).margin(5)
|
||||
},
|
||||
if self.current.stage == self.latest.stage {
|
||||
Button::inactive_button(ctx, ">")
|
||||
Btn::text_fg(">").inactive(ctx)
|
||||
} else {
|
||||
Btn::text_fg(">").build(ctx, "next tutorial", None)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user