@@ -5,6 +5,12 @@ pub const FONT_SIZE: f32 = 22.0;
55pub const FONT_MUL : f32 = 2.0 ;
66pub const RESOURCE_BUNDLE_FILENAME = "resources.bd" ;
77
8+ pub const Error = error {
9+ ResourceReadError ,
10+ ResourceNotFound ,
11+ UnknownImageFormat ,
12+ };
13+
814// A vector may represent a position or distance in 2D space.
915pub const Vector = struct {
1016 x : f32 = 0 ,
@@ -920,7 +926,7 @@ pub const Element = struct {
920926 allocator : Allocator ,
921927 display : * Display ,
922928 conf : Element ,
923- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! * Element {
929+ ) (Error || Allocator . Error || Resources . Error )! * Element {
924930 std .debug .assert (self .type == .panel );
925931 const child = try allocator .create (Element );
926932 child .* = conf ;
@@ -3353,7 +3359,7 @@ pub const Display = struct {
33533359 self : * Display ,
33543360 allocator : Allocator ,
33553361 name : []const u8 ,
3356- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! * FontInfo {
3362+ ) (Error || Allocator . Error || Resources . Error )! * FontInfo {
33573363 const resource = try self .resources .lookupOne (name , .font , allocator );
33583364 if (resource == null ) {
33593365 err ("load_font({s}) Font not in resource folder" , .{name });
@@ -3477,7 +3483,7 @@ pub const Display = struct {
34773483 self : * Display ,
34783484 allocator : Allocator ,
34793485 name : []const u8 ,
3480- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! ? * TextureInfo {
3486+ ) (Error || Allocator . Error || Resources . Error )! ? * TextureInfo {
34813487 if (name .len == 0 ) {
34823488 return null ;
34833489 }
@@ -3519,7 +3525,7 @@ pub const Display = struct {
35193525 resource : * Resource ,
35203526 allocator : Allocator ,
35213527 si : * SurfaceInfo ,
3522- ) error { OutOfMemory , ResourceReadError , ResourceNotFound , UnknownImageFormat } ! void {
3528+ ) ( Error || Allocator . Error ) ! void {
35233529 si .buffer = try sdl_load_resource (self .resources , resource , allocator );
35243530 errdefer allocator .free (si .buffer );
35253531 si .img = zigimg .Image .fromMemory (allocator , si .buffer [0.. ]) catch | e | {
@@ -4436,12 +4442,7 @@ pub const Display = struct {
44364442 allocator : Allocator ,
44374443 parent : * Element ,
44384444 close_fn : Callback ,
4439- ) (error {
4440- OutOfMemory ,
4441- ResourceNotFound ,
4442- ResourceReadError ,
4443- UnknownImageFormat ,
4444- } || ResourcesError )! * Element {
4445+ ) (Error || Allocator .Error || Resources .Error )! * Element {
44454446 return try parent .add_alloc (
44464447 allocator ,
44474448 display ,
@@ -4471,12 +4472,7 @@ pub const Display = struct {
44714472 allocator : Allocator ,
44724473 parent : * Element ,
44734474 size : f32 ,
4474- ) (error {
4475- OutOfMemory ,
4476- ResourceNotFound ,
4477- ResourceReadError ,
4478- UnknownImageFormat ,
4479- } || Resources .Error )! * Element {
4475+ ) (Error || Allocator .Error || Resources .Error )! * Element {
44804476 return try parent .add (allocator , try engine .create_panel (
44814477 allocator ,
44824478 display ,
@@ -4498,12 +4494,7 @@ pub const Display = struct {
44984494 size : TextSize ,
44994495 name : []const u8 ,
45004496 text : []const u8 ,
4501- ) (error {
4502- OutOfMemory ,
4503- ResourceNotFound ,
4504- ResourceReadError ,
4505- UnknownImageFormat ,
4506- } || ResourcesError )! void {
4497+ ) (Error || Allocator .Error || Resources .Error )! void {
45074498 _ = try parent .add_alloc (allocator , display , .{
45084499 .name = name ,
45094500 .focus = .accessibility_focus ,
@@ -4523,7 +4514,7 @@ pub const Display = struct {
45234514 self : * Display ,
45244515 allocator : Allocator ,
45254516 element : * Element ,
4526- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4517+ ) (Error || Allocator . Error || Resources . Error )! void {
45274518 switch (element .type ) {
45284519 .panel = > try setup_panel (self , allocator , element ),
45294520 .button = > try setup_button (self , allocator , element ),
@@ -4700,7 +4691,7 @@ pub fn setup_rect(
47004691 _ : * Display ,
47014692 _ : Allocator ,
47024693 element : * Element ,
4703- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4694+ ) (Error || Allocator . Error || Resources . Error )! void {
47044695 element .texture = null ;
47054696 element .background .image = null ;
47064697 if (element .focus == .unspecified ) {
@@ -4712,7 +4703,7 @@ pub fn setup_panel(
47124703 self : * Display ,
47134704 allocator : Allocator ,
47144705 element : * Element ,
4715- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4706+ ) (Error || Allocator . Error || Resources . Error )! void {
47164707 element .texture = null ;
47174708 element .background .image = null ;
47184709
@@ -4739,7 +4730,7 @@ pub fn setup_progress_bar(
47394730 self : * Display ,
47404731 allocator : Allocator ,
47414732 element : * Element ,
4742- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4733+ ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || Resources . Error )! void {
47434734 element .texture = null ;
47444735 element .background .image = null ;
47454736 if (element .focus == .unspecified ) {
@@ -4762,7 +4753,7 @@ pub fn setup_checkbox(
47624753 self : * Display ,
47634754 allocator : Allocator ,
47644755 element : * Element ,
4765- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4756+ ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || Resources . Error )! void {
47664757 element .texture = null ;
47674758 element .background .image = null ;
47684759 element .type .checkbox .translated = "" ;
@@ -4806,7 +4797,7 @@ pub fn setup_expander(
48064797 _ : * Display ,
48074798 _ : Allocator ,
48084799 element : * Element ,
4809- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4800+ ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || Resources . Error )! void {
48104801 element .texture = null ;
48114802 element .background .image = null ;
48124803 element .focus = .never_focus ;
@@ -4816,7 +4807,7 @@ pub fn setup_label(
48164807 self : * Display ,
48174808 allocator : Allocator ,
48184809 element : * Element ,
4819- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4810+ ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || Resources . Error )! void {
48204811 element .texture = null ;
48214812 element .background .image = null ;
48224813 element .type .label .translated = "" ;
@@ -4847,7 +4838,7 @@ pub fn setup_text_input(
48474838 self : * Display ,
48484839 allocator : Allocator ,
48494840 element : * Element ,
4850- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4841+ ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || Resources . Error )! void {
48514842 element .texture = null ;
48524843 element .background .image = null ;
48534844 if (element .focus == .unspecified ) {
@@ -4899,7 +4890,7 @@ pub fn setup_sprite(
48994890 self : * Display ,
49004891 allocator : Allocator ,
49014892 element : * Element ,
4902- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4893+ ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || Resources . Error )! void {
49034894 element .texture = null ;
49044895 element .background .image = null ;
49054896 if (element .focus == .unspecified )
@@ -4954,7 +4945,7 @@ pub fn setup_button(
49544945 display : * Display ,
49554946 allocator : Allocator ,
49564947 element : * Element ,
4957- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! void {
4948+ ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || Resources . Error )! void {
49584949 element .type .button .translated = "" ;
49594950 element .texture = null ;
49604951 element .background .image = null ;
@@ -5069,7 +5060,7 @@ pub fn create_label(
50695060 allocator : Allocator ,
50705061 display : * Display ,
50715062 settings : Element ,
5072- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! * Element {
5063+ ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || Resources . Error )! * Element {
50735064 const element = try display .allocator .create (Element );
50745065 element .* = settings ;
50755066 try display .setup_element (allocator , element );
@@ -5081,7 +5072,7 @@ pub fn create_checkbox(
50815072 allocator : Allocator ,
50825073 display : * Display ,
50835074 settings : Element ,
5084- ) (error { OutOfMemory , ResourceNotFound , ResourceReadError , UnknownImageFormat } || ResourcesError )! * Element {
5075+ ) (error { OutOfMemory , ResourceNotFound , ResourceReadError , UnknownImageFormat } || Resources . Error )! * Element {
50855076 const element = try allocator .create (Element );
50865077 element .* = settings ;
50875078 try display .setup_element (allocator , element );
@@ -5093,7 +5084,7 @@ pub fn create_button(
50935084 allocator : Allocator ,
50945085 display : * Display ,
50955086 settings : Element ,
5096- ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || ResourcesError )! * Element {
5087+ ) (error { OutOfMemory , UnknownImageFormat , ResourceNotFound , ResourceReadError } || Resources . Error )! * Element {
50975088 const element = try allocator .create (Element );
50985089 element .* = settings ;
50995090 try display .setup_element (allocator , element );
@@ -5105,7 +5096,7 @@ pub fn create_text_input(
51055096 allocator : Allocator ,
51065097 display : * Display ,
51075098 settings : Element ,
5108- ) (error { OutOfMemory , ResourceNotFound , ResourceReadError , UnknownImageFormat } || ResourcesError )! * Element {
5099+ ) (error { OutOfMemory , ResourceNotFound , ResourceReadError , UnknownImageFormat } || Resources . Error )! * Element {
51095100 const element = try allocator .create (Element );
51105101 element .* = settings ;
51115102 try display .setup_element (allocator , element );
@@ -5117,7 +5108,7 @@ pub fn create_progress_bar(
51175108 allocator : Allocator ,
51185109 display : * Display ,
51195110 settings : Element ,
5120- ) (error { OutOfMemory , ResourceNotFound , ResourceReadError , UnknownImageFormat } || ResourcesError )! * Element {
5111+ ) (error { OutOfMemory , ResourceNotFound , ResourceReadError , UnknownImageFormat } || Resources . Error )! * Element {
51215112 const element = try allocator .create (Element );
51225113 element .* = settings ;
51235114 try display .setup_element (allocator , element );
@@ -5133,7 +5124,7 @@ pub fn create_expander(
51335124 allocator : Allocator ,
51345125 display : * Display ,
51355126 settings : Element ,
5136- ) (error { ResourceReadError , ResourceNotFound , UnknownImageFormat } || Allocator .Error || ResourcesError )! * Element {
5127+ ) (error { ResourceReadError , ResourceNotFound , UnknownImageFormat } || Allocator .Error || Resources . Error )! * Element {
51375128 const element = try allocator .create (Element );
51385129 element .* = settings ;
51395130 try display .setup_element (allocator , element );
@@ -5148,7 +5139,7 @@ pub fn create_panel(
51485139 allocator : Allocator ,
51495140 display : * Display ,
51505141 settings : Element ,
5151- ) (error { OutOfMemory , ResourceReadError , ResourceNotFound , UnknownImageFormat } || ResourcesError )! * Element {
5142+ ) (error { OutOfMemory , ResourceReadError , ResourceNotFound , UnknownImageFormat } || Resources . Error )! * Element {
51525143 const element = try allocator .create (Element );
51535144 element .* = settings ;
51545145 try display .setup_element (allocator , element );
@@ -5579,7 +5570,6 @@ pub const Translation = @import("translation.zig").Translation;
55795570
55805571const Resources = @import ("resources" ).Resources ;
55815572const Resource = @import ("resources" ).Resource ;
5582- const ResourcesError = @import ("resources" ).Resources .Error ;
55835573
55845574const default_themes = @import ("theme.zig" ).default_themes ;
55855575const Theme = @import ("theme.zig" ).Theme ;
0 commit comments