Skip to content

Instantly share code, notes, and snippets.

@eseidelGoogle
Last active August 29, 2015 14:20
Show Gist options
  • Save eseidelGoogle/b8c42258423b81c2af2b to your computer and use it in GitHub Desktop.
Save eseidelGoogle/b8c42258423b81c2af2b to your computer and use it in GitHub Desktop.
Painting wrapped Text in Sky?
import "dart:sky";
var inline = new RenderInline();
// We'll need a better API for looking up fonts.
inline.textStyle.fontSize = "Helvetica";
var text = new RenderText("This is a long bit of text which should wrap. ");
var text2 = new RenderText("And this bit is bold ");
text2.textStyle.weight = 900;
inline.add(text);
inline.add(text2);
var text3 = new RenderText("And this bit has the default font");
var block = new RenderParagraph();
block.add(inline);
block.add(text3);
block.layout(minWidth: 100, maxWidth: 100);
var list = new DisplayList();
block.paint(list);
sky.rootDisplayList = list;
@eseidelGoogle
Copy link
Author

Looking at the c++ code just now, I think this can work. Change new DisplayList to new PaintContext and pass the size that you plan to paint into. And then when block.paint() is called, steal the SkCanvas out of the PaintContext, bottle it up into a GraphicsContext and call RenderBox::paintLayer() with that context. May need to come in through FrameView to get all the clipping right, so likely need to add a separate path which does not depend on that entrance.

@ojanvafai
Copy link

lgtm for the base layer exposed from C++.

I think the framework will want something that makes it so that you can't call layout from arbitrary places (at least not without explicitly disabling an assert or something). You want to encourage code that does all the layout/paint as part of an explicit layout/paint phase so that you can ensure the work is only done once per frame. I'm happy with the base C++ layer not doing the asserting though since you can imagine the framework wanting to do things differently eventually (e.g. to layout/paint a disconnected subtree before appending it to the actual tree).

Also, I believe we may eventually want to let you cache the output of paint for a specific RenderNode (e.g. imagine a canvas or an img). I'm not particularly wed to any specific api here, but one thought that would basically be the same, but allow caching as well, would be to have paint return an SkPaint-equivalent:

var list = new DisplayList();
list.append(block.paint());

That way you can save out the output of the paint call if you want. You can also do things like generate the output of the paint call over multiple frames while showing stale content without causing us to miss frames.

@eseidelGoogle
Copy link
Author

I'm going to start with something even simpler for now:
https://gist.github.com/eseidelGoogle/56973c1495e1d256c827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment