Author Topic: [ANN] TyControls 3.0 released: 165 custom-drawn, themeable controls for Lazarus  (Read 5439 times)

ACTom

  • New Member
  • *
  • Posts: 15
Hi all,

TyControls 3.0 is out: 165 controls for Lazarus that draw themselves (with BGRABitmap) and take their whole look from a theme.

The same program can look like a classic desktop application, with bevels and gradient headers, or like a modern flat one in the style of today's web and Electron apps. One property switches the whole window, title bar included, between 17 built-in themes, each in light and dark, while the program runs. Nothing native is drawn, so it looks the same on Windows, Linux and macOS.

This is a visual library, so the pictures say more than I can:

Switching themes is one line

Code: Pascal  [Select][+][-]
  1. TyRegisterBuiltinThemes;                 // once at startup (unit tyControls.BuiltinThemes)
  2. TyStyleController1.ThemeName := 'macos'; // or win11, classic, material3, fluent, ...
  3. TyStyleController1.Mode := 'dark';       // or 'light'
  4.  

Every control repaints in the new theme, no restart. Light/dark and the accent colour can also follow the OS. In the form designer you see the theme live as you set it.

Themes are text you can edit

A theme is a CSS-like .tycss file, so you can change one or write your own without recompiling:

Code: [Select]
TyButton         { border-radius: var(--radius); padding: 6px 9px; }
TyButton:hover   { background: var(--card-hover); }
TyButton.primary { background: var(--accent); color: var(--on-accent); }

A single control can be adjusted on its own too: set its StyleOverride to border-radius: 14px; in the Object Inspector, and it still follows every theme change.

Also in the box
  • Everyday controls plus the heavy ones: a data grid with per-column editors, a multi-column virtual tree, a ribbon with key tips, charts, a calendar, shell file browsing and 20 custom-drawn dialogs
  • HiDPI: vector drawing, crisp at any scaling, and it adapts when a window moves to a monitor with different scaling
  • Designer support: palette, containers you drop controls straight into, File > New templates for a themed application or form
  • 2,022 Lucide icons, referenced by name; the ones you don't use cost nothing
  • English and Chinese UI strings (gettext .po)
  • 6,000+ unit tests, and the whole suite runs leak-free

Getting it

Lazarus 3.0 or later, FPC 3.2.2 or later, BGRABitmap (BGRABitmapPack). Windows (win32/win64), Linux (gtk2, qt5, qt6; gtk3 partially) and macOS (cocoa).
  • OPM: TyControls is in the Online Package Manager.
  • By hand: download the zip from the release page, install BGRABitmapPack, then open tycontrols_dt.lpk and click Use > Install.

Then File > New... > Project > TyControls Application gives you a themed main form to start from. The getting started guide takes it from there.

Links

License: modified LGPL, the same as the LCL, so you can use it in closed-source applications.

3.0 is the first stable release; the 2.x versions were previews. Thanks to everyone who tried them and reported problems. Bug reports and suggestions are welcome, here or on GitHub.

ACTom
« Last Edit: October 01, 2026, 06:47:43 am by ACTom »

fcu

  • Full Member
  • ***
  • Posts: 136
very nice , thanks for sharing
i find maybe a bug

ACTom

  • New Member
  • *
  • Posts: 15
very nice , thanks for sharing
i find maybe a bug
Aha, this bug is quite interesting. I'll fix it along with others in the next version. 
The control is still in a relatively early stage of development, so there should be quite a few minor bugs.

Antek

  • New Member
  • *
  • Posts: 34
This looks really impressive!

Quote
- A borderless-window control with a custom title bar, for modern-looking forms

Using the "Demo" program I was not able to resize the app (right/buttom)

Using the "Dialogs" program  I was able to resize the app but there is graphical problem with client area?!

I think this is because of TTyTitleBar (doing some "form(window) drawing stuff")

Also using windows, the"Snap-Features" are not available (e.g.throwing the window to the right)

Win11 24h2 / Laz4.8-fpc3.2.2 /32bit 96dpi
 
best

Antek

  • New Member
  • *
  • Posts: 34
second anim

ACTom

  • New Member
  • *
  • Posts: 15
second anim

Both of the issues you reported are caused by a problem in Windows DWM where, after setting a borderless window with shadows, parts of the main window's right and bottom areas fail to render. The new version resolves this by introducing a surface window. You can try the current code on the main branch when you have time.

The new version introduces more controls and is currently being prepared for release, with various bug fixes in progress. We hope to receive more feedback.

Antek

  • New Member
  • *
  • Posts: 34
I think the controls are just great. Awsome work!

I've been following the project over the past few weeks and testing it repeatedly. I'm just thrilled.

As far as I can tell, the “window problem” has been handled well using ‘TtyFormsurface’ and “ttytitlebar”!
However, there are still two minor issues (on Windows):

- Aero Snap doesn’t work correctly: When the form is dragged to the center to maximize it, the window is resized but not maximized!

-  When a window is maximized, it can’t be "normalized" by dragging
  --> tyControls.Form;TitleBarMouseMove:
 
Code: Pascal  [Select][+][-]
  1.   { Don't drag-move a maximized window (a maximized window has no movable position; a
  2.     post-maximize MouseMove with a still-armed drag would otherwise yank it back toward the
  3.     press origin — the double-click-to-maximize "grew in place" bug). }

At least on windows the behavior should be like I mentioned

For the first I was not able to find relevant source entry point to solve the problem.

For second issue I tried some "hacky" code in TitleBarMouseMove and MouseDown and forcing "ToggleMaximize; "  That works only have the way....
 

Antek

  • New Member
  • *
  • Posts: 34
TtySteps ; antdesign example
Arrow keys do not work... (because of no focus?)

Again, great work!


Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1330
This looks an impressive body of work!

You've piqued my interest.  In https://github.com/ACTom/TyControls/blob/main/README.en.md you mention "Appearance additionally has a pixel-level golden guard — every change to a theme's resolved styles must be deliberate."

What is a pixel-level golden guard and how is it implemented?  I'm assuming this is a form of unit test for gui's?   
Lazarus Trunk/FPC latest fixes on Windows 11
  How to use the forum:  https://wiki.lazarus.freepascal.org/Forum

ACTom

  • New Member
  • *
  • Posts: 15
I think the controls are just great. Awsome work!

I've been following the project over the past few weeks and testing it repeatedly. I'm just thrilled.

As far as I can tell, the “window problem” has been handled well using ‘TtyFormsurface’ and “ttytitlebar”!
However, there are still two minor issues (on Windows):

- Aero Snap doesn’t work correctly: When the form is dragged to the center to maximize it, the window is resized but not maximized!

-  When a window is maximized, it can’t be "normalized" by dragging
  --> tyControls.Form;TitleBarMouseMove:
 
Code: Pascal  [Select][+][-]
  1.   { Don't drag-move a maximized window (a maximized window has no movable position; a
  2.     post-maximize MouseMove with a still-armed drag would otherwise yank it back toward the
  3.     press origin — the double-click-to-maximize "grew in place" bug). }

At least on windows the behavior should be like I mentioned

For the first I was not able to find relevant source entry point to solve the problem.

For second issue I tried some "hacky" code in TitleBarMouseMove and MouseDown and forcing "ToggleMaximize; "  That works only have the way....
I've also noticed this issue you mentioned. It's on the recent fix list and should be resolved within a day or two.

Quote
TtySteps ; antdesign example
Arrow keys do not work... (because of no focus?)
This should be a focus issue. The entire focus system currently has some problems, such as being unable to obtain focus when clicking a button. Previously, we only fixed auto-focusing on things like checkboxes, but it wasn't comprehensive enough. This will also be addressed systematically in the near future.

Quote
This looks an impressive body of work!

You've piqued my interest.  In https://github.com/ACTom/TyControls/blob/main/README.en.md you mention "Appearance additionally has a pixel-level golden guard — every change to a theme's resolved styles must be deliberate."

What is a pixel-level golden guard and how is it implemented?  I'm assuming this is a form of unit test for gui's?   
Haha, this should be from when I encountered some issue with an AI's analysis on a certain topic and the AI added this on its own. Below is Claude's response: 
Code: Text  [Select][+][-]
  1. Good question — and "pixel-level" is admittedly loose wording on my part. It is not screenshot comparison. Let me explain what it actually does.
  2.  
  3. What it guards
  4.  
  5. TyControls resolves every control's appearance through a theme engine: a .tycss stylesheet is parsed, merged with a built-in base layer, and then queried as ResolveStyle(typeKey, variant, states) which returns a TTyStyleSet — background fill, text colour, border colour/width/style, corner radii, padding, font family/size/weight, opacity, shadow, outline. Those values are what ultimately decides what pixels get drawn. The golden test snapshots those values, not the rendered output.
  6.  
  7. How it works
  8.  
  9. The test (TTestThemeGolden in tests/test.themes.pas) walks a fixed grid of 203 (typeKey, variant) pairs — TyButton|, TyButton|primary, TyButton|danger, TyListItem|, … — times 5 states (normal / hover / active / focused / disabled), calls ResolveStyle for each, and serialises the entire returned record to one line of text:
  10.  
  11. TyButton|primary|1 => pres[0,1,2,3,4,5,7,8,] bg=k1/FF4B8CF7 ut=0 txt=FFFFFFFF
  12.                       bd=FFBCC0C5/1/0 rad=6/6,6,6,6 pad=6,6,6,6 fnt=/9/400
  13.                       op=1000 sh=00000000/0/0,0 ol=00000000/0/0
  14. Colours are ARGB hex, everything else integers — exact comparison, no tolerance. The dump is kind-aware, so a gradient fill serialises as from>to@angle, an image fill as path/mode/blur, and so on. Resolved size tokens (ResolveMetric) are appended too, because runtime geometry used to sit outside the guard and a mistyped token would just silently fall back.
  15.  
  16. That whole dump is compared byte-for-byte against a committed file, one per theme (tests/golden/{light,dark,showcase}.golden.txt, ~1100 lines each). On mismatch the test writes the new dump next to it as .golden.txt.actual and fails with "diff these two; if the change was intended, update the golden." On first run for a new theme it just bootstraps the file instead of failing.
  17.  
  18. So is it a GUI unit test?
  19.  
  20. More of a snapshot / characterisation test. It runs completely headless — no window, no widgetset, no rendering — which is exactly why it can afford to cover 203 × 5 × 3 combinations and still be instant and perfectly deterministic (no font hinting, GPU or DPI variance to fight).
  21.  
  22. The point isn't to freeze the design. It's that changing one line of CSS, or refactoring the merge/resolve order, or moving a token between tiers, can quietly shift a colour in a state nobody was looking at. The golden makes you look at the diff and confirm you meant it.
  23.  
  24. Two caveats worth knowing if you copy the idea
  25.  
  26. The grid is a hand-maintained array, so a newly added control is not automatically guarded — you have to add its typeKey. We learned that the hard way; a whole batch of controls had no coverage for a while because the list simply stopped where it had been written.
  27.  
  28. And it only covers three themes; the other bundled skins are guarded by a different test that asserts newly-split keys still resolve identically to the key they were split from, in every skin.
  29.  
  30. There are real-pixel tests as well, but they're written per control and there are far fewer: render the control to a TBitmap via RenderTo, then probe specific coordinates and assert the colour. Those answer a different question — "is the resolved value actually being painted?" — which the golden can't see.
  31.  

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1330
Those values are what ultimately decides what pixels get drawn. The golden test snapshots those values, not the rendered output.

Ah.  Naming makes sense now I know the history :-)   I was wondering how UI unit tests were handled.  Thanks
Lazarus Trunk/FPC latest fixes on Windows 11
  How to use the forum:  https://wiki.lazarus.freepascal.org/Forum

Antek

  • New Member
  • *
  • Posts: 34
@ACTom
I checked/tested tyscrollbox it seem that this component is broken.

- Weird scrollbar visibility and location
- No or wrong child component calculations..

best

Antek

  • New Member
  • *
  • Posts: 34
AeroSnap
Quote
I've also noticed this issue you mentioned. It's on the recent fix list and should be resolved within a day or two.

from 3alpha branch known_gaps:
Quote
Windows Aero Snap (edge tiling + snap-to-top maximize): implemented on the Win32 widgetset.

Just tested and seems to work (win11 ;laz 4.8-32bit)! Great work!

best

Antek

  • New Member
  • *
  • Posts: 34
@ACTom

known_gaps:

Quote
Borderless-window rounded corners + native drop shadow: implemented in tyControls.WindowEffects (TyApplyWindowEffects), applied by TTyForm on show/theme/maximize. ON by default; opt out via TyForm { border-radius: 0; window-shadow: false; }.

Code: CSS  [Select][+][-]
  1. TyForm { border-radius: 0; window-shadow: false;}


tested with antdesign.tycss :
border-radius is (partly?)working but window-shadow is always shown.

Is there a way to apply above to a ttyform at runtime like other controls "StyleOverride" ?

best

« Last Edit: July 28, 2026, 07:59:50 pm by Antek »

Antek

  • New Member
  • *
  • Posts: 34
@ACTom
EDIT: couldn't use tyscrollcontent from latest commit (d1849d2).

---

tyscrollbox issue ;tested with latest commit  cef6109(fix(scrollbox): keep the content )

 - Scrollbars behind child control(panel),( I know that scroll bar is also child of scrollbox)
-  Scroll using mouse wheel: first delta/tick of wheel is forcing movement scrollbar to wrong direction
- using the Scrollbars : scrollbar flicker/repaint issue? or (wrong recursive) calculation issue?
-using the Scrollbars : content movement a bit strange hopping?!--> check gif

best
« Last Edit: July 30, 2026, 01:13:22 pm by Antek »

 

TinyPortal © 2005-2018