mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +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.
|
// 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
|
// Thus it does not include its own GAM reference; instead we create one on
|
||||||
// the fly when needed.
|
// the fly when needed.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct Slider {
|
pub struct Slider {
|
||||||
pub min: u32,
|
pub min: u32,
|
||||||
pub max: u32,
|
pub max: u32,
|
||||||
|
|
@ -19,7 +19,8 @@ pub struct Slider {
|
||||||
pub is_progressbar: bool,
|
pub is_progressbar: bool,
|
||||||
pub is_password: bool,
|
pub is_password: bool,
|
||||||
pub show_legend: bool,
|
pub show_legend: bool,
|
||||||
pub units: String,
|
pub units: [u8; 8],
|
||||||
|
pub units_len: usize,
|
||||||
}
|
}
|
||||||
impl Slider {
|
impl Slider {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
|
@ -33,19 +34,19 @@ impl Slider {
|
||||||
is_progressbar: bool,
|
is_progressbar: bool,
|
||||||
show_legend: bool,
|
show_legend: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let checked_units = if let Some(unit_str) = units {
|
let mut units_storage = [0u8; 8];
|
||||||
if unit_str.len() < 8 {
|
let mut units_len = 0;
|
||||||
String::from(unit_str)
|
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 {
|
} else {
|
||||||
log::error!(
|
log::error!(
|
||||||
"Unit string must be less than 8 *bytes* long (are you using unicode?), ignoring length {} string",
|
"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 {
|
Slider {
|
||||||
action_conn,
|
action_conn,
|
||||||
|
|
@ -56,7 +57,8 @@ impl Slider {
|
||||||
max,
|
max,
|
||||||
step,
|
step,
|
||||||
action_payload: initial_setting,
|
action_payload: initial_setting,
|
||||||
units: checked_units,
|
units: units_storage,
|
||||||
|
units_len,
|
||||||
show_legend,
|
show_legend,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +134,13 @@ impl ActionApi for Slider {
|
||||||
// estimate width of current setting
|
// estimate width of current setting
|
||||||
tv.bounds_computed = None;
|
tv.bounds_computed = None;
|
||||||
tv.bounds_hint = TextBounds::GrowableFromTl(Point::new(0, 0), maxwidth);
|
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");
|
modal.gam.bounds_compute_textview(&mut tv).expect("couldn't simulate text size");
|
||||||
let textwidth = if let Some(bounds) = tv.bounds_computed {
|
let textwidth = if let Some(bounds) = tv.bounds_computed {
|
||||||
bounds.br.x - bounds.tl.x
|
bounds.br.x - bounds.tl.x
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue