Theme Controller — sgcHTML | eSeGeCe

Theme Controller

TsgcHTMLThemeController / TsgcHTMLThemeBuilder — manage light, dark and system themes across all pages and generate Bootstrap CSS variable blocks for custom brand colours.

TsgcHTMLThemeController & TsgcHTMLThemeBuilder

TsgcHTMLThemeController selects a page theme (ptDefault, ptDark or ptDarkPro) and generates the matching CSS to inject into the page head. TsgcHTMLThemeBuilder generates a <style> block that overrides Bootstrap CSS variables with your brand colours.

Component classes

TsgcHTMLThemeController, TsgcHTMLThemeBuilder

Role

Light/dark theming & custom CSS

Languages

Delphi, C++ Builder, .NET

Switch themes, inject custom colours

Use TsgcHTMLThemeController to pick a page theme and emit its CSS with GetCSS. Use TsgcHTMLThemeBuilder to emit a custom CSS variable block for your brand colours.

uses
  sgcHTML_Component, sgcHTML_ThemeBuilder, sgcHTML_Template_Bootstrap;

// 1) Pick a page theme and inject its CSS into the head:
var
  oTheme: TsgcHTMLThemeController;
begin
  oTheme := TsgcHTMLThemeController.Create(nil);
  try
    oTheme.Theme     := ptDark;   // ptDefault / ptDark / ptDarkPro
    oTheme.CustomCSS := '.navbar{border-bottom:2px solid #7C3AED;}';
    // GetCSS = shared component CSS + theme CSS + your CustomCSS:
    oTemplate.ThemeCSS := oTheme.GetCSS;
  finally
    oTheme.Free;
  end;
end;

// 2) Override Bootstrap CSS variables with your brand colours:
var
  oBuilder: TsgcHTMLThemeBuilder;
begin
  oBuilder := TsgcHTMLThemeBuilder.Create(nil);
  try
    oBuilder.PrimaryColor   := '#7C3AED';
    oBuilder.SecondaryColor := '#1E293B';
    // GetHTML returns a <style> block (+ sync script for tmSystem):
    oTemplate.CustomHead := oTemplate.CustomHead + oBuilder.GetHTML;
  finally
    oBuilder.Free;
  end;
end;
TsgcHTMLThemeController *oTheme = new TsgcHTMLThemeController(NULL);
try
{
  oTheme->Theme    = ptDark;   // ptDefault / ptDark / ptDarkPro
  oTheme->CustomCSS = ".navbar{border-bottom:2px solid #7C3AED;}";
  oTemplate->ThemeCSS = oTheme->GetCSS();
}
__finally { delete oTheme; }

TsgcHTMLThemeBuilder *oBuilder = new TsgcHTMLThemeBuilder(NULL);
try
{
  oBuilder->PrimaryColor   = "#7C3AED";
  oBuilder->SecondaryColor = "#1E293B";
  oTemplate->CustomHead = oTemplate->CustomHead + oBuilder->GetHTML();
}
__finally { delete oBuilder; }
var themeCtrl = new TsgcHTMLThemeController();
themeCtrl.Theme     = TsgcHTMLPageTheme.ptDark;   // ptDefault / ptDark / ptDarkPro
themeCtrl.CustomCSS = ".navbar{border-bottom:2px solid #7C3AED;}";
template.ThemeCSS = themeCtrl.GetCSS();

var themeBuilder = new TsgcHTMLThemeBuilder();
themeBuilder.PrimaryColor   = "#7C3AED";
themeBuilder.SecondaryColor = "#1E293B";
template.CustomHead += themeBuilder.GetHTML();

Key properties & methods

The members you reach for most often.

TsgcHTMLThemeController.Theme

Selects the page theme: ptDefault, ptDark or ptDarkPro.

TsgcHTMLThemeController.CustomCSS

Extra CSS appended to the generated theme CSS for per-app tweaks.

GetCSS / GetSharedCSS

GetCSS returns the shared component CSS plus the selected theme CSS plus your CustomCSS, ready to inject into <head>. The class method GetSharedCSS returns just the shared component CSS.

TsgcHTMLThemeBuilder.PrimaryColor

Overrides Bootstrap's --bs-primary CSS variable with your brand colour.

TsgcHTMLThemeBuilder.Mode

Palette mode: tmLight, tmDark or tmSystem (system follows the OS preference via a media query).

TsgcHTMLThemeBuilder.GetHTML

Returns a <style> block built from the colour properties, plus an OS-preference sync script when Mode is tmSystem.

Keep exploring

Online HelpFull API reference and usage guide for this component.
All sgcHTML ComponentsBrowse the full feature matrix of 80+ components.
Download Free TrialThe 30-day trial ships the 60.HTML demo projects.
PricingSingle, Team and Site licenses with full source code.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and start building web UIs in Delphi, C++ Builder and .NET.