Sensorycc / SensoryAestheticsZine001

MIT License
0 stars 1 forks source link

content layout interface #9

Open quinkennedy opened 9 years ago

quinkennedy commented 9 years ago

I'm thinking that each atomic piece of content (heading, quote, image, footer, page num, etc) should have a rendering function which takes a rect and a float as arguments, and the renderer is allowed to use a percentage of the specified rect area for rendering its content.

This might be something like:

rect heading(String text, rect area, float amount){
  text(text, area.x, area.y, area.w, area.h*amount);
  return rect(area.x, area.y+area.h*amount, area.w, area.h*(1-amount));
}

rect image(PImage img, rect area, float amount){
  if (image.width > image .height){
    image(img, area.x, area.y, area.w, area.h*amount);
    return rect(area.x, area.y+area.h*amount, area.w, area.h*(1-amount));
  } else {
    image(img, area.x, area.y, area.w*amount, area.h);
    return rect(area.x+area.w*amount, area.y, area.w*(1-amount), area.h);
  }
}

void render(PageData pd){
  rect r = heading(pd.heading, rect(0, 0, pd.contentWidthPx, pd.contentHeightPx), .25);
  r = image(pd.imageContent[0], r, 2.0/3);
}
quinkennedy commented 9 years ago

We started working toward this with commit 5211bd4c14b136e336e73588cb1521e7d94cd12c

Currently we have a ContentBox render(...) interface, this might want to be expanded to include a query or layout interface for pre-render calculations. the render function returns a Rectangle representing the actual area that the element used (whereas the Rectangle argument is the area available)