@@ -47,47 +47,59 @@ pub fn main() void {
4747 }
4848
4949 const output = outputs .items [0 ];
50+ const outputInfo = output .info () catch | e | @panic (@errorName (e ));
5051 const surface = output .createSurface (.output , .{
51- .size = ( output . info () catch | e | @panic ( @errorName ( e ))) .size .res ,
52+ .size = outputInfo .size .res ,
5253 }) catch | e | @panic (@errorName (e ));
5354 defer {
5455 surface .destroy () catch {};
5556 surface .deinit ();
5657 }
5758
59+ const fontFormat = phantom .fonts .backends .bdf .create (alloc ) catch | e | @panic (@errorName (e ));
60+ defer fontFormat .deinit ();
61+
62+ const font = fontFormat .loadBuffer (@embedFile ("example.bdf" ), .{
63+ .colorspace = .sRGB ,
64+ .colorFormat = .{ .rgba = @splat (8 ) },
65+ .foregroundColor = .{
66+ .uint8 = .{
67+ .sRGB = .{
68+ .value = @splat (0 ),
69+ },
70+ },
71+ },
72+ .backgroundColor = .{
73+ .uint8 = .{
74+ .sRGB = .{
75+ .value = @splat (255 ),
76+ },
77+ },
78+ },
79+ }) catch | e | @panic (@errorName (e ));
80+ defer font .deinit ();
81+
82+ const utfView = std .unicode .Utf8View .initComptime ("Hello, world!" );
83+ var iter = utfView .iterator ();
84+
85+ var nodes = std .ArrayList (* phantom .scene .Node ).init (alloc );
86+
5887 const scene = surface .createScene (@enumFromInt (@intFromEnum (sceneBackendType ))) catch | e | @panic (@errorName (e ));
5988
60- const format = phantom . painting . image . formats . zigimg . create ( alloc ) catch | e | @panic ( @errorName ( e ));
61- defer format . deinit ( );
89+ while ( iter . nextCodepoint ()) | codepoint | {
90+ const glyph = font . lookupGlyph ( codepoint ) catch | e | @panic ( @errorName ( e ) );
6291
63- const image = format .readBuffer (@embedFile ("example.gif" )) catch | e | @panic (@errorName (e ));
64- defer image .deinit ();
92+ nodes .append (scene .createNode (.NodeFrameBuffer , .{
93+ .source = glyph .fb ,
94+ }) catch | e | @panic (@errorName (e ))) catch | e | @panic (@errorName (e ));
95+ }
6596
66- const fb = scene .createNode (.NodeFrameBuffer , .{
67- .source = image .buffer (0 ) catch | e | @panic (@errorName (e )),
97+ const flex = scene .createNode (.NodeFlex , .{
98+ .direction = .horizontal ,
99+ .children = nodes .items ,
68100 }) catch | e | @panic (@errorName (e ));
69101
70- const stderr = if (builtin .os .tag == .uefi ) SimpleTextOutputWriter {
71- .context = std .os .uefi .system_table .std_err .? ,
72- } else std .io .getStdErr ().writer ();
73-
74- var prevTime = std .time .milliTimestamp ();
75102 while (true ) {
76- const currTime = std .time .milliTimestamp ();
77- const deltaTime = currTime - prevTime ;
78- _ = stderr .print ("FPS: {} (Delta time: {}, Prev: {}, Curr: {})\n " , .{
79- 60 / @max (deltaTime , 1 ),
80- deltaTime ,
81- prevTime ,
82- currTime ,
83- }) catch {};
84-
85- _ = scene .frame (fb ) catch | e | @panic (@errorName (e ));
86-
87- fb .setProperties (.{
88- .source = image .buffer (scene .seq % image .info ().seqCount ) catch | e | @panic (@errorName (e )),
89- }) catch | e | @panic (@errorName (e ));
90-
91- prevTime = currTime ;
103+ _ = scene .frame (flex ) catch | e | @panic (@errorName (e ));
92104 }
93105}
0 commit comments