void StylePrepareStaticStyles() { int fontSize = GetPrefFontSize(); assert(NULL == staticStyles[0]); for (uint_t i = 0; i < ARRAY_SIZE(staticStyleDescriptors); ++i) { const char* def = staticStyleDescriptors[i].definition; staticStyles[i] = StyleParse(def, strlen(def)); #ifndef NDEBUG if (NULL == staticStyles[i]) DebugBreak(); #endif #ifdef _WIN32 // pre-create default fonts so that they are referenced at least once when used for the 1st time ScaleStyleFont(fontSize, *staticStyles[i]); staticStyles[i]->font(); #endif } #ifdef DEBUG test_StaticStyleTable(); #endif }
void xoMain(xo::SysWnd* wnd) { xo::Doc* doc = wnd->Doc(); int nx = 100; int ny = 100; for (int y = 0; y < ny; y++) { auto line = doc->Root.AddNode(xo::TagDiv); line->StyleParse("width: 100%; height: 4px; margin: 1px; display: block;"); for (int x = 0; x < nx; x++) { auto div = line->AddNode(xo::TagDiv); div->StyleParse("width: 1%; height: 100%; border-radius: 2px; margin: 1px; display: inline;"); div->StyleParsef("background: #%02x%02x%02x%02x", (uint8_t)(x * 5), 0, 0, 255); char txt[2] = "a"; txt[0] = 'a' + x % 26; div->AddText(txt); } } }
void ScaleStylesFontSizes(int fontSize) { if (NULL == staticStyles[0]) return; for (uint_t i = 0; i < ARRAY_SIZE(staticStyleDescriptors); ++i) { const char* def = staticStyleDescriptors[i].definition; staticStyles[i]->invalidateCachedFont(); StyleParse(*staticStyles[i], def, strlen(def)); ScaleStyleFont(fontSize, *staticStyles[i]); staticStyles[i]->font(); } }
bool DomNode::StyleParsef(const char* t, ...) { char buff[8192]; va_list va; va_start(va, t); uint32_t r = vsnprintf(buff, arraysize(buff), t, va); va_end(va); buff[arraysize(buff) - 1] = 0; if (r < arraysize(buff)) { return StyleParse(buff); } else { String str = String(t); str.Z[50] = 0; ParseFail("Parse string is too long for StyleParsef: %s...", str.Z); XO_DEBUG_ASSERT(false); return false; } }
void CFLTKEditor::StyleUpdate(int iPos, int nInserted, int nDeleted, int nRestyled, const char *deletedText) { int iStart, // Start of text iEnd; // End of text char cLast, // Last style on line *pcStyle, // Style data *pcText; // Text data // If this is just a selection change, just unselect the style buffer... if (nInserted == 0 && nDeleted == 0) { GetStyleBuffer()->unselect(); return; } // Track changes in the text buffer... if (nInserted > 0) { // Insert characters into the style buffer... pcStyle = new char[nInserted + 1]; memset(pcStyle, 'A', nInserted); pcStyle[nInserted] = '\0'; GetStyleBuffer()->replace(iPos, iPos + nDeleted /*nInserted*/, pcStyle); delete[] pcStyle; } else { // Just delete characters in the style buffer... GetStyleBuffer()->remove(iPos, iPos + nDeleted); } // Select the area that was just updated to avoid unnecessary // callbacks... if (iPos > 0) iPos--; GetStyleBuffer()->select(iPos, iPos + nInserted - nDeleted + 1); // Re-parse the changed region; we do this by parsing from the // beginning of the line of the changed region to the end of // the line of the changed region... Then we check the last // style character and keep updating if we have a multi-line // comment character... iStart = GetTextBuffer()->line_start(iPos); iEnd = GetTextBuffer()->line_end(iPos + nInserted + 1); if (iEnd+1 < GetTextBuffer()->length()) iEnd++; pcText = GetTextBuffer()->text_range(iStart, iEnd); pcStyle = GetStyleBuffer()->text_range(iStart, iEnd); cLast = pcStyle[iEnd - iStart - 1]; // printf("iStart = %d, iEnd = %d, pcText = \"%s\", pcStyle = \"%s\"...\n", // iStart, iEnd, pcText, pcStyle); m_bReparsing = false; m_bReparseAll = false; StyleParse(pcText, pcStyle, iEnd - iStart); // printf("new pcStyle = \"%s\"...\n", pcStyle); GetStyleBuffer()->replace(iStart, iEnd, pcStyle); GetEditor()->redisplay_range(iStart, iEnd); if (m_bReparseAll) //cLast != pcStyle[iEnd - iStart - 1] || pcStyle[iEnd - iStart - 1] == 'Z') { // The cLast character on the line changed styles, so reparse the // remainder of the buffer... free(pcText); free(pcStyle); iStart = 0; iEnd = GetTextBuffer()->length(); pcText = GetTextBuffer()->text_range(iStart, iEnd); pcStyle = GetStyleBuffer()->text_range(iStart, iEnd); m_bReparsing = true; StyleParse(pcText, pcStyle, iEnd - iStart); GetStyleBuffer()->replace(iStart, iEnd, pcStyle); GetEditor()->redisplay_range(iStart, iEnd); } free(pcText); free(pcStyle); }