e
e
This commit is contained in:
@@ -14,6 +14,19 @@ use alloc::{
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct Pos {
|
||||||
|
pub x: usize,
|
||||||
|
pub y: usize,
|
||||||
|
}
|
||||||
|
impl Pos {
|
||||||
|
pub fn new(x: usize, y: usize) -> Pos {
|
||||||
|
Pos { x, y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// all interface elements must implement this trait in order to be
|
/// all interface elements must implement this trait in order to be
|
||||||
/// rendered on the screen
|
/// rendered on the screen
|
||||||
pub trait Element {
|
pub trait Element {
|
||||||
@@ -186,23 +199,23 @@ pub fn overlap_check(oldchar: char, newchar: char) -> char {
|
|||||||
|
|
||||||
// function to return a charmap of the outline of an object
|
// function to return a charmap of the outline of an object
|
||||||
|
|
||||||
pub fn gen_outline(dimensions: (usize, usize)) -> Vec<Vec<char>> {
|
pub fn gen_outline(dimensions: Pos) -> Vec<Vec<char>> {
|
||||||
let mut charmap = Vec::<Vec<char>>::new();
|
let mut charmap = Vec::<Vec<char>>::new();
|
||||||
|
|
||||||
let mut frstline = vec!['┌'];
|
let mut frstline = vec!['┌'];
|
||||||
let mut midlines = vec!['│'];
|
let mut midlines = vec!['│'];
|
||||||
let mut lastline = vec!['└'];
|
let mut lastline = vec!['└'];
|
||||||
|
|
||||||
frstline.append(&mut vec!['─'; dimensions.0 - 2]);
|
frstline.append(&mut vec!['─'; dimensions.x - 2]);
|
||||||
midlines.append(&mut vec![' '; dimensions.0 - 2]);
|
midlines.append(&mut vec![' '; dimensions.x - 2]);
|
||||||
lastline.append(&mut vec!['─'; dimensions.0 - 2]);
|
lastline.append(&mut vec!['─'; dimensions.x - 2]);
|
||||||
|
|
||||||
frstline.append(&mut vec!['┐']);
|
frstline.append(&mut vec!['┐']);
|
||||||
midlines.append(&mut vec!['│']);
|
midlines.append(&mut vec!['│']);
|
||||||
lastline.append(&mut vec!['┘']);
|
lastline.append(&mut vec!['┘']);
|
||||||
|
|
||||||
charmap.push(frstline);
|
charmap.push(frstline);
|
||||||
for _ in 0..dimensions.1 - 2 {
|
for _ in 0..dimensions.y - 2 {
|
||||||
charmap.push(midlines.clone());
|
charmap.push(midlines.clone());
|
||||||
}
|
}
|
||||||
charmap.push(lastline);
|
charmap.push(lastline);
|
||||||
@@ -222,7 +235,7 @@ pub fn test_elements() {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
containers.push(Container::new((5, 5), (15, 5), true));
|
containers.push(Container::new((5, 5), (15, 5), true));
|
||||||
containers.push(Container::new((10, 3), (50, 15), true));
|
containers.push(Container::new((10, 3), (50, 20), true));
|
||||||
|
|
||||||
let mut bar = IndicatorBar::new((10, 6), 12);
|
let mut bar = IndicatorBar::new((10, 6), 12);
|
||||||
let mut bar2 = IndicatorBar::new((10, 7), 12);
|
let mut bar2 = IndicatorBar::new((10, 7), 12);
|
||||||
@@ -237,9 +250,9 @@ pub fn test_elements() {
|
|||||||
use super::libgui_elements;
|
use super::libgui_elements;
|
||||||
let tbox = libgui_elements::TextBox::new(
|
let tbox = libgui_elements::TextBox::new(
|
||||||
String::from("title"),
|
String::from("title"),
|
||||||
String::from("text"),
|
String::from("text boxes are working gg but how well will they work if they go over the end of the textbox, will it cause a crash, well ima have to keep testing to figure that out properly, this could take a while lmao, i hope it works"),
|
||||||
(10, 10),
|
Pos::new(25, 10),
|
||||||
(10, 8),
|
Pos::new(10, 9),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
use super::libgui_core;
|
use super::libgui_core::{self, Pos};
|
||||||
use alloc::{
|
use alloc::{
|
||||||
string::{String, ToString},
|
string::{String, ToString},
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
|
use crate::std::io::println;
|
||||||
|
|
||||||
// TEXT BOX
|
// TEXT BOX
|
||||||
|
|
||||||
pub struct TextBox {
|
pub struct TextBox {
|
||||||
dimensions: (usize, usize),
|
dimensions: Pos,
|
||||||
position: (usize, usize),
|
position: Pos,
|
||||||
content: String,
|
content: String,
|
||||||
title: String,
|
title: String,
|
||||||
outlined: bool,
|
outlined: bool,
|
||||||
@@ -18,24 +19,54 @@ impl libgui_core::Element for TextBox {
|
|||||||
fn render(&self) -> (Vec<Vec<char>>, (usize, usize)) {
|
fn render(&self) -> (Vec<Vec<char>>, (usize, usize)) {
|
||||||
let mut charmap = Vec::<Vec<char>>::new();
|
let mut charmap = Vec::<Vec<char>>::new();
|
||||||
|
|
||||||
|
let mut inner_dims = Pos::new(self.dimensions.x -2, self.dimensions.y -2);
|
||||||
|
|
||||||
if self.outlined {
|
if self.outlined {
|
||||||
charmap = libgui_core::gen_outline(self.dimensions);
|
charmap = libgui_core::gen_outline(self.dimensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
let inner_dims = (self.dimensions.0 - 2, self.dimensions.1 - 2);
|
|
||||||
|
|
||||||
let mut titlechars = self.title.chars().collect::<Vec<char>>();
|
let mut titlechars = self.title.chars().collect::<Vec<char>>();
|
||||||
// render title
|
// render title
|
||||||
|
|
||||||
for (i, char) in titlechars.iter().enumerate() {}
|
for (i, char) in titlechars.iter().enumerate() {
|
||||||
|
if i < inner_dims.x {
|
||||||
|
charmap[0][i + 1] = *char;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
|
|
||||||
while idx < self.content.len() {
|
// render text
|
||||||
()
|
|
||||||
|
let mut pos = Pos::new(0,0);
|
||||||
|
|
||||||
|
for chr in self.content.chars().collect::<Vec<char>>() {
|
||||||
|
|
||||||
|
if pos.x < inner_dims.x {
|
||||||
|
charmap[pos.y + 1][pos.x + 1] = chr;
|
||||||
|
pos.x += 1;
|
||||||
|
} else {
|
||||||
|
pos.y += 1;
|
||||||
|
pos.x = 1;
|
||||||
|
|
||||||
|
if pos.y < inner_dims.y {
|
||||||
|
charmap[pos.y + 1][1] = chr;
|
||||||
|
} else {
|
||||||
|
charmap[inner_dims.y][inner_dims.x] = '.';
|
||||||
|
charmap[inner_dims.y][inner_dims.x -1] = '.';
|
||||||
|
charmap[inner_dims.y][inner_dims.x -2] = '.';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (charmap, self.position);
|
|
||||||
|
|
||||||
|
|
||||||
|
return (charmap, (self.position.x, self.position.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,8 +74,8 @@ impl TextBox {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
title: String,
|
title: String,
|
||||||
content: String,
|
content: String,
|
||||||
dimensions: (usize, usize),
|
dimensions: Pos,
|
||||||
position: (usize, usize),
|
position: Pos,
|
||||||
outlined: bool,
|
outlined: bool,
|
||||||
) -> TextBox {
|
) -> TextBox {
|
||||||
TextBox {
|
TextBox {
|
||||||
|
|||||||
Reference in New Issue
Block a user