Boxes may convert to multiple display list items

This commit is contained in:
Brian Anderson 2012-06-16 15:57:08 -07:00
parent 96c44f9726
commit 2c0dcbc722

View file

@ -41,7 +41,7 @@ fn build_display_list_from_origin(box: @Box, origin: Point2D<au>)
px_to_au(au_to_px(origin.y) + au_to_px(box.bounds.origin.y))); px_to_au(au_to_px(origin.y) + au_to_px(box.bounds.origin.y)));
#debug("Handed origin %?, box has bounds %?, starting with origin %?", origin, copy box.bounds, box_origin); #debug("Handed origin %?, box has bounds %?, starting with origin %?", origin, copy box.bounds, box_origin);
let mut list = [box_to_display_item(box, box_origin)]; let mut list = box_to_display_items(box, box_origin);
for btree.each_child(box) {|c| for btree.each_child(box) {|c|
#debug("Recursively building display list with origin %?", box_origin); #debug("Recursively building display list with origin %?", box_origin);
@ -60,8 +60,8 @@ Args:
-origin: the coordinates of upper-left corner of the passed in box. -origin: the coordinates of upper-left corner of the passed in box.
"] "]
fn box_to_display_item(box: @Box, origin: Point2D<au>) -> dl::display_item { fn box_to_display_items(box: @Box, origin: Point2D<au>) -> [dl::display_item] {
let mut item; let mut items = [];
#debug("request to display a box from origin %?", origin); #debug("request to display a box from origin %?", origin);
@ -71,37 +71,37 @@ fn box_to_display_item(box: @Box, origin: Point2D<au>) -> dl::display_item {
(TextBox(subbox), _, _) { (TextBox(subbox), _, _) {
let run = copy subbox.run; let run = copy subbox.run;
assert run.is_some(); assert run.is_some();
item = dl::display_item({ items += [dl::display_item({
item_type: dl::display_item_text(run.get()), item_type: dl::display_item_text(run.get()),
bounds: bounds bounds: bounds
}); })];
} }
(_, some(image), some(*)) | (_, some(image), none) { (_, some(image), some(*)) | (_, some(image), none) {
item = dl::display_item({ items += [dl::display_item({
item_type: dl::display_item_image(~copy *image), item_type: dl::display_item_image(~copy *image),
bounds: bounds bounds: bounds
}); })];
} }
(_, none, some(col)) { (_, none, some(col)) {
#debug("Assigning color %? to box with bounds %?", col, bounds); #debug("Assigning color %? to box with bounds %?", col, bounds);
item = dl::display_item({ items += [dl::display_item({
item_type: dl::display_item_solid_color(col.red, col.green, col.blue), item_type: dl::display_item_solid_color(col.red, col.green, col.blue),
bounds: bounds bounds: bounds
}); })];
} }
(_, none, none) { (_, none, none) {
let r = rand::rng(); let r = rand::rng();
item = dl::display_item({ items += [dl::display_item({
item_type: dl::display_item_solid_color(r.next() as u8, item_type: dl::display_item_solid_color(r.next() as u8,
r.next() as u8, r.next() as u8,
r.next() as u8), r.next() as u8),
bounds: bounds bounds: bounds
}); })];
} }
} }
#debug("layout: display item: %?", item); #debug("layout: display items: %?", items);
ret item; ret items;
} }
fn should_convert_text_boxes_to_text_items() { fn should_convert_text_boxes_to_text_items() {
@ -112,9 +112,9 @@ fn should_convert_text_boxes_to_text_items() {
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = alt check b.kind { TextBox(subbox) { subbox } }; let subbox = alt check b.kind { TextBox(subbox) { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
let di = box_to_display_item(b, Point2D(px_to_au(0), px_to_au(0))); let di = box_to_display_items(b, Point2D(px_to_au(0), px_to_au(0)));
alt di.item_type { alt di[0].item_type {
dl::display_item_text(_) { } dl::display_item_text(_) { }
_ { fail } _ { fail }
} }
@ -128,15 +128,15 @@ fn should_calculate_the_bounds_of_the_text_box() {
let b = n.construct_boxes(); let b = n.construct_boxes();
let subbox = alt check b.kind { TextBox(subbox) { subbox } }; let subbox = alt check b.kind { TextBox(subbox) { subbox } };
b.reflow_text(px_to_au(800), subbox); b.reflow_text(px_to_au(800), subbox);
let di = box_to_display_item(b, Point2D(px_to_au(0), px_to_au(0))); let di = box_to_display_items(b, Point2D(px_to_au(0), px_to_au(0)));
let expected = Rect( let expected = Rect(
Point2D(px_to_au(0), px_to_au(0)), Point2D(px_to_au(0), px_to_au(0)),
Size2D(px_to_au(110), px_to_au(14)) Size2D(px_to_au(110), px_to_au(14))
); );
#error("%?", di.bounds); #error("%?", di[0].bounds);
#error("%?", expected); #error("%?", expected);
assert di.bounds == expected; assert di[0].bounds == expected;
} }