bevy_asky/view/mod.rs
1//! ascii, color, or button views
2use bevy::prelude::*;
3use std::fmt::Write;
4
5#[cfg(feature = "ascii")]
6pub mod ascii;
7// pub mod button;
8pub mod click;
9#[cfg(feature = "color")]
10pub mod color;
11// pub(crate) mod interaction;
12pub mod widget;
13
14pub(crate) fn plugin(_app: &mut App) {}
15
16// /// Replace or insert a [TextSection] at a particular index.
17// pub fn replace_or_insert(text: &mut Text, index: usize, replacement: &str) {
18// let len = text.sections.len();
19// if len <= index {
20// for _ in len.saturating_sub(1)..index {
21// text.sections.push(TextSection::default());
22// }
23// text.sections.push(TextSection::from(replacement));
24// } else {
25// text.sections[index].value.replace_range(.., replacement);
26// }
27// }
28//
29pub(crate) fn write_rep(
30 writer: &mut impl Write,
31 s: &str,
32 repetition: usize,
33) -> Result<(), std::fmt::Error> {
34 for _ in 0..repetition {
35 writer.write_str(s)?;
36 }
37 Ok(())
38}
39
40// /// Replace or insert a [TextSection] at a particular index with a repeating string.
41// pub fn replace_or_insert_rep(text: &mut Text, index: usize, replacement: &str, repetition: usize) {
42// let len = text.sections.len();
43// if len <= index {
44// for _ in len.saturating_sub(1)..index {
45// text.sections.push(TextSection::default());
46// }
47// // This allocates a string, which is fine because TextSection needs one.
48// text.sections
49// .push(TextSection::from(replacement.repeat(repetition)));
50// } else {
51// text.sections[index].value.clear();
52// for _ in 0..repetition {
53// // This doesn't allocate a string.
54// text.sections[index].value.push_str(replacement);
55// }
56// }
57// }