added outline support (still not done yet)
This commit is contained in:
+29
-17
@@ -2,31 +2,27 @@ use std::io::{stdout, Write};
|
||||
|
||||
pub struct Frame<'a> {
|
||||
used: Vec<u16>,
|
||||
css: &'a crate::ui::Css,
|
||||
writer: &'a mut crate::Writer,
|
||||
}
|
||||
|
||||
impl<'a> Frame<'a> {
|
||||
pub fn new(writer: &'a mut crate::Writer, css: &'a crate::ui::Css) -> Self {
|
||||
pub fn new(writer: &'a mut crate::Writer) -> Self {
|
||||
Frame {
|
||||
used: vec![0; writer.size.1 as usize],
|
||||
css,
|
||||
writer,
|
||||
}
|
||||
}
|
||||
pub fn render(&mut self, focused: bool, element: &crate::Element) {
|
||||
let style = element.get_style();
|
||||
let mut style_element = style.clone().get(focused);
|
||||
let css = unsafe { &*self.writer.css };
|
||||
|
||||
for class in element.get_class().split(" ") {
|
||||
if let Some(upper) = self
|
||||
.css
|
||||
.get(&crate::ui::StyleName::Class(class.to_string()))
|
||||
{
|
||||
if let Some(upper) = css.get(&crate::ui::StyleName::Class(class.to_string())) {
|
||||
style_element.merge(upper);
|
||||
}
|
||||
|
||||
if let Some(upper) = self.css.get(&crate::ui::StyleName::ClassState(
|
||||
if let Some(upper) = css.get(&crate::ui::StyleName::ClassState(
|
||||
class.to_string(),
|
||||
if style.2 == "" && focused {
|
||||
"hover".to_string()
|
||||
@@ -56,24 +52,40 @@ impl<'a> Frame<'a> {
|
||||
.x
|
||||
.1
|
||||
.as_position(style_element.outline.1, y_, self.writer.size.0);
|
||||
let mut writer = crate::Writer::new(
|
||||
let mut writer = crate::Writer {
|
||||
focused,
|
||||
style_element.clone(),
|
||||
(x, y),
|
||||
self.writer.size,
|
||||
self.css,
|
||||
);
|
||||
style: style_element.clone(),
|
||||
pos: (x, y),
|
||||
size: self.writer.size,
|
||||
css,
|
||||
parent: Some(self.writer),
|
||||
written: (0, 0),
|
||||
};
|
||||
element.render(&mut writer);
|
||||
let (mut width, mut height) = writer.get_size_root();
|
||||
if style_element.outline.1 {
|
||||
width += 2;
|
||||
height += 2;
|
||||
}
|
||||
for i in y..y + height {
|
||||
if let Some(o) = self.used.get_mut(i as usize) {
|
||||
*o += x + width;
|
||||
{
|
||||
let (mut x, mut y) = (x, y);
|
||||
if style_element.outline.1 {
|
||||
x -= 1;
|
||||
y -= 1;
|
||||
}
|
||||
let height = if style_element.outline.1 {
|
||||
height + 1
|
||||
} else {
|
||||
height
|
||||
};
|
||||
|
||||
for i in y..y + height {
|
||||
if let Some(o) = self.used.get_mut(i as usize) {
|
||||
*o += x + width + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.after_render(width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user