mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
ah yes. This was the kind of xous-ipc abuse I was worried I would have done.
And I did it! and it's now fixed. I was using xous-ipc String to make a fixed-length string in a structure that's not strictly an IPC structure. The solution to this is to just implement a fixed length string directly.
This commit is contained in:
parent
6e4eec99a3
commit
7141a02e10
1 changed files with 20 additions and 12 deletions
|
|
@ -8,7 +8,7 @@ use crate::*;
|
|||
// the enum_actions API to update the progress state in an efficient manner.
|
||||
// Thus it does not include its own GAM reference; instead we create one on
|
||||
// the fly when needed.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Slider {
|
||||
pub min: u32,
|
||||
pub max: u32,
|
||||
|
|
@ -19,7 +19,8 @@ pub struct Slider {
|
|||
pub is_progressbar: bool,
|
||||
pub is_password: bool,
|
||||
pub show_legend: bool,
|
||||
pub units: String,
|
||||
pub units: [u8; 8],
|
||||
pub units_len: usize,
|
||||
}
|
||||
impl Slider {
|
||||
pub fn new(
|
||||
|
|
@ -33,19 +34,19 @@ impl Slider {
|
|||
is_progressbar: bool,
|
||||
show_legend: bool,
|
||||
) -> Self {
|
||||
let checked_units = if let Some(unit_str) = units {
|
||||
if unit_str.len() < 8 {
|
||||
String::from(unit_str)
|
||||
let mut units_storage = [0u8; 8];
|
||||
let mut units_len = 0;
|
||||
if let Some(unit_str) = units {
|
||||
if unit_str.as_bytes().len() <= 8 {
|
||||
units_storage[..unit_str.as_bytes().len()].copy_from_slice(unit_str.as_bytes());
|
||||
units_len = unit_str.as_bytes().len();
|
||||
} else {
|
||||
log::error!(
|
||||
"Unit string must be less than 8 *bytes* long (are you using unicode?), ignoring length {} string",
|
||||
unit_str.len()
|
||||
unit_str.as_bytes().len()
|
||||
);
|
||||
String::new()
|
||||
}
|
||||
} else {
|
||||
String::new() // just populate with a blank string, easier than checking Some/None later on everywhere
|
||||
};
|
||||
}
|
||||
|
||||
Slider {
|
||||
action_conn,
|
||||
|
|
@ -56,7 +57,8 @@ impl Slider {
|
|||
max,
|
||||
step,
|
||||
action_payload: initial_setting,
|
||||
units: checked_units,
|
||||
units: units_storage,
|
||||
units_len,
|
||||
show_legend,
|
||||
}
|
||||
}
|
||||
|
|
@ -132,7 +134,13 @@ impl ActionApi for Slider {
|
|||
// estimate width of current setting
|
||||
tv.bounds_computed = None;
|
||||
tv.bounds_hint = TextBounds::GrowableFromTl(Point::new(0, 0), maxwidth);
|
||||
write!(tv, "{}{}", self.action_payload, &self.units).unwrap();
|
||||
write!(
|
||||
tv,
|
||||
"{}{}",
|
||||
self.action_payload,
|
||||
String::from_utf8(self.units[..self.units_len].to_vec()).unwrap_or("UTF8-Err".to_string())
|
||||
)
|
||||
.unwrap();
|
||||
modal.gam.bounds_compute_textview(&mut tv).expect("couldn't simulate text size");
|
||||
let textwidth = if let Some(bounds) = tv.bounds_computed {
|
||||
bounds.br.x - bounds.tl.x
|
||||
|
|
|
|||
Loading…
Reference in a new issue