great usize extinction event - graphics-server

This commit is contained in:
bunnie 2021-01-22 00:33:49 +08:00
parent 87501444c5
commit 75cd321175
2 changed files with 17 additions and 17 deletions

View file

@ -92,17 +92,17 @@ impl Rectangle {
style: style, style: style,
} }
} }
pub fn x0(&self) -> usize { pub fn x0(&self) -> u32 {
self.tl.x as usize self.tl.x as u32
} }
pub fn x1(&self) -> usize { pub fn x1(&self) -> u32 {
self.br.x as usize self.br.x as u32
} }
pub fn y0(&self) -> usize { pub fn y0(&self) -> u32 {
self.tl.y as usize self.tl.y as u32
} }
pub fn y1(&self) -> usize { pub fn y1(&self) -> u32 {
self.br.y as usize self.br.y as u32
} }
/// Make a rectangle of the full screen size /// Make a rectangle of the full screen size

View file

@ -64,7 +64,7 @@ pub struct TextView {
pub invert: bool, // only trusted, token-validated TextViews will have the invert bit respected pub invert: bool, // only trusted, token-validated TextViews will have the invert bit respected
// lower numbers are drawn last // lower numbers are drawn last
pub draw_order: usize, pub draw_order: u32,
// offsets for text drawing -- exactly one of the following options should be specified // offsets for text drawing -- exactly one of the following options should be specified
pub bounds_hint: TextBounds, pub bounds_hint: TextBounds,
@ -72,7 +72,7 @@ pub struct TextView {
pub style: GlyphStyle, pub style: GlyphStyle,
text: [u8; TEXTVIEW_LEN], text: [u8; TEXTVIEW_LEN],
length: usize, length: u32,
pub alignment: TextAlignment, pub alignment: TextAlignment,
pub cursor: Cursor, pub cursor: Cursor,
@ -84,12 +84,12 @@ pub struct TextView {
pub y_margin: u16, pub y_margin: u16,
// this field specifies the beginning and end of a "selected" region of text // this field specifies the beginning and end of a "selected" region of text
pub selected: Option<[usize; 2]>, pub selected: Option<[u32; 2]>,
canvas: Gid, // GID of the canvas to draw on canvas: Gid, // GID of the canvas to draw on
} }
impl TextView { impl TextView {
pub fn new(canvas: Gid, draw_order: usize, bounds_hint: TextBounds) -> Self { pub fn new(canvas: Gid, draw_order: u32, bounds_hint: TextBounds) -> Self {
TextView { TextView {
operation: TextOp::Nop, operation: TextOp::Nop,
untrusted: true, untrusted: true,
@ -131,7 +131,7 @@ impl TextView {
pub fn to_str(&self) -> &str { pub fn to_str(&self) -> &str {
core::str::from_utf8(unsafe { core::str::from_utf8(unsafe {
core::slice::from_raw_parts(self.text.as_ptr(), self.length) core::slice::from_raw_parts(self.text.as_ptr(), self.length as usize)
}) })
.unwrap() .unwrap()
} }
@ -192,19 +192,19 @@ impl core::fmt::Write for TextView {
let b = s.bytes(); let b = s.bytes();
// Ensure the length is acceptable // Ensure the length is acceptable
if b.len() + self.length > self.text.len() { if b.len() + self.length as usize > self.text.len() as usize {
Err(core::fmt::Error)?; Err(core::fmt::Error)?;
} }
// append the write to the array // append the write to the array
for c in s.bytes() { for c in s.bytes() {
if self.length < self.text.len() { if self.length < self.text.len() as u32 {
self.text[self.length] = c; self.text[self.length as usize] = c;
self.length += 1; self.length += 1;
} }
} }
// Attempt to convert the string to UTF-8 to validate it's correct UTF-8. // Attempt to convert the string to UTF-8 to validate it's correct UTF-8.
core::str::from_utf8(unsafe { core::str::from_utf8(unsafe {
core::slice::from_raw_parts(self.text.as_ptr(), self.length) core::slice::from_raw_parts(self.text.as_ptr(), self.length as usize)
}) })
.map_err(|_| core::fmt::Error)?; .map_err(|_| core::fmt::Error)?;
Ok(()) Ok(())