slightly refactoring Text creation

This commit is contained in:
Dustin Carlino 2019-05-01 11:42:14 -07:00
parent b2b7d0767c
commit 1eb1b0ea40
11 changed files with 19 additions and 33 deletions

View File

@ -66,8 +66,7 @@ impl ABTestMode {
return evmode;
}
let mut txt = Text::new();
txt.add_styled_line("A/B Test Mode".to_string(), None, Some(Color::BLUE), None);
let mut txt = Text::prompt("A/B Test Mode");
txt.add_line(state.ui.primary.map.get_edits().edits_name.clone());
if let Some(ref diff) = mode.diff_trip {
txt.add_line(format!("Showing diff for {}", diff.trip));

View File

@ -72,13 +72,7 @@ impl DebugMode {
return evmode;
}
let mut txt = Text::new();
txt.add_styled_line(
"Debug Mode".to_string(),
None,
Some(Color::BLUE),
None,
);
let mut txt = Text::prompt("Debug Mode");
if mode.chokepoints.is_some() {
txt.add_line("Showing chokepoints".to_string());
}

View File

@ -31,8 +31,7 @@ impl EditMode {
ctx.canvas.handle_event(ctx.input);
// Common functionality
let mut txt = Text::new();
txt.add_styled_line("Map Edit Mode".to_string(), None, Some(Color::BLUE), None);
let mut txt = Text::prompt("Map Edit Mode");
txt.add_line(state.ui.primary.map.get_edits().edits_name.clone());
txt.add_line(state.ui.primary.map.get_edits().describe());
txt.add_line("Right-click a lane or intersection to start editing".to_string());

View File

@ -8,7 +8,7 @@ use crate::game::{GameState, Mode};
use crate::render::DrawOptions;
use crate::ui::ShowEverything;
use abstutil::elapsed_seconds;
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard};
use ezgui::{EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard};
use geom::Duration;
use sim::{Benchmark, Sim, TripID};
use std::time::Instant;
@ -79,8 +79,7 @@ impl SandboxMode {
return EventLoopMode::InputOnly;
}
let mut txt = Text::new();
txt.add_styled_line("Sandbox Mode".to_string(), None, Some(Color::BLUE), None);
let mut txt = Text::prompt("Sandbox Mode");
txt.add_line(state.ui.primary.sim.summary());
if let State::Running { ref speed, .. } = mode.state {
txt.add_line(format!(

View File

@ -1,7 +1,7 @@
use crate::game::{GameState, Mode};
use crate::render::DrawOptions;
use crate::ui::ShowEverything;
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard};
use ezgui::{EventCtx, EventLoopMode, GfxCtx, Key, Text, Wizard};
use geom::Pt2D;
// Does CommonState make sense?
@ -14,8 +14,7 @@ impl TutorialMode {
pub fn event(state: &mut GameState, ctx: &mut EventCtx) -> EventLoopMode {
ctx.canvas.handle_event(ctx.input);
let mut txt = Text::new();
txt.add_styled_line("Tutorial".to_string(), None, Some(Color::BLUE), None);
let mut txt = Text::prompt("Tutorial");
match state.mode {
Mode::Tutorial(TutorialMode::Part1(orig_center)) => {
txt.add_line("Click and drag to pan around".to_string());

View File

@ -252,9 +252,7 @@ impl UserInput {
prompt: String,
canvas: &Canvas,
) -> ScreenPt {
let mut txt = Text::new();
txt.add_styled_line(prompt, None, Some(text::PROMPT_COLOR), None);
self.set_mode_with_new_prompt(mode, txt, canvas)
self.set_mode_with_new_prompt(mode, Text::prompt(&prompt), canvas)
}
pub fn set_mode_with_new_prompt(

View File

@ -51,6 +51,12 @@ impl Text {
}
}
pub fn prompt(line: &str) -> Text {
let mut txt = Text::new();
txt.add_styled_line(line.to_string(), None, Some(PROMPT_COLOR), None);
txt
}
pub fn with_bg_color(bg_color: Option<Color>) -> Text {
Text {
lines: Vec::new(),

View File

@ -54,8 +54,7 @@ impl<T: Clone + Hash + Eq> Autocomplete<T> {
}
pub fn draw(&self, g: &mut GfxCtx) {
let mut txt = Text::new();
txt.add_styled_line(self.prompt.clone(), None, Some(text::PROMPT_COLOR), None);
let mut txt = Text::prompt(&self.prompt);
txt.add_line(self.line[0..self.cursor_x].to_string());
if self.cursor_x < self.line.len() {

View File

@ -48,8 +48,7 @@ impl<T: Clone> ScrollingMenu<T> {
}
pub fn draw(&self, g: &mut GfxCtx) {
let mut txt = Text::new();
txt.add_styled_line(self.prompt.clone(), None, Some(text::PROMPT_COLOR), None);
let mut txt = Text::prompt(&self.prompt);
// TODO Silly results from doing this:
// - The menu width changes as we scroll

View File

@ -22,8 +22,7 @@ impl TextBox {
}
pub fn draw(&self, g: &mut GfxCtx) {
let mut txt = Text::new();
txt.add_styled_line(self.prompt.clone(), None, Some(text::PROMPT_COLOR), None);
let mut txt = Text::prompt(&self.prompt);
txt.add_line(self.line[0..self.cursor_x].to_string());
if self.cursor_x < self.line.len() {

View File

@ -1,5 +1,5 @@
use crate::widgets::{Menu, Position};
use crate::{text, Canvas, GfxCtx, InputResult, Key, LogScroller, Text, TextBox, UserInput};
use crate::{Canvas, GfxCtx, InputResult, Key, LogScroller, Text, TextBox, UserInput};
use abstutil::Cloneable;
use std::collections::VecDeque;
@ -212,12 +212,7 @@ impl<'a> WrappedWizard<'a> {
.map(|(key, s, item)| (key, s, item.clone_box()))
.collect();
self.wizard.menu = Some(Menu::new(
Some(Text::from_styled_line(
query.to_string(),
None,
Some(text::PROMPT_COLOR),
None,
)),
Some(Text::prompt(query)),
boxed_choices,
true,
false,