@@ -8,7 +8,7 @@ const Widget = @import("widget.zig").Widget;
88const Class = @import ("widget.zig" ).Class ;
99const Size = dataStructures .Size ;
1010const Atom = dataStructures .Atom ;
11- const Container_Impl = @import ("containers.zig" ).Container_Impl ;
11+ const Container = @import ("containers.zig" ).Container ;
1212const Layout = @import ("containers.zig" ).Layout ;
1313const MouseButton = @import ("backends/shared.zig" ).MouseButton ;
1414
@@ -175,7 +175,7 @@ pub fn Widgeting(comptime T: type) type {
175175 } else {
176176 comptime {
177177 var compileError : []const u8 = "No such property: " ++ name ;
178- if (T == Container_Impl ) {
178+ if (T == Container ) {
179179 compileError = compileError ++ ", did you mean to use getChild() ?" ;
180180 }
181181 @compileError (compileError );
@@ -317,9 +317,32 @@ fn iterateFields(comptime config_fields: *[]const std.builtin.Type.StructField,
317317 }
318318}
319319
320- pub fn applyConfigStruct (target : anytype , config : anytype ) void {
321- _ = target ;
322- _ = config ;
320+ /// target is a pointer to a component
321+ /// config is a config struct generated by GenerateConfigStruct(T)
322+ pub fn applyConfigStruct (target : anytype , config : GenerateConfigStruct (std .meta .Child (@TypeOf (target )))) void {
323+ std .debug .assert (std .meta .trait .isPtrTo (.Struct )(@TypeOf (target )));
324+ iterateApplyFields (std .meta .Child (@TypeOf (target )), target , config );
325+
326+ if (config .onclick ) | onclick | {
327+ target .addClickHandler (onclick ) catch unreachable ; // TODO: improve
328+ }
329+ if (config .ondraw ) | ondraw | {
330+ target .addDrawHandler (ondraw ) catch unreachable ; // TODO: improve
331+ }
332+ }
333+
334+ fn iterateApplyFields (comptime T : type , target : anytype , config : GenerateConfigStruct (T )) void {
335+ inline for (std .meta .fields (std .meta .Child (@TypeOf (target )))) | field | {
336+ const FieldType = field .type ;
337+ if (comptime dataStructures .isAtom (FieldType )) {
338+ const name = field .name ;
339+ @field (target , field .name ).set (
340+ @field (config , name ),
341+ );
342+ } else if (comptime std .meta .trait .is (.Struct )(FieldType )) {
343+ iterateApplyFields (T , &@field (target , field .name ), config );
344+ }
345+ }
323346}
324347
325348/// If T is a pointer, return the type it points to, otherwise return T.
@@ -349,7 +372,7 @@ pub fn genericWidgetFrom(component: anytype) anyerror!Widget {
349372 break :blk copy ;
350373 };
351374
352- // Udate things like data wrappers, this happens once, at initialization,
375+ // Update things like data wrappers, this happens once, at initialization,
353376 // after that the component isn't moved in memory anymore
354377 cp .pointerMoved ();
355378
@@ -555,6 +578,7 @@ pub fn Events(comptime T: type) type {
555578 /// When the value is changed in the opacity data wrapper
556579 fn opacityChanged (newValue : f32 , userdata : usize ) void {
557580 const widget = @as (* T , @ptrFromInt (userdata ));
581+ std .log .info ("opaccity changed to {d}" , .{newValue });
558582 if (widget .peer ) | * peer | {
559583 peer .setOpacity (newValue );
560584 }
0 commit comments