@@ -7,7 +7,7 @@ const Node = @import("../node.zig");
77
88pub const Options = struct {
99 font : * fonts.Font ,
10- text : [] const u21 ,
10+ view : std.unicode.Utf8View ,
1111};
1212
1313pub fn NodeText (comptime Impl : type ) type {
@@ -18,7 +18,7 @@ pub fn NodeText(comptime Impl: type) type {
1818
1919 const State = struct {
2020 font : * fonts.Font ,
21- text : [] const u21 ,
21+ view : std.unicode.Utf8View ,
2222 implState : ImplState ,
2323
2424 pub fn init (alloc : Allocator , options : Options ) Allocator.Error ! * State {
@@ -34,14 +34,13 @@ pub fn NodeText(comptime Impl: type) type {
3434 pub fn equal (self : * State , other : * State ) bool {
3535 return std .simd .countTrues (@Vector (2 , bool ){
3636 self .font == other .font ,
37- std .mem .eql (u8 , self .text , other .text ),
37+ std .mem .eql (u8 , self .view . bytes , other .view . bytes ),
3838 if (ImplState != void ) self .implState .equal (other .implState ) else true ,
3939 }) == 2 ;
4040 }
4141
4242 pub fn deinit (self : * State , alloc : Allocator ) void {
4343 if (ImplState != void ) self .implState .deinit (alloc );
44- alloc .free (self .text );
4544 alloc .destroy (self );
4645 }
4746 };
@@ -53,10 +52,7 @@ pub fn NodeText(comptime Impl: type) type {
5352 pub fn new (alloc : Allocator , id : ? usize , options : Options ) Allocator.Error ! * Node {
5453 const self = try alloc .create (Self );
5554 self .* = .{
56- .options = .{
57- .font = options .font ,
58- .text = try alloc .dupe (u21 , options .text ),
59- },
55+ .options = options ,
6056 .node = .{
6157 .allocator = alloc ,
6258 .ptr = self ,
@@ -92,8 +88,7 @@ pub fn NodeText(comptime Impl: type) type {
9288 }
9389
9490 fn calcSize (self : * Self ) ! vizops.vector.UsizeVector2 {
95- const view = try std .unicode .Utf8View .init (self .options .text );
96- var viewIter = view .iterator ();
91+ var viewIter = self .option .view .iterator ();
9792
9893 var width : usize = 0 ;
9994 var yMaxMin = vizops .vector .UsizeVector2 .zero ();
@@ -160,7 +155,6 @@ pub fn NodeText(comptime Impl: type) type {
160155 Impl .deinit (self );
161156 }
162157
163- self .node .allocator .free (self .options .text );
164158 self .node .allocator .destroy (self );
165159 }
166160
0 commit comments