27#include <Objectively/Hash.h>
31#include "stylesheet.css.h"
33#define _Class _Stylesheet
44 release(this->selectors);
45 release(this->styles);
53static int hash(
const Object *self) {
59 hash = HashForObject(
hash, this->selectors);
60 hash = HashForObject(
hash, this->styles);
68static _Bool
isEqual(
const Object *self,
const Object *other) {
70 if (super(Object, self,
isEqual, other)) {
74 if (other && $(other, isKindOfClass,
_Stylesheet())) {
80 return $((Object *) this->styles,
isEqual, (Object *) that->
styles);
87#pragma mark - Stylesheet
108 $((MutableArray *) accumulator, addObjectsFromArray, ((
Style *) obj)->selectors);
132 MutableArray *selectors = $$(MutableArray, array);
154 String *
string = $$(String, stringWithData, data, STRING_ENCODING_UTF8);
182 Resource *resource = $$(Resource, resourceWithName, name);
242#pragma mark - Class lifecycle
249 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
250 ((ObjectInterface *) clazz->interface)->hash =
hash;
251 ((ObjectInterface *) clazz->interface)->isEqual =
isEqual;
253 ((StylesheetInterface *) clazz->interface)->defaultStylesheet =
defaultStylesheet;
256 ((StylesheetInterface *) clazz->interface)->initWithResource =
initWithResource;
258 ((StylesheetInterface *) clazz->interface)->initWithString =
initWithString;
282 clazz = _initialize(&(
const ClassDef) {
283 .name =
"Stylesheet",
284 .superclass = _Object(),
286 .interfaceOffset = offsetof(
Stylesheet, interface),
287 .interfaceSize =
sizeof(StylesheetInterface),
ObjectivelyMVC: Object oriented MVC framework for OpenGL, SDL2 and GNU C.
static void destroy(Class *clazz)
static Stylesheet * stylesheetWithData(const Data *data)
static ident selectorsReducer(const ident obj, ident accumulator, ident data)
static _Bool isEqual(const Object *self, const Object *other)
static void dealloc(Object *self)
static Stylesheet * _defaultStylesheet
static void initialize(Class *clazz)
static int hash(const Object *self)
static Order selectorsComparator(const ident a, const ident b)
Comparator for Selector sorting.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Font * initWithData(Font *self, Data *data, int size, int index)
Data * data
The raw font data.
Image * initWithResourceName(Image *self, const char *name)
Initializes this Image, loading the Resource by the given name.
Image * initWithResource(Image *self, const Resource *resource)
Initializes this Image with the specified Resource.
Selectors are comprised of one or more SelectorSequences.
Order compareTo(const Selector *self, const Selector *other)
Compares this Selector to other, ordering by specificity.
Array * parse(const char *rules)
Parses the null-terminated C string of Selector rules into an Array of Selectors.
Stylesheets are comprised of Selectors and Styles.
Stylesheet * stylesheetWithCharacters(const char *chars)
Instantiates a new Stylesheet with the given CSS definitions.
Stylesheet * initWithData(Stylesheet *self, const Data *data)
Initializes this Stylesheet with the CSS definitions in data.
Array * styles
The Styles, keyed by Selector.
Stylesheet * stylesheetWithString(const String *string)
Instantiates a new Stylesheet with the given CSS String.
Stylesheet * defaultStylesheet(void)
Stylesheet * stylesheetWithResource(const Resource *resource)
Instantiates a new Stylesheet with the given CSS Resource.
Class * _Stylesheet(void)
The Stylesheet archetype.
Stylesheet * initWithCharacters(Stylesheet *self, const char *chars)
Initializes this Stylesheet with the given CSS definitions.
Array * selectors
The Selectors, ordered by specificity.
Stylesheet * initWithString(Stylesheet *self, const String *string)
Initializes this Stylesheet with the CSS definitions in string.
Stylesheet * stylesheetWithResourceName(const char *name)
Instantiates a new Stylesheet with the CSS Resource by the specified name.