Overview

ReflectionEffectLib creates mirror-like reflections below visual controls, wrapping the FireMonkey TReflectionEffect component. The effect renders a fading, inverted copy of the control beneath it — similar to iOS-style glossy reflections or objects reflected on a polished surface.

PropertyDetails
LibraryReflectionEffectLib
Prefixreflection_
WrapsTReflectionEffect
Functions16
TypeVisual effect (decorative)
CategoryCountDescription
Creation / Destruction2Create and free effect
Length2Get/set reflection height
Opacity2Get/set reflection transparency
Offset2Get/set gap from control
Effect Control4Enabled and trigger get/set
Error Handling4Error codes and messages
🪄 Glossy Surfaces: This effect adds a polished, professional look to UI elements. Use subtle opacity (0.2–0.4) and moderate length (0.3–0.5) for the most realistic appearance.

Cross-Platform Support

PlatformSupport
Windows✅ Full support
Linux✅ Full support
Android✅ Full support

Creation & Destruction

reflection#(parent#)

Creates a new reflection effect attached to the specified visual control.

ParameterTypeDescription
parent#PointerTarget visual control
ReturnsPointerEffect handle, or 0 on failure

reflection_free(effect#)

Destroys the effect and releases associated resources.

Error Handling

FunctionSignatureDescription
reflection_error()reflection_error@Returns last error code (0 = none)
reflection_errormsg$()reflection_errormsg$@Returns last error message
reflection_strerror$(code)reflection_strerror$@nConverts error code to text
reflection_clearerror()reflection_clearerror@Clears the error state

Length

Controls how much of the control is reflected. A value of 1.0 reflects the entire control; 0.5 reflects only the bottom half.

FunctionSignatureDescription
reflection_length#(effect#, value)reflection_length#@#nSet reflection height (0–1)
reflection_length(effect#)reflection_length@#Get reflection height
ValueEffect
0.2–0.3Short, subtle reflection
0.4–0.5Medium reflection (default range)
0.6–0.8Tall reflection
1.0Full mirror image

Opacity

Controls the transparency of the reflection. Lower values create a more subtle, realistic effect.

FunctionSignatureDescription
reflection_opacity#(effect#, value)reflection_opacity#@#nSet opacity (0–1)
reflection_opacity(effect#)reflection_opacity@#Get opacity

Offset

Sets the gap in pixels between the control and its reflection, creating visual separation.

FunctionSignatureDescription
reflection_offset#(effect#, pixels)reflection_offset#@#nSet gap (pixels)
reflection_offset(effect#)reflection_offset@#Get gap

Effect Control

FunctionSignatureDescription
reflection_enabled#(effect#, value)reflection_enabled#@#nEnable (1) or disable (0)
reflection_enabled(effect#)reflection_enabled@#Gets enabled state
reflection_trigger#(effect#, trigger$)reflection_trigger#@#$Sets trigger string
reflection_trigger$(effect#)reflection_trigger$@#Gets trigger string

Complete Examples

Example 1: Basic Reflection

╯ basic-reflection.bas
let frm# = Pointer#(0)
let rect# = Pointer#(0)
let refl# = Pointer#(0)

frm# = form#("Reflection Demo", 400, 350)

rect# = rectangle#(frm#)
rectangle_bounds#(rect#, 100, 50, 200, 100)
rectangle_fill#(rect#, "SteelBlue")

refl# = reflection#(rect#)
reflection_length#(refl#, 0.5)
reflection_opacity#(refl#, 0.4)
reflection_offset#(refl#, 2)

form_show(frm#)

Example 2: Reflection Controls

╯ reflection-controls.bas
let frm# = Pointer#(0)
let rect# = Pointer#(0)
let refl# = Pointer#(0)
let lbl# = Pointer#(0)

frm# = form#("Reflection Controls", 450, 380)

rect# = rectangle#(frm#)
rectangle_bounds#(rect#, 125, 40, 200, 100)
rectangle_fill#(rect#, "Navy")

refl# = reflection#(rect#)
reflection_length#(refl#, 0.5)
reflection_opacity#(refl#, 0.5)

lbl# = label#(frm#, "Length: 50%  Opacity: 50%", 120, 220)

let btn1# = button#(frm#, "Len 25%")
button_bounds#(btn1#, 40, 260, 80, 30)
button_onclick#(btn1#, "SetLen25")

let btn2# = button#(frm#, "Len 50%")
button_bounds#(btn2#, 130, 260, 80, 30)
button_onclick#(btn2#, "SetLen50")

let btn3# = button#(frm#, "Len 75%")
button_bounds#(btn3#, 220, 260, 80, 30)
button_onclick#(btn3#, "SetLen75")

let btn4# = button#(frm#, "Toggle")
button_bounds#(btn4#, 310, 260, 80, 30)
button_onclick#(btn4#, "Toggle")

form_show(frm#)

function SetLen25(sender#)
  reflection_length#(refl#, 0.25)
  label_text#(lbl#, "Length: 25%")
endfunction

function SetLen50(sender#)
  reflection_length#(refl#, 0.50)
  label_text#(lbl#, "Length: 50%")
endfunction

function SetLen75(sender#)
  reflection_length#(refl#, 0.75)
  label_text#(lbl#, "Length: 75%")
endfunction

function Toggle(sender#)
  if reflection_enabled(refl#) = 1 then
    reflection_enabled#(refl#, 0)
    label_text#(lbl#, "Reflection: OFF")
  else
    reflection_enabled#(refl#, 1)
    label_text#(lbl#, "Reflection: ON")
  endif
endfunction

Example 3: Gallery with Reflections

╯ reflection-gallery.bas
let frm# = Pointer#(0)

frm# = form#("Reflection Gallery", 500, 350)

' Create 3 items with reflections
let rect1# = rectangle#(frm#)
rectangle_bounds#(rect1#, 50, 50, 120, 80)
rectangle_fill#(rect1#, "Red")
let refl1# = reflection#(rect1#)
reflection_length#(refl1#, 0.4)
reflection_opacity#(refl1#, 0.3)

let rect2# = rectangle#(frm#)
rectangle_bounds#(rect2#, 190, 50, 120, 80)
rectangle_fill#(rect2#, "Green")
let refl2# = reflection#(rect2#)
reflection_length#(refl2#, 0.4)
reflection_opacity#(refl2#, 0.3)

let rect3# = rectangle#(frm#)
rectangle_bounds#(rect3#, 330, 50, 120, 80)
rectangle_fill#(rect3#, "Blue")
let refl3# = reflection#(rect3#)
reflection_length#(refl3#, 0.4)
reflection_opacity#(refl3#, 0.3)

form_show(frm#)

Best Practices

PracticeWhy
Use opacity 0.2–0.4 for professional lookToo opaque looks unrealistic
Keep length at 0.3–0.5Realistic reflections fade before full length
Add small offset (2–4 px)Creates visual separation from control
Works best on solid colored shapesComplex controls may have uneven reflections
Leave space below the controlThe reflection renders beneath the control's bounds

Quick Reference

FunctionSignatureDescription
CREATION & DESTRUCTION
reflection#(parent#)reflection#@#Create effect
reflection_free(effect#)reflection_free@#Destroy effect
LENGTH
reflection_length#(effect#, value)reflection_length#@#nSet height (0–1)
reflection_length(effect#)reflection_length@#Get height
OPACITY
reflection_opacity#(effect#, value)reflection_opacity#@#nSet opacity (0–1)
reflection_opacity(effect#)reflection_opacity@#Get opacity
OFFSET
reflection_offset#(effect#, pixels)reflection_offset#@#nSet gap (pixels)
reflection_offset(effect#)reflection_offset@#Get gap
EFFECT CONTROL
reflection_enabled#(effect#, value)reflection_enabled#@#nEnable/disable
reflection_enabled(effect#)reflection_enabled@#Get enabled state
reflection_trigger#(effect#, trigger$)reflection_trigger#@#$Set trigger
reflection_trigger$(effect#)reflection_trigger$@#Get trigger
ERROR HANDLING
reflection_error()reflection_error@Last error code
reflection_errormsg$()reflection_errormsg$@Last error message
reflection_strerror$(code)reflection_strerror$@nCode to text
reflection_clearerror()reflection_clearerror@Clear error state

See Also

LibraryDescription
ShadowEffectLibDrop shadow effects
GlowEffectLibOuter glow effects
InnerGlowEffectLibInner glow effects