proper auto sizing
This commit is contained in:
+50
-2
@@ -20,8 +20,14 @@ pub fn size_auto(ctx: &mut DrawContext, _view: &View) {
|
|||||||
for i in &ctx.drawing {
|
for i in &ctx.drawing {
|
||||||
match i {
|
match i {
|
||||||
DrawInstruction::Text(_, text) => {
|
DrawInstruction::Text(_, text) => {
|
||||||
ctx.allocated.width = text.len() as u16;
|
let mut height = 0;
|
||||||
ctx.allocated.height = 1;
|
|
||||||
|
for line in text.lines() {
|
||||||
|
ctx.allocated.width = ctx.allocated.width.max(line.len() as u16);
|
||||||
|
height += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.allocated.height = height;
|
||||||
}
|
}
|
||||||
DrawInstruction::View(area, view) => {
|
DrawInstruction::View(area, view) => {
|
||||||
let mut c = DrawContext::new(area.clone());
|
let mut c = DrawContext::new(area.clone());
|
||||||
@@ -35,6 +41,48 @@ pub fn size_auto(ctx: &mut DrawContext, _view: &View) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn width_auto(ctx: &mut DrawContext, _view: &View) {
|
||||||
|
for i in &ctx.drawing {
|
||||||
|
match i {
|
||||||
|
DrawInstruction::Text(_, text) => {
|
||||||
|
for line in text.lines() {
|
||||||
|
ctx.allocated.width = ctx.allocated.width.max(line.len() as u16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DrawInstruction::View(area, view) => {
|
||||||
|
let mut c = DrawContext::new(area.clone());
|
||||||
|
view(&mut c);
|
||||||
|
size_auto(&mut c, view);
|
||||||
|
ctx.allocated.width = c.allocated.width;
|
||||||
|
}
|
||||||
|
DrawInstruction::Child(_, _) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn height_auto(ctx: &mut DrawContext, _view: &View) {
|
||||||
|
for i in &ctx.drawing {
|
||||||
|
match i {
|
||||||
|
DrawInstruction::Text(_, text) => {
|
||||||
|
let mut height = 0;
|
||||||
|
|
||||||
|
for _ in text.lines() {
|
||||||
|
height += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.allocated.height = height;
|
||||||
|
}
|
||||||
|
DrawInstruction::View(area, view) => {
|
||||||
|
let mut c = DrawContext::new(area.clone());
|
||||||
|
view(&mut c);
|
||||||
|
size_auto(&mut c, view);
|
||||||
|
ctx.allocated.height = c.allocated.height;
|
||||||
|
}
|
||||||
|
DrawInstruction::Child(_, _) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn redraw(ctx: &mut DrawContext, view: &View) {
|
pub fn redraw(ctx: &mut DrawContext, view: &View) {
|
||||||
ctx.clear();
|
ctx.clear();
|
||||||
ctx.draw_view(ctx.allocated.clone(), view.clone());
|
ctx.draw_view(ctx.allocated.clone(), view.clone());
|
||||||
|
|||||||
Reference in New Issue
Block a user