1pub mod key_bindings;
8pub mod layout_picker;
9pub mod options;
10pub mod profiles;
11
12use crate::prelude::*;
13
14use shuyi_assets::lang::text_width;
15
16pub use crate::frame::draw::cut;
17
18use crate::ctx::{Ctx, GameData};
19use crate::frame::color::Rgb;
20use crate::frame::glyph_buffer::GlyphBuffer;
21use crate::input::fixed;
22
23pub const TEXT_BOX_HELP: &str = "text_box.help";
26
27pub fn text_keys_help<G: GameData>(ctx: &Ctx<G>) -> String {
30 let [done, delete, cancel] = fixed::text_key_names();
31 ctx.text_with(
32 TEXT_BOX_HELP,
33 &[("done", &done), ("delete", &delete), ("cancel", &cancel)],
34 )
35}
36
37pub fn centre_x(buf: &GlyphBuffer, width: usize) -> i32 {
39 let width = i32::try_from(width).unwrap_or(i32::MAX);
40 (i32::from(buf.width()) - width) / 2
41}
42
43pub fn print_centred(buf: &mut GlyphBuffer, y: i32, text: &str, fg: Rgb, bg: Rgb) {
46 let shown = cut(text, usize::from(buf.width()), buf.widths());
47 let x = centre_x(buf, text_width(&shown, buf.widths()));
48 buf.print(x, y, &shown, fg, bg);
49}
50
51#[cfg(test)]
52mod tests;