Implement style property retrieval with inheritance.

This commit is contained in:
Tom Rothamel
2013-12-27 23:19:35 -05:00
parent c4ebac7fcf
commit 4e2916c3f0
2 changed files with 38 additions and 6 deletions
+33 -5
View File
@@ -223,19 +223,47 @@ cdef class StyleCore:
Retrieves the property at `index` from this style or its parents.
"""
cdef PyObject *o
# The current style object we're looking at.
cdef StyleCore s
# The style object we'll backtrack to when s has no down-parent.
cdef StyleCore left
index += self.offset
if not self.built:
build_style(self)
cdef PyObject *o
s = self
left = None
while True:
# If we have the style, return it.
if s.cache != NULL:
o = s.cache[index]
if o != NULL:
return <object> o
# If there is no left-parent, and we have one, store it.
if left is None and s.left_parent is not None:
left = s.left_parent
s = s.down_parent
# If no down-parent, try left.
if s is None:
s = left
left = None
# If no down-parent or left-parent, default to None.
if s is None:
return None
o = self.cache[index]
if o == NULL:
return None
return <object> o
from renpy.styleclass import Style
+5 -1
View File
@@ -65,7 +65,11 @@ class TestStyles(unittest.TestCase):
build_styles()
s = sm.prefs_default["foo"]
assert s.bold == "default_foo"
assert s.italic == "prefs_default"
assert s.size == "default"