Skip to content

Commit e2b2266

Browse files
fix(List): bgimg is to use texture_name internally
Should fix #4
1 parent 519042a commit e2b2266

File tree

2 files changed

+102
-68
lines changed

2 files changed

+102
-68
lines changed

spec/flow_extras_spec.lua

+101-67
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,75 @@ describe("List", function ()
5151
assert.same(gui.Stack{
5252
align_h = "center",
5353
align_v = "center",
54-
gui.Image{ bgimg = "flow_extras_list_bg.png", w = 1, h = 1 },
54+
gui.Image{ texture_name = "flow_extras_list_bg.png", w = 1, h = 1 },
5555
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 }
5656
}, flow_extras.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 })
5757
-- Should be noted that 0,0 is not a valid size, but this should not care.
5858
end)
59-
it("has a default theme background", function ()
60-
assert.same(gui.Stack{
61-
align_h = "center",
62-
align_v = "center",
63-
gui.Image{ w = 1, h = 1, bgimg = "flow_extras_list_bg.png" },
64-
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 }
65-
}, flow_extras.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 })
66-
end)
67-
it("accepts a theme background string", function ()
68-
assert.same(gui.Stack{
69-
align_h = "center",
70-
align_v = "center",
71-
gui.Image{ w = 1, h = 1, bgimg = "c" },
72-
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 }
73-
}, flow_extras.List{ inventory_location = "a", list_name = "b", w = 1, h = 1, bgimg = "c" })
74-
end)
75-
it("accepts a listof theme backgrounds", function ()
76-
assert.same(gui.Stack{
77-
align_h = "center",
78-
align_v = "center",
79-
gui.HBox{
80-
spacing = 0.25,
81-
gui.Image{ w = 1, h = 1, bgimg = "c" },
82-
gui.Image{ w = 1, h = 1, bgimg = "d" },
83-
gui.Image{ w = 1, h = 1, bgimg = "e" },
84-
gui.Image{ w = 1, h = 1, bgimg = "c" },
85-
gui.Image{ w = 1, h = 1, bgimg = "d" }
86-
},
87-
gui.List{ inventory_location = "a", list_name = "b", w = 5, h = 1 }
88-
}, flow_extras.List{ inventory_location = "a", list_name = "b", w = 5, h = 1, bgimg = { "c", "d", "e" } })
59+
describe("theme background", function ()
60+
it("has a default", function ()
61+
assert.same(gui.Stack{
62+
align_h = "center",
63+
align_v = "center",
64+
gui.Image{ w = 1, h = 1, texture_name = "flow_extras_list_bg.png" },
65+
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 }
66+
}, flow_extras.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 })
67+
end)
68+
it("can be overriden with a string", function ()
69+
assert.same(gui.Stack{
70+
align_h = "center",
71+
align_v = "center",
72+
gui.Image{ w = 1, h = 1, texture_name = "c" },
73+
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 }
74+
}, flow_extras.List{ inventory_location = "a", list_name = "b", w = 1, h = 1, bgimg = "c" })
75+
end)
76+
describe("list overriding", function ()
77+
it("works with default starting_item_index", function ()
78+
assert.same(gui.Stack{
79+
align_h = "center",
80+
align_v = "center",
81+
gui.HBox{
82+
spacing = 0.25,
83+
gui.Image{ w = 1, h = 1, texture_name = "c" },
84+
gui.Image{ w = 1, h = 1, texture_name = "d" },
85+
gui.Image{ w = 1, h = 1, texture_name = "e" },
86+
gui.Image{ w = 1, h = 1, texture_name = "c" },
87+
gui.Image{ w = 1, h = 1, texture_name = "d" }
88+
},
89+
gui.List{ inventory_location = "a", list_name = "b", w = 5, h = 1 }
90+
}, flow_extras.List{ inventory_location = "a", list_name = "b", w = 5, h = 1, bgimg = { "c", "d", "e" } })
91+
end)
92+
it("works with specific starting_item_index", function ()
93+
assert.same(gui.Stack{
94+
align_h = "center",
95+
align_v = "center",
96+
gui.HBox{
97+
spacing = 0.25,
98+
gui.Image{ w = 1, h = 1, texture_name = "e" },
99+
gui.Image{ w = 1, h = 1, texture_name = "c" },
100+
gui.Image{ w = 1, h = 1, texture_name = "d" },
101+
gui.Image{ w = 1, h = 1, texture_name = "e" },
102+
gui.Image{ w = 1, h = 1, texture_name = "c" },
103+
},
104+
gui.List{ inventory_location = "a", list_name = "b", w = 5, h = 1, starting_item_index = 2 }
105+
}, flow_extras.List{
106+
inventory_location = "a",
107+
list_name = "b",
108+
w = 5,
109+
h = 1,
110+
bgimg = { "c", "d", "e" },
111+
starting_item_index = 2
112+
})
113+
end)
114+
it("asserts an error when list length is zero, according to # operator", function ()
115+
assert.has_error(function ()
116+
return flow_extras.List{ inventory_location = "a", list_name = "b", w = 5, h = 1, bgimg = { } }
117+
end, "must not be a nil image 1")
118+
assert.has_error(function ()
119+
return flow_extras.List{ inventory_location = "a", list_name = "b", w = 5, h = 1, bgimg = { [2]="c" } }
120+
end, "must not be a nil image 1")
121+
end)
122+
end)
89123
end)
90124
it("works with two demensions", function ()
91125
assert.same(gui.Stack{
@@ -95,18 +129,18 @@ describe("List", function ()
95129
spacing = 0.25,
96130
gui.HBox{
97131
spacing = 0.25,
98-
gui.Image{ w = 1, h = 1, bgimg = "c" },
99-
gui.Image{ w = 1, h = 1, bgimg = "c" },
132+
gui.Image{ w = 1, h = 1, texture_name = "c" },
133+
gui.Image{ w = 1, h = 1, texture_name = "c" },
100134
},
101135
gui.HBox{
102136
spacing = 0.25,
103-
gui.Image{ w = 1, h = 1, bgimg = "c" },
104-
gui.Image{ w = 1, h = 1, bgimg = "c" },
137+
gui.Image{ w = 1, h = 1, texture_name = "c" },
138+
gui.Image{ w = 1, h = 1, texture_name = "c" },
105139
},
106140
gui.HBox{
107141
spacing = 0.25,
108-
gui.Image{ w = 1, h = 1, bgimg = "c" },
109-
gui.Image{ w = 1, h = 1, bgimg = "c" },
142+
gui.Image{ w = 1, h = 1, texture_name = "c" },
143+
gui.Image{ w = 1, h = 1, texture_name = "c" },
110144
}
111145
},
112146
gui.List{ inventory_location = "a", list_name = "b", w = 2, h = 3 }
@@ -122,15 +156,15 @@ describe("List", function ()
122156
spacing = 0.25,
123157
gui.HBox{
124158
spacing = 0.25,
125-
gui.Image{ w = 1, h = 1, bgimg = "c" },
126-
gui.Image{ w = 1, h = 1, bgimg = "c" },
127-
gui.Image{ w = 1, h = 1, bgimg = "c" }
159+
gui.Image{ w = 1, h = 1, texture_name = "c" },
160+
gui.Image{ w = 1, h = 1, texture_name = "c" },
161+
gui.Image{ w = 1, h = 1, texture_name = "c" }
128162
},
129163
gui.HBox{
130164
spacing = 0.25,
131-
gui.Image{ w = 1, h = 1, bgimg = "c" },
132-
gui.Image{ w = 1, h = 1, bgimg = "c" },
133-
gui.Image{ w = 1, h = 1, bgimg = "c" }
165+
gui.Image{ w = 1, h = 1, texture_name = "c" },
166+
gui.Image{ w = 1, h = 1, texture_name = "c" },
167+
gui.Image{ w = 1, h = 1, texture_name = "c" }
134168
}
135169
},
136170
gui.List{ inventory_location = "a", list_name = "b", w = 3, h = 2 }
@@ -142,8 +176,8 @@ describe("List", function ()
142176
align_v = "center",
143177
gui.VBox{
144178
spacing = 0.25,
145-
gui.Image{ w = 1, h = 1, bgimg = "c" },
146-
gui.Image{ w = 1, h = 1, bgimg = "c" }
179+
gui.Image{ w = 1, h = 1, texture_name = "c" },
180+
gui.Image{ w = 1, h = 1, texture_name = "c" }
147181
},
148182
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 2, starting_item_index = 6 }
149183
}
@@ -167,15 +201,15 @@ describe("List", function ()
167201
spacing = 0.25,
168202
gui.HBox{
169203
spacing = 0.25,
170-
gui.Image{ w = 1, h = 1, bgimg = "c" },
171-
gui.Image{ w = 1, h = 1, bgimg = "c" },
172-
gui.Image{ w = 1, h = 1, bgimg = "c" }
204+
gui.Image{ w = 1, h = 1, texture_name = "c" },
205+
gui.Image{ w = 1, h = 1, texture_name = "c" },
206+
gui.Image{ w = 1, h = 1, texture_name = "c" }
173207
},
174208
gui.HBox{
175209
spacing = 0.25,
176-
gui.Image{ w = 1, h = 1, bgimg = "c" },
177-
gui.Image{ w = 1, h = 1, bgimg = "c" },
178-
gui.Image{ w = 1, h = 1, bgimg = "c" }
210+
gui.Image{ w = 1, h = 1, texture_name = "c" },
211+
gui.Image{ w = 1, h = 1, texture_name = "c" },
212+
gui.Image{ w = 1, h = 1, texture_name = "c" }
179213
}
180214
},
181215
gui.List{ inventory_location = "a", list_name = "b", w = 3, h = 2 }
@@ -187,8 +221,8 @@ describe("List", function ()
187221
align_v = "center",
188222
gui.HBox{
189223
spacing = 0.25,
190-
gui.Image{ w = 1, h = 1, bgimg = "c" },
191-
gui.Image{ w = 1, h = 1, bgimg = "c" }
224+
gui.Image{ w = 1, h = 1, texture_name = "c" },
225+
gui.Image{ w = 1, h = 1, texture_name = "c" }
192226
},
193227
gui.List{ inventory_location = "a", list_name = "b", w = 2, h = 1, starting_item_index = 6 }
194228
}
@@ -212,15 +246,15 @@ describe("List", function ()
212246
gui.Stack{
213247
align_h = "center",
214248
align_v = "center",
215-
gui.Image{ bgimg = "flow_extras_list_bg.png", w = 1, h = 1 },
249+
gui.Image{ texture_name = "flow_extras_list_bg.png", w = 1, h = 1 },
216250
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 }
217251
},
218252
gui.HBox{
219253
align_h = "e",
220254
gui.Stack{
221255
align_h = "center",
222256
align_v = "center",
223-
gui.Image{ h = 1, w = 1, bgimg = "flow_extras_list_bg.png" },
257+
gui.Image{ h = 1, w = 1, texture_name = "flow_extras_list_bg.png" },
224258
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1, starting_item_index = 1 }
225259
}
226260
}
@@ -242,15 +276,15 @@ describe("List", function ()
242276
gui.Stack{
243277
align_h = "center",
244278
align_v = "center",
245-
gui.Image{ h = 1, w = 1, bgimg = "flow_extras_list_bg.png" },
279+
gui.Image{ h = 1, w = 1, texture_name = "flow_extras_list_bg.png" },
246280
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 }
247281
},
248282
gui.VBox{
249283
align_v = "e",
250284
gui.Stack{
251285
align_h = "center",
252286
align_v = "center",
253-
gui.Image{ h = 1, w = 1, bgimg = "flow_extras_list_bg.png" },
287+
gui.Image{ h = 1, w = 1, texture_name = "flow_extras_list_bg.png" },
254288
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1, starting_item_index = 1 }
255289
}
256290
}
@@ -271,13 +305,13 @@ describe("List", function ()
271305
gui.Stack{
272306
align_h = "center",
273307
align_v = "center",
274-
gui.Image{ h = 1, w = 1, bgimg = "flow_extras_list_bg.png" },
308+
gui.Image{ h = 1, w = 1, texture_name = "flow_extras_list_bg.png" },
275309
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1, starting_item_index = 100 }
276310
},
277311
gui.Stack{
278312
align_v = "center",
279313
align_h = "center",
280-
gui.Image{ h = 1, w = 1, bgimg = "flow_extras_list_bg.png" },
314+
gui.Image{ h = 1, w = 1, texture_name = "flow_extras_list_bg.png" },
281315
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1, starting_item_index = 101 }
282316
}
283317
}, flow_extras.List{
@@ -293,7 +327,7 @@ describe("List", function ()
293327
gui.Stack{
294328
align_h = "center",
295329
align_v = "center",
296-
gui.Image{ w = 1, h = 1, bgimg = "flow_extras_list_bg.png" },
330+
gui.Image{ w = 1, h = 1, texture_name = "flow_extras_list_bg.png" },
297331
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 1 }
298332
},
299333
gui.Listring{ inventory_location = "a", list_name = "b" },
@@ -320,7 +354,7 @@ describe("List", function ()
320354
gui.VBox{
321355
spacing = 0.25,
322356
gui.Spacer{ w = 1, h = 1, expand = false },
323-
gui.Image{ w = 1, h = 1, bgimg = "c" }
357+
gui.Image{ w = 1, h = 1, texture_name = "c" }
324358
},
325359
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 2 },
326360
}, flow_extras.List{ inventory_location = "a", list_name = "b", w = 1, h = 2, bgimg = { false, "c" } })
@@ -336,13 +370,13 @@ describe("List", function ()
336370
spacing = 1,
337371
gui.HBox{
338372
spacing = 1,
339-
gui.Image{ w = 1, h = 1, bgimg = "flow_extras_list_bg.png" },
340-
gui.Image{ w = 1, h = 1, bgimg = "flow_extras_list_bg.png" }
373+
gui.Image{ w = 1, h = 1, texture_name = "flow_extras_list_bg.png" },
374+
gui.Image{ w = 1, h = 1, texture_name = "flow_extras_list_bg.png" }
341375
},
342376
gui.HBox{
343377
spacing = 1,
344-
gui.Image{ w = 1, h = 1, bgimg = "flow_extras_list_bg.png" },
345-
gui.Image{ w = 1, h = 1, bgimg = "flow_extras_list_bg.png" }
378+
gui.Image{ w = 1, h = 1, texture_name = "flow_extras_list_bg.png" },
379+
gui.Image{ w = 1, h = 1, texture_name = "flow_extras_list_bg.png" }
346380
}
347381
},
348382
gui.List{ inventory_location = "a", list_name = "b", w = 2, h = 2 }
@@ -352,8 +386,8 @@ describe("List", function ()
352386
align_v = "center",
353387
gui.VBox{
354388
spacing = 1,
355-
gui.Image{ w = 1, h = 1, bgimg = "flow_extras_list_bg.png" },
356-
gui.Image{ w = 1, h = 1, bgimg = "flow_extras_list_bg.png" }
389+
gui.Image{ w = 1, h = 1, texture_name = "flow_extras_list_bg.png" },
390+
gui.Image{ w = 1, h = 1, texture_name = "flow_extras_list_bg.png" }
357391
},
358392
gui.List{ inventory_location = "a", list_name = "b", w = 1, h = 2, starting_item_index = 4 }
359393
}

widgets/list.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ local function ThemableList(fields)
3535
bgimg_idx = bgimg_idx + 1
3636
return (type(the_image) == "boolean" and not the_image) and
3737
gui.Spacer{ w = 1, h = 1, expand = false } or
38-
gui.Image{ w = 1, h = 1, bgimg = the_image }
38+
gui.Image{ w = 1, h = 1, texture_name = the_image }
3939
end
4040
},
4141
gui.List(fields)

0 commit comments

Comments
 (0)