bool Control::SetStyle(Style *style) { CachedStyle *newCachedStyle = CacheStyle(style); if (newCachedStyle != cachedStyle) { cachedStyle = newCachedStyle; return true; } return false; }
// returns true if the style of control has changed bool Control::SetStyle(Style *style) { bool changed; CachedStyle *currStyle = cachedStyle; cachedStyle = CacheStyle(style, &changed); if (currStyle != cachedStyle) changed = true; if (changed) RequestRepaint(this); return changed; }
// styles are cached globally, so we only add a style if it doesn't // exist already static void CacheStyleFromStruct(TxtNode* def) { CrashIf(!def->IsStructWithName("style")); TxtNode* nameNode = TxtChildNodeWithKey(def, "name"); CrashIf(!nameNode); // must have name or else no way to refer to it AutoFree tmp(nameNode->ValDup()); if (StyleByName(tmp)) return; Style* style = new Style(); for (TxtNode* node = def->firstChild; node != nullptr; node = node->sibling) { CrashIf(!node->IsText()); AddStyleProp(style, node); } CacheStyle(style, nullptr); }
// styles are cached globally, so we only add a style if it doesn't // exist already static void CacheStyleFromStruct(TxtNode* def) { CrashIf(!def->IsStructWithName("style")); TxtNode *nameNode = TxtChildNodeWithKey(def, "name"); CrashIf(!nameNode); // must have name or else no way to refer to it ScopedMem<char> tmp(nameNode->ValDup()); if (StyleByName(tmp)) return; Style *style = new Style(); size_t n = def->children->Count(); for (size_t i = 0; i < n; i++) { TxtNode *node = def->children->At(i); CrashIf(!node->IsText()); AddStyleProp(style, node); } CacheStyle(style, NULL); }
void Control::SetStyle(Style *style) { cachedStyle = CacheStyle(style); }