Skip to content

Colours and theming ​

The chat is an HTML page, so its colours are CSS — but you do not have to write any. The page defines everything through --hc-* variables, and the component fills them from the framework your application already uses. For what is not a colour - a radius, a spacing, a button you do not want - the application can add a stylesheet of its own: see Inside the panel.

VCL: it follows your style ​

With FollowVclStyle := True (the default) the panel is coloured after the active VCL style, and follows a style change at runtime, including while the chat is open:

pascal
TStyleManager.TrySetStyle('Windows11 Modern Dark');   // the chat follows

Five base colours are derived from the style — background, surface, text, border, accent — and the light/dark decision, using the same per-style table that StyledComponents curates for the styles shipped with Delphi (117 of them). For a style that is not in the table, the values come from StyleServices. The accent is the more saturated of the style's hot and hot-border colours, because several styles use a pale hover and keep the brand colour on the border.

Everything else — bubbles, muted text, code background, the contrast text on the accent — is derived from those, so a style you never heard of still produces a readable chat.

Four things the style does not decide ​

  • A light style gets a white page. The window colour of a light style is the grey of its forms - Windows10 answers #f3f3f3 - and the chat is read, not filled in: so under a light style the page is white, and the surfaces (header, footer, assistant bubbles, documentation page) keep the colour of the style. Where the style paints those white as well, they take a 4% step instead, or they would vanish into the page. Dark styles are left as they are: there the grey of the style is the reading surface.
  • The bars cast a shadow on the conversation, because they share their colour with the assistant bubbles: without it a bubble that reaches the top or the bottom edge melts into the bar. The colour is --hc-shadow (THelpChatTheme.Shadow), derived per mode like the rest.
  • Two bubbles of the same colour are told apart. Some styles answer the same colour for their accent and for their surface (Windows10 #cccccc, Windows10 Dark #262626), which would make the question and the answer one block: when the two are closer than 12% of the scale, the user's bubble steps away from the page and the assistant's one towards it. Write both of them in OnGetTheme and they are kept exactly as you set them.
  • A link must read on its bubble. Links, focus rings and the tick of a copied answer use --hc-link (THelpChatTheme.Link), which is the accent when the accent stands out from the assistant bubble, and otherwise the accent moved towards the text until it does. Windows10 gives the same grey for its accent and its surfaces, and its links used to be invisible on a light bubble; Carbon has the same problem on a dark one. For the same reason the send button takes the colour of the user's bubble, not the accent.

FollowVclStyle := False leaves the page with its own light/dark defaults, which follow the operating system preference.

FMX: ThemeMode ​

There are no VCL styles, so you choose:

pascal
HelpChatAI.ThemeMode := tmAuto;    // page defaults, following the system (default)
HelpChatAI.ThemeMode := tmLight;
HelpChatAI.ThemeMode := tmDark;

Adjusting the result ​

OnGetTheme receives the theme just before it is applied. Change what you want, leave the rest:

pascal
procedure TMainForm.HelpChatGetTheme(Sender: TObject; var ATheme: THelpChatTheme);
begin
  ATheme.UserBubble := '#c8102e';      // our brand red on the send button and user bubbles
  ATheme.UserText := '#ffffff';
  ATheme.FontFamily := 'Segoe UI, sans-serif';
end;

Every colour is a #rrggbb string. The theme arrives already completed - from a VCL style, or from tmLight / tmDark - so every colour has a value, and a colour that has a value is kept: changing Accent alone moves only --hc-accent (the selected entry of the model list), not the user bubble, the send button or the links, which were derived from the old accent. Either write the colour you mean (UserBubble, Link), or empty the derived ones (UserBubble, UserText, AccentText, Link) and they are derived again from the base colours when the theme is written. Empty the whole record and the page keeps its defaults.

pascal
// a theme of your own, ignoring the framework entirely
procedure TMainForm.HelpChatGetTheme(Sender: TObject; var ATheme: THelpChatTheme);
begin
  ATheme := THelpChatTheme.Dark;
  ATheme.Accent := '#00a3a3';
  ATheme.AccentText := '';    // the built-in theme is completed too: empty what
  ATheme.UserBubble := '';    // was derived from its accent, and it follows the new one
  ATheme.UserText := '';
  ATheme.Link := '';
end;

How it reaches the page ​

Two paths, so that a page never appears with the wrong colours:

  • at load, the theme is rendered as a :root { --hc-bg: ...; } rule placed after the stylesheet of the page - and after the CSS of PanelStyleSheet - so it wins;
  • at runtime, a style change pushes the new values into the open page with window.hcApplyTheme({...}) — no reload, no flicker.

A VCL style change recreates windows, which makes the WebView reload the page; the component stores the new theme before that happens, so the reload already asks for the right colours.

Changing the page itself ​

Before forking the page, see whether a stylesheet of your own is enough: PanelStyleSheet (a CSS file) and ATheme.StyleSheet in OnGetTheme add rules after the page's own, without rebuilding anything - Inside the panel.

The page (resources/panel.html, panel.css, panel.js plus htmx) is compiled into source/HelpChatAI.Panel.res. Edit the files, run Tools\BuildResources.cmd and rebuild: the whole chat is one self-contained page, with no external asset to deploy.

Two rules if you touch it:

  • never hard-code a colour outside the --hc-* definitions, or theming stops working;
  • a new outbound call must be named in the page's Content-Security-Policy, otherwise the browser drops it before it reaches the network.

Released under the Apache License 2.0