mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
remove the last button constructor, except for the inactive ones
This commit is contained in:
parent
7592a36fe4
commit
9644ff24be
@ -263,7 +263,7 @@ impl ManagedWidget {
|
||||
JustDraw::svg_transform(ctx, filename, rewrite)
|
||||
}
|
||||
|
||||
pub fn btn(btn: Button) -> ManagedWidget {
|
||||
pub(crate) fn btn(btn: Button) -> ManagedWidget {
|
||||
ManagedWidget::new(WidgetType::Btn(btn))
|
||||
}
|
||||
|
||||
@ -299,17 +299,10 @@ impl ManagedWidget {
|
||||
false_btn: ManagedWidget,
|
||||
true_btn: ManagedWidget,
|
||||
) -> ManagedWidget {
|
||||
fn take_btn(w: ManagedWidget) -> Button {
|
||||
match w.widget {
|
||||
WidgetType::Btn(btn) => btn,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
ManagedWidget::new(WidgetType::Checkbox(Checkbox::new(
|
||||
enabled,
|
||||
take_btn(false_btn),
|
||||
take_btn(true_btn),
|
||||
false_btn.take_btn(),
|
||||
true_btn.take_btn(),
|
||||
)))
|
||||
}
|
||||
|
||||
@ -752,6 +745,13 @@ impl ManagedWidget {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn take_btn(self) -> Button {
|
||||
match self.widget {
|
||||
WidgetType::Btn(btn) => btn,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Dims {
|
||||
|
@ -122,36 +122,6 @@ impl Widget for Button {
|
||||
|
||||
// TODO Simplify all of these APIs!
|
||||
impl Button {
|
||||
pub fn text_no_bg(
|
||||
unselected_text: Text,
|
||||
selected_text: Text,
|
||||
hotkey: Option<MultiKey>,
|
||||
tooltip: &str,
|
||||
padding: bool,
|
||||
ctx: &EventCtx,
|
||||
) -> Button {
|
||||
// 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 unselected_batch = unselected_text.render_ctx(ctx);
|
||||
let dims = unselected_batch.get_dims();
|
||||
let selected_batch = selected_text.render_ctx(ctx);
|
||||
assert_eq!(dims, selected_batch.get_dims());
|
||||
let geom = Polygon::rectangle(
|
||||
dims.width + 2.0 * horiz_padding,
|
||||
dims.height + 2.0 * vert_padding,
|
||||
);
|
||||
|
||||
let mut normal = GeomBatch::new();
|
||||
normal.add_translated(unselected_batch, horiz_padding, vert_padding);
|
||||
let mut hovered = GeomBatch::new();
|
||||
hovered.add_translated(selected_batch, horiz_padding, vert_padding);
|
||||
|
||||
Button::new(ctx, normal, hovered, hotkey, tooltip, geom)
|
||||
}
|
||||
|
||||
// TODO Extreme wackiness.
|
||||
pub fn inactive_button<S: Into<String>>(ctx: &mut EventCtx, label: S) -> ManagedWidget {
|
||||
let txt_batch = Text::from(Line(label).fg(Color::grey(0.5))).render_ctx(ctx);
|
||||
@ -339,14 +309,26 @@ impl BtnBuilder {
|
||||
ManagedWidget::btn(btn)
|
||||
}
|
||||
BtnBuilder::TextFG(_, normal_txt, maybe_t) => {
|
||||
let mut btn = Button::text_no_bg(
|
||||
normal_txt.clone(),
|
||||
normal_txt.change_fg(Color::ORANGE),
|
||||
key,
|
||||
&action_tooltip.into(),
|
||||
true,
|
||||
ctx,
|
||||
// TODO Padding here is unfortunate, but I don't understand when the flexbox padding
|
||||
// actually works.
|
||||
let horiz_padding = 15.0;
|
||||
let vert_padding = 8.0;
|
||||
|
||||
let unselected_batch = normal_txt.clone().render_ctx(ctx);
|
||||
let dims = unselected_batch.get_dims();
|
||||
let selected_batch = normal_txt.change_fg(Color::ORANGE).render_ctx(ctx);
|
||||
assert_eq!(dims, selected_batch.get_dims());
|
||||
let geom = Polygon::rectangle(
|
||||
dims.width + 2.0 * horiz_padding,
|
||||
dims.height + 2.0 * vert_padding,
|
||||
);
|
||||
|
||||
let mut normal = GeomBatch::new();
|
||||
normal.add_translated(unselected_batch, horiz_padding, vert_padding);
|
||||
let mut hovered = GeomBatch::new();
|
||||
hovered.add_translated(selected_batch, horiz_padding, vert_padding);
|
||||
|
||||
let mut btn = Button::new(ctx, normal, hovered, key, &action_tooltip.into(), geom);
|
||||
if let Some(t) = maybe_t {
|
||||
btn.tooltip = t;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::layout::Widget;
|
||||
use crate::widgets::PopupMenu;
|
||||
use crate::{
|
||||
Button, Choice, Color, EventCtx, GfxCtx, InputResult, Line, ScreenDims, ScreenPt,
|
||||
ScreenRectangle, Text,
|
||||
Btn, Button, Choice, Color, EventCtx, GfxCtx, InputResult, ScreenDims, ScreenPt,
|
||||
ScreenRectangle,
|
||||
};
|
||||
use geom::{Polygon, Pt2D};
|
||||
use std::any::Any;
|
||||
@ -126,13 +126,7 @@ impl Widget for Dropdown {
|
||||
}
|
||||
|
||||
fn make_btn(ctx: &EventCtx, name: &str, label: &str) -> Button {
|
||||
let txt = Text::from(Line(format!("{} ▼", name)));
|
||||
Button::text_no_bg(
|
||||
txt.clone(),
|
||||
txt.change_fg(Color::ORANGE),
|
||||
None,
|
||||
label,
|
||||
true,
|
||||
ctx,
|
||||
)
|
||||
Btn::text_fg(format!("{} ▼", name))
|
||||
.build(ctx, label, None)
|
||||
.take_btn()
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ use crate::helpers::ID;
|
||||
use crate::managed::{WrappedComposite, WrappedOutcome};
|
||||
use crate::sandbox::{GameplayMode, SandboxMode};
|
||||
use ezgui::{
|
||||
hotkey, Btn, Button, Color, Composite, EventCtx, EventLoopMode, GeomBatch, GfxCtx,
|
||||
HorizontalAlignment, Key, Line, ManagedWidget, Outcome, Plot, PlotOptions, RewriteColor,
|
||||
Series, Slider, Text, VerticalAlignment,
|
||||
hotkey, Btn, Color, Composite, EventCtx, EventLoopMode, GeomBatch, GfxCtx, HorizontalAlignment,
|
||||
Key, Line, ManagedWidget, Outcome, Plot, PlotOptions, RewriteColor, Series, Slider, Text,
|
||||
VerticalAlignment,
|
||||
};
|
||||
use geom::{Duration, Polygon, Time};
|
||||
use instant::Instant;
|
||||
@ -97,22 +97,31 @@ impl SpeedControls {
|
||||
row.push(
|
||||
ManagedWidget::row(
|
||||
vec![
|
||||
ManagedWidget::btn(Button::text_no_bg(
|
||||
Text::from(Line("+1h").fg(Color::WHITE).size(21).roboto()),
|
||||
Text::from(Line("+1h").fg(colors::HOVERING).size(21).roboto()),
|
||||
hotkey(Key::N),
|
||||
"step forwards 1 hour",
|
||||
false,
|
||||
ctx,
|
||||
)),
|
||||
ManagedWidget::btn(Button::text_no_bg(
|
||||
Text::from(Line("+0.1s").fg(Color::WHITE).size(21).roboto()),
|
||||
Text::from(Line("+0.1s").fg(colors::HOVERING).size(21).roboto()),
|
||||
hotkey(Key::M),
|
||||
"step forwards 0.1 seconds",
|
||||
false,
|
||||
ctx,
|
||||
)),
|
||||
Btn::custom(
|
||||
Text::from(Line("+1h").fg(Color::WHITE).size(21).roboto()).render_ctx(ctx),
|
||||
Text::from(Line("+1h").fg(colors::HOVERING).size(21).roboto())
|
||||
.render_ctx(ctx),
|
||||
{
|
||||
let dims = Text::from(Line("+1h").size(21).roboto())
|
||||
.render_ctx(ctx)
|
||||
.get_dims();
|
||||
Polygon::rectangle(dims.width, dims.height)
|
||||
},
|
||||
)
|
||||
.build(ctx, "step forwards 1 hour", hotkey(Key::N)),
|
||||
Btn::custom(
|
||||
Text::from(Line("+0.1s").fg(Color::WHITE).size(21).roboto())
|
||||
.render_ctx(ctx),
|
||||
Text::from(Line("+0.1s").fg(colors::HOVERING).size(21).roboto())
|
||||
.render_ctx(ctx),
|
||||
{
|
||||
let dims = Text::from(Line("+0.1s").size(21).roboto())
|
||||
.render_ctx(ctx)
|
||||
.get_dims();
|
||||
Polygon::rectangle(dims.width, dims.height)
|
||||
},
|
||||
)
|
||||
.build(ctx, "step forwards 0.1 seconds", hotkey(Key::M)),
|
||||
Btn::svg_def("../data/system/assets/speed/jump_to_time.svg").build(
|
||||
ctx,
|
||||
"jump to specific time",
|
||||
|
Loading…
Reference in New Issue
Block a user