use underlining to refer to edits, not quotes. only in some places. :\

This commit is contained in:
Dustin Carlino 2020-06-26 14:13:12 -07:00
parent bfd1b9c190
commit 16beebd1de
10 changed files with 66 additions and 23 deletions

View File

@ -47,6 +47,7 @@ pub struct TextSpan {
fg_color: Color,
size: usize,
font: Font,
underlined: bool,
}
impl TextSpan {
@ -99,6 +100,11 @@ impl TextSpan {
self.size = 16;
self
}
pub fn underlined(mut self) -> TextSpan {
self.underlined = true;
self
}
}
// TODO What's the better way of doing this? Also "Line" is a bit of a misnomer
@ -109,6 +115,7 @@ pub fn Line<S: Into<String>>(text: S) -> TextSpan {
fg_color: DEFAULT_FG_COLOR,
size: DEFAULT_FONT_SIZE,
font: DEFAULT_FONT,
underlined: false,
}
}
@ -351,6 +358,7 @@ impl Text {
size: span.size,
font: span.font,
fg_color: span.fg_color,
underlined: false,
}],
svg::LOW_QUALITY,
assets,
@ -408,9 +416,14 @@ fn render_line(spans: Vec<TextSpan>, tolerance: f32, assets: &Assets) -> GeomBat
for span in spans {
write!(
&mut contents,
r##"<tspan fill="{}">{}</tspan>"##,
r##"<tspan fill="{}" {}>{}</tspan>"##,
// TODO Doesn't support alpha
span.fg_color.to_hex(),
if span.underlined {
"text-decoration=\"underline\""
} else {
""
},
htmlescape::encode_minimal(&span.text)
)
.unwrap();

View File

@ -1,6 +1,6 @@
use crate::{
svg, Color, Drawable, EventCtx, GeomBatch, GfxCtx, JustDraw, Line, MultiKey, Outcome,
RewriteColor, ScreenDims, ScreenPt, Text, TextSpan, Widget, WidgetImpl, WidgetOutput,
RewriteColor, ScreenDims, ScreenPt, Text, Widget, WidgetImpl, WidgetOutput,
};
use geom::Polygon;
@ -147,9 +147,8 @@ impl Btn {
BtnBuilder::TextFG(label.clone(), Text::from(Line(label)), None)
}
pub fn text_fg_line<I: Into<String>>(label: I, line: TextSpan) -> BtnBuilder {
let label = label.into();
BtnBuilder::TextFG(label.clone(), Text::from(line), None)
pub fn txt<I: Into<String>>(label: I, txt: Text) -> BtnBuilder {
BtnBuilder::TextFG(label.into(), txt, None)
}
pub fn text_bg<I: Into<String>>(

View File

@ -1,6 +1,6 @@
use crate::{
Btn, Button, Color, EventCtx, GeomBatch, GfxCtx, MultiKey, ScreenDims, ScreenPt, Widget,
WidgetImpl, WidgetOutput,
Btn, Button, Color, EventCtx, GeomBatch, GfxCtx, Line, MultiKey, ScreenDims, ScreenPt, Text,
TextSpan, Widget, WidgetImpl, WidgetOutput,
};
use geom::{Polygon, Pt2D};
@ -44,6 +44,28 @@ impl Checkbox {
.named(label)
}
pub fn custom_text<I: Into<String>>(
ctx: &EventCtx,
label: I,
spans: Vec<TextSpan>,
hotkey: Option<MultiKey>,
enabled: bool,
) -> Widget {
let label = label.into();
let mut off = vec![Line("[ ] ")];
let mut on = vec![Line("[X] ")];
off.extend(spans.clone());
on.extend(spans);
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),
)
.outline(ctx.style().outline_thickness, ctx.style().outline_color)
.named(label)
}
pub fn colored(ctx: &EventCtx, label: &str, color: Color, enabled: bool) -> Widget {
let vert_pad = 4.0;
let horiz_pad = 4.0;

View File

@ -61,7 +61,7 @@ impl CityPicker {
let mut this_city = vec![];
for name in abstutil::list_all_objects(abstutil::path_all_maps()) {
if let Some((_, color, _)) = regions.iter().find(|(n, _, _)| &name == n) {
let btn = Btn::text_fg_line(&name, Line(nice_map_name(&name)).fg(*color))
let btn = Btn::txt(&name, Text::from(Line(nice_map_name(&name)).fg(*color)))
.tooltip(Text::new());
this_city.push(
if &name == app.primary.map.get_name() {
@ -73,9 +73,9 @@ impl CityPicker {
);
} else {
other_cities.push(
Btn::text_fg(nice_map_name(&name))
Btn::txt(&name, Text::from(Line(nice_map_name(&name))))
.tooltip(Text::new())
.build(ctx, name, None)
.build_def(ctx, None)
.margin_below(5),
);
}

View File

@ -184,7 +184,7 @@ fn make_panel(
let inner = if idx == scenes.len() {
Widget::col(vec![
(make_task)(ctx),
Btn::text_fg_line("Start", Line("Start").fg(Color::BLACK))
Btn::txt("Start", Text::from(Line("Start").fg(Color::BLACK)))
.build_def(ctx, hotkey(Key::Enter))
.centered_horiz()
.align_bottom(),
@ -225,9 +225,12 @@ fn make_panel(
Widget::row(vec![prev.margin_right(15), next])
.centered_horiz()
.margin_below(10),
Btn::text_fg_line("Skip cutscene", Line("Skip cutscene").fg(Color::BLACK))
.build_def(ctx, None)
.centered_horiz(),
Btn::txt(
"Skip cutscene",
Text::from(Line("Skip cutscene").fg(Color::BLACK)),
)
.build_def(ctx, None)
.centered_horiz(),
])
.align_bottom(),
])
@ -264,7 +267,7 @@ impl FYI {
composite: Composite::new(
Widget::col(vec![
contents,
Btn::text_fg_line("Okay", Line("Okay").fg(Color::BLACK))
Btn::txt("Okay", Text::from(Line("Okay").fg(Color::BLACK)))
.build_def(ctx, hotkeys(vec![Key::Escape, Key::Space, Key::Enter]))
.centered_horiz()
.align_bottom(),

View File

@ -58,7 +58,7 @@ pub fn traffic(
)));
rows.push(txt.draw(ctx));
rows.push(opts.to_controls(ctx, app).margin_below(10));
rows.push(opts.to_controls(ctx, app).margin_below(15));
let time = if opts.show_end_of_day {
app.primary.sim.get_end_of_day()

View File

@ -177,7 +177,7 @@ pub fn traffic(
)));
rows.push(txt.draw(ctx));
rows.push(opts.to_controls(ctx, app).margin_below(10));
rows.push(opts.to_controls(ctx, app).margin_below(15));
let r = map.get_l(id).parent;
let time = if opts.show_end_of_day {

View File

@ -614,13 +614,16 @@ impl DataOptions {
return Widget::nothing();
}
Widget::row(vec![
Checkbox::text(
Checkbox::custom_text(
ctx,
format!("Show before \"{}\"", app.primary.map.get_edits().edits_name),
"Show before changes",
vec![
Line("Show before "),
Line(&app.primary.map.get_edits().edits_name).underlined(),
],
None,
self.show_before,
)
.named("Show before changes"),
),
if self.show_before {
Checkbox::text(ctx, "Show full day", None, self.show_end_of_day)
} else {

View File

@ -234,7 +234,8 @@ pub fn finished(
Text::from_all(vec![
Line("After / "),
Line("Before").secondary(),
Line(format!(" \"{}\"", app.primary.map.get_edits().edits_name)),
Line(" "),
Line(&app.primary.map.get_edits().edits_name).underlined(),
]),
app.cs.section_bg,
app.cs.hovering,
@ -254,7 +255,8 @@ pub fn finished(
Text::from_all(vec![
Line("After / ").secondary(),
Line("Before"),
Line(format!(" \"{}\"", app.primary.map.get_edits().edits_name)),
Line(" "),
Line(&app.primary.map.get_edits().edits_name).underlined(),
]),
app.cs.section_bg,
app.cs.hovering,

View File

@ -582,6 +582,7 @@ impl State for TimeWarpScreen {
Duration::realtime_elapsed(self.started)
)),
if let Some(n) = finished_before {
// TODO Underline
Line(format!(
"Finished trips: {} ({} compared to before \"{}\")",
prettyprint_usize(finished_after),