.
.
This commit is contained in:
@@ -39,19 +39,19 @@ pub trait Element {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Container {
|
pub struct Container<'a> {
|
||||||
// a simple container objects for grouping
|
// a simple container objects for grouping
|
||||||
// other containers together
|
// other containers together
|
||||||
frame: Vec<Vec<char>>,
|
frame: Vec<Vec<char>>,
|
||||||
elements: Vec<Box<dyn Element>>,
|
elements: Vec<Box<&'a dyn Element>>,
|
||||||
position: Pos, // x,y
|
position: Pos, // x,y
|
||||||
//
|
//
|
||||||
outlined: bool,
|
outlined: bool,
|
||||||
dimensions: Pos, // x,y
|
dimensions: Pos, // x,y
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Container {
|
impl Container<'a> {
|
||||||
fn new(position: Pos, dimensions: Pos, outlined: bool) -> Container {
|
fn new(position: Pos, dimensions: Pos, outlined: bool) -> Container<'a> {
|
||||||
Self {
|
Self {
|
||||||
frame: vec![vec![' '; dimensions.x as usize]; dimensions.y as usize],
|
frame: vec![vec![' '; dimensions.x as usize]; dimensions.y as usize],
|
||||||
elements: Vec::new(),
|
elements: Vec::new(),
|
||||||
@@ -60,12 +60,9 @@ impl Container {
|
|||||||
dimensions,
|
dimensions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn place(&self, element: Vec<Vec<char>>) {
|
|
||||||
return; // unimplemented
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Element for Container {
|
impl Element for Container<'_> {
|
||||||
fn render(&self) -> (Vec<Vec<char>>, Pos) {
|
fn render(&self) -> (Vec<Vec<char>>, Pos) {
|
||||||
// returns all elements as a single frame
|
// returns all elements as a single frame
|
||||||
|
|
||||||
@@ -255,18 +252,18 @@ pub fn test_elements() {
|
|||||||
|
|
||||||
containers.push(Container::new(Pos::new(0, 1), Pos::new(80, 24), true));
|
containers.push(Container::new(Pos::new(0, 1), Pos::new(80, 24), true));
|
||||||
|
|
||||||
containers[0]
|
let tbox = libgui_elements::TextBox::new(
|
||||||
.elements
|
String::from("ANNOUNCEMENTS"),
|
||||||
.push(Box::new(libgui_elements::TextBox::new(
|
String::from(
|
||||||
String::from("ANNOUNCEMENTS"),
|
"CrystalRPG coming soon! XD
|
||||||
String::from(
|
|
||||||
"CrystalRPG coming soon! XD
|
|
||||||
this is gonna be the best game ever",
|
this is gonna be the best game ever",
|
||||||
),
|
),
|
||||||
Pos::new(25, 10),
|
Pos::new(25, 10),
|
||||||
Pos::new(0, 0),
|
Pos::new(0, 0),
|
||||||
true,
|
true,
|
||||||
)));
|
);
|
||||||
|
|
||||||
|
containers[0].elements.push(Box::new(&tbox));
|
||||||
|
|
||||||
render_frame(containers);
|
render_frame(containers);
|
||||||
|
|
||||||
@@ -275,7 +272,7 @@ this is gonna be the best game ever",
|
|||||||
|
|
||||||
// function to generate a box in a random location on the screen.
|
// function to generate a box in a random location on the screen.
|
||||||
|
|
||||||
fn generate_box() -> Container {
|
fn generate_box() -> Container<'static> {
|
||||||
use crate::std::random::Random;
|
use crate::std::random::Random;
|
||||||
let width = Random::int(5, 20);
|
let width = Random::int(5, 20);
|
||||||
let height = Random::int(5, 10);
|
let height = Random::int(5, 10);
|
||||||
|
|||||||
Reference in New Issue
Block a user