Repository navigation
tkTheme
Home › All Categories › tkControls › tkTheme
Keeps the shared light and dark theme every tkControls control takes its colours from.
A theme is one TKTHEME_COLORS struct of semantic roles (Window, Surface, Text, Accent, Selected, Popup, Border, Error and the rest), not a colour for each field of each control. Every control derives its own colours from the roles, so one theme switch restyles the whole program.
A theme is applied, not looked up at paint time. tkTheme_Apply( t ) makes t the process-wide current theme and sends TKM_THEMECHANGED to every widget on every surface; each control then copies the roles it uses into its own colours, unless the program pinned that control's colours. Main windows and dialogs take t.Window as their background. Applying a theme equal to the current one does nothing. Before any theme is applied, tkTheme_Get() is the Dark preset, which is what every control starts with.
In a tkApp program use tkApp_SetTheme or tkApp_SetThemeMode instead: they apply the theme and also fire the forms' OnThemeChanged, and TKAPP_THEME_SYSTEM follows the OS light/dark setting live.
#import "vendor/tkControls/tkTheme"
using tkThemeEvery control and tkApp import tkTheme publicly, so using tkTheme usually needs no #import of its own. It re-exports tkHost.
dim as TKTHEME_COLORS t = tkTheme_Dark()
t.Accent = tkRGB( 0, 120, 215 )
tkApp_SetTheme( t ) ' every unpinned control and every form repaints
dim as TKBUTTON_COLORS danger = tkButton_ThemeColors( t )
danger.BackColor = tkRGB( 196, 43, 28 )
tkButton_SetColors( hDelete, @danger ) ' pins this button: the theme leaves it alone
tkButton_UnpinColors( hDelete ) ' ...until it is handed backtkTheme_Dark() and tkTheme_Light() are the two presets. tkTheme_SystemIsDark() reads the OS preference through SDL (an unknown answer reads as light), and tkTheme_System() is the matching preset. tkTheme_Equal( a, b ) compares two themes.
Each control has, beside its own SetColors:
-
tk<X>_ThemeColors( t ): the control's colour set derived from the roles (controls with aTK<X>_COLORStype); -
tk<X>_ApplyTheme( h, t ): applies the theme unless the colours are pinned; -
tk<X>_UnpinColors( h ): hands the control back to the theme and applies it at once.
Any colour setter the program calls pins the control. Item-level colours (a chart series, a toolbar item's foreground) are data, never pinned and never themed. A widget of your own follows the theme by handling TKM_THEMECHANGED and reading tkTheme_Get().
| PsTheme | tkTheme |
|---|---|
PSTHEME_COLORS |
TKTHEME_COLORS (the same roles, the same preset values) |
PsTheme_Dark, Light, System, SystemIsDark, Equal
|
tkTheme_Dark, Light, System, SystemIsDark, Equal
|
Ps<X>_ThemeColors, ApplyTheme, UnpinColors
|
tk<X>_ThemeColors, ApplyTheme, UnpinColors
|
- Colours are
ulong&hAARRGGBB(tkRGB), notCOLORREF. - Added: the current theme itself,
tkTheme_GetandtkTheme_Apply, which works without tkApp. - Dropped:
PsTheme_ApplyTitleBarandApplyCaptionOf. SDL draws no caption, so the OS colours the title bar in its own theme.
The PsTheme page remains the behaviour reference for everything not listed here.
Every public name the module declares, as the source declares it. Signatures are exact; type bodies keep their field comments and drop the rest.
type TKTHEME_COLORS
IsDark as boolean
Window as ulong ' form background; controls that sit flat on it
Surface as ulong ' control face: buttons, fields, bars
SurfaceHot as ulong ' face under the mouse
SurfaceDisabled as ulong
Text as ulong
TextHot as ulong ' text under the mouse
TextStrong as ulong ' titles, pressed and emphasised text
TextDim as ulong ' secondary text: captions, labels, placeholders
TextDisabled as ulong
Accent as ulong ' checked / on / progress / today
AccentHot as ulong
FocusRing as ulong ' focus rings and focused borders
Border as ulong
BorderDisabled as ulong
Divider as ulong ' separators, grid lines, hairlines
Selected as ulong ' selection and pressed fill
SelectedText as ulong
Popup as ulong ' menus, dropdowns, tooltips
PopupText as ulong
Track as ulong ' the unfilled part of a track: toggle off, progress
Success as ulong
Warning as ulong
Error as ulong
end typefunction tkTheme_Dark( ) as TKTHEME_COLORS
function tkTheme_Light( ) as TKTHEME_COLORS
function tkTheme_SystemIsDark( ) as boolean
function tkTheme_System( ) as TKTHEME_COLORS
function tkTheme_Equal( byref a as TKTHEME_COLORS, byref b as TKTHEME_COLORS ) as boolean
function tkTheme_Get( ) as TKTHEME_COLORS
sub tkTheme_Apply( byref t as TKTHEME_COLORS )- tkControls
- tkApp, tkHost
- PsTheme, the PsControls module
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing