Overview
Fresnel is a visual component library based on CSS and custom drawn components. It is in an early stage of development.
git repo: https://gitlab.com/freepascal.org/lazarus/fresnel
Requirements: fpc 3.2.2 and Lazarus 4.99.
Advantages
- CSS-Driven Design: Separate design from logic cleanly using familiar CSS rules (inline styling, classes, IDs, selectors, and pseudo-classes like :hover).
- Modern Layout Engines: Supports flex, grid, and flow layouters for dynamic, responsive UI designs.
- Coexists with the LCL: Run Fresnel forms alongside LCL forms, or embed a Fresnel viewport directly inside an LCL control (TFresnelLCLControl).
- Detailed control over the appearance of every element
- Flexible Units: Define elements using em, vh, cm, mm, %, or px, along
- CSS is a standard, so you can use one of the many website stylesheets of your choice
- Text with highlighting, decorations, placeholders, icons, floats, etc.
- Font fallbacks: if your favorite font is missing a glyph, it uses the glyph of the fallback and so forth. see font-family.
- Color spaces (not yet implemented)
- Animations
- Subpixel rendering
- Visual Tools: Includes a dockable CSS Inspector in Lazarus, live CSS updating, and a form designer package.
Quick Start
Download/clone the above git repository. Then open in Lazarus one of the demos, e.g. demo/ButtonGenerator/ButtonGenerator.lpi
The above screenshot was using the skia renderer. The LCL renderer lacks some features and does not use sub pixel rendering.
Gallery
The InspectorDemo showing CSS rules of an element and its box model properties:
The IDEDemo with a port of SynEdit as editor control:
Platforms
Fresnel runs already natively on
- Linux/gtk3 native or optionally using Skia.
- Macos with Skia
- Webassembly in the browser using fpc 3.3.1.
- Windows with Skia.
- Fresnel Skia compiles even with fpc 3.2.2 using a subset wrapper.
Fresnel forms can also run inside an LCL application.
- A Fresnel form can be used inside an LCL app. This allows to migrate LCL forms one by one.
- Fresnel runs everywhere the LCL runs.
- Renderer: With Skia or directly on the LCL canvas.
- Finally there is a LCL control TFresnelLCLControl, allowing to embed a Fresnel viewport as a control on a LCL form.
Documentation
Docs in the git repository
Architecture - explains how Fresnel is put together, in plain language, for someone who is new to the code.
Controls - explains, for each control, what elements it is made of and which CSS you can write to change its look.
Development Guide - how to build Fresnel, run the tests, and write your first app, in plain steps.
Wiki pages
What is working?
As Fresnel is still in an alpha stage, many things do work already:
- fcl-css supports big part of CSS parsing, even some CSS-5 feats (the actual attributes are done by TFresnelElement)
- Lazarus package:
- src/fresnel.lpk containing the runtime units for standalone applications.
- src/lcl/fresnellcl.lpk containing the runtime units for Fresnel inside a LCL applications.
- A designtime package design/fresneldsgn.lpk registering a Fresnel Form, allowing to put TBody, TDiv, TSpan, etc onto the designer.
- Current platforms:
- Linux/Gtk3, native or with Skia
- Windows with Skia
- WebAssembly - for a website
- Inside a LCL application' as window: TFresnelForm - for LCL applications
- Using LCL canvas for rendering (default)
- Using Skia as renderer: add an IDEMacro value FresnelLCLRenderer:=skia to Additions and Overrides
- Inside a LCL form as control: TFresnelLCLControl - to embed Fresnel inside an LCL form
- Layouters: flow, flex, grid
- Elements:
- TFresnelElement
- a TComponent that works similar to an HTML element
- supports many common CSS attributes like border, padding, margin, etc
- has inline CSS in the Style property and CSS classes in the CSSClasses property
- You can define descendants adding their own CSS attributes.
- TFresnelViewport - a TFresnelElement that is the root of the tree.
- TReplacedElement - a TFresnelElement leaf node
- TTextElement - a TReplacedElement with a Text property. Text can fragment and/or merge with other inline Text.
- TFresnelForm - a window with a viewport
- TFresnelElement
- Controls (specialized elements):
- Foundations and containers — TBody, TDiv, TSpan, TLabel, TImage, TPanel, TGroupBox
- Buttons and toggles — TButton, TCheckBox, TRadioButton, TToggle, TCheckGroup, TRadioGroup
- Text input — TEdit, TMemo, TButtonEdit, TWordsEdit
- Lists and combo boxes — TListBox, TColorListBox, TCheckListBox, TGroupedListBox, TComboBox
- Tabs, splitters and bars — TTabs, TPageControl, TTabSheet, TSplitter, TStatusBar, TToast
- Trees and calendars — TTreeView, TCalendar, TCalendarEdit
- Grids — TGrid, TDBGrid
- Indicators and shapes — TProgressBar, TTrackBar, TSpinner, TShape
- Menus — TMainMenu, TPopupMenu
- A code editor - TFresnelSynEdit
- Dialogs:
- TFresnelOpenDialog, TFresnelSaveDialog, TFresnelSelectDirectoryDialog
- TFresnelPrintDialog, TFresnelPageSetupDialog
- TFresnelColorDialog
- TFresnelFontDialog
- Lazarus Designer for TFresnelForm
- Menu item for adding a new Fresnel form: .pas, .lfm and .css file.
- Menu item for create a new Fresnel native application
- Editing a form's css updates the form with short delay.
- CSS Inspector as dockable window.
Skia
- On Linux:
Skia is a dynamic lib. Set the environment variable:
set or export LD_LIBRARY_PATH=~/pathtoyour/fresnel/bin/Binary/Shared/Linux64/
- On aarch64 Mac:
Skia is a static lib. Add your fpc linker search path -FL:
/Users/USERNAME/pathtoyour/fresnel/bin/Binary/Static/OSXARM64
- On intel Mac:
For the static library add to the linker search path -FL:
/Users/USERNAME/pathtoyour/fresnel/bin/Binary/Static/OSX64
Goals
The main goals are at the moment:
- CSS development tools
- Lazarus designer tools
- drag&drop on a form, between forms, from external, to external
Roadmap
- CSS engine:
- Log warnings for invalid CSS attributes
- CSS functions calc, min, max, minmax, clamp.
- CSS Inspector
- Shorthands: strikethrough parts
- Grid layout inspector
- Flex layout inspector
- Computed values
- Changed page
- Element Tree view, for selecting elements
- Lazarus/Designer
- Inspector: add, delete attribute in Lazarus
- Inspector: add. delete rule in Lazarus.
- Mark CSS errors in source editor
- Rename CSS identifiers when renaming a form element
- CSS help
- Extend Lazarus lfm repair wizard to support duplicate classnames
- Extend Lazarus Change Class to support duplicate classnames
- Property editors and component editors
- Layouter:
- Flow layouter:
- direction: ltr
- position: sticky, absolute, fixed
- Flex layouter:
- direction: ltr
- Flow layouter:
- Canvas
- offscreen canvas
- more graphic functions
- TPicture like component storing various image formats
- TImage support for svg
- Renderer-LCL:
- Testsuite
- borders: style
- opacity
- Renderer-Skia:
- Skia
- Testsuite
- borders: style
- Cocoa native renderer
- Other:
- stylesheets for windows, linux, macos:
- require more background and border features, system colors, system icons, system fonts
- backend should dynamically create the theme and set custom attributes
- backend like scrollbars
- third party controls can use the system colors/icons/fonts/lengths
- special funding page on foundation site.
- HTML importer
- LCL form converter tools
- Frames
- methods to iterate elements, XPath
- methods to search and edit CSS
- stylesheets for windows, linux, macos: