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.
| Property | Details |
|---|---|
| Library | ReflectionEffectLib |
| Prefix | reflection_ |
| Wraps | TReflectionEffect |
| Functions | 16 |
| Type | Visual effect (decorative) |
| Category | Count | Description |
|---|---|---|
| Creation / Destruction | 2 | Create and free effect |
| Length | 2 | Get/set reflection height |
| Opacity | 2 | Get/set reflection transparency |
| Offset | 2 | Get/set gap from control |
| Effect Control | 4 | Enabled and trigger get/set |
| Error Handling | 4 | Error 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
| Platform | Support |
|---|---|
| Windows | ✅ Full support |
| Linux | ✅ Full support |
| Android | ✅ Full support |
Creation & Destruction
reflection#(parent#)
Creates a new reflection effect attached to the specified visual control.
| Parameter | Type | Description |
|---|---|---|
parent# | Pointer | Target visual control |
| Returns | Pointer | Effect handle, or 0 on failure |
reflection_free(effect#)
Destroys the effect and releases associated resources.
Error Handling
| Function | Signature | Description |
|---|---|---|
reflection_error() | reflection_error@ | Returns last error code (0 = none) |
reflection_errormsg$() | reflection_errormsg$@ | Returns last error message |
reflection_strerror$(code) | reflection_strerror$@n | Converts 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.
| Function | Signature | Description |
|---|---|---|
reflection_length#(effect#, value) | reflection_length#@#n | Set reflection height (0–1) |
reflection_length(effect#) | reflection_length@# | Get reflection height |
| Value | Effect |
|---|---|
0.2–0.3 | Short, subtle reflection |
0.4–0.5 | Medium reflection (default range) |
0.6–0.8 | Tall reflection |
1.0 | Full mirror image |
Opacity
Controls the transparency of the reflection. Lower values create a more subtle, realistic effect.
| Function | Signature | Description |
|---|---|---|
reflection_opacity#(effect#, value) | reflection_opacity#@#n | Set 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.
| Function | Signature | Description |
|---|---|---|
reflection_offset#(effect#, pixels) | reflection_offset#@#n | Set gap (pixels) |
reflection_offset(effect#) | reflection_offset@# | Get gap |
Effect Control
| Function | Signature | Description |
|---|---|---|
reflection_enabled#(effect#, value) | reflection_enabled#@#n | Enable (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
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
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
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
| Practice | Why |
|---|---|
| Use opacity 0.2–0.4 for professional look | Too opaque looks unrealistic |
| Keep length at 0.3–0.5 | Realistic reflections fade before full length |
| Add small offset (2–4 px) | Creates visual separation from control |
| Works best on solid colored shapes | Complex controls may have uneven reflections |
| Leave space below the control | The reflection renders beneath the control's bounds |
Quick Reference
| Function | Signature | Description |
|---|---|---|
| CREATION & DESTRUCTION | ||
reflection#(parent#) | reflection#@# | Create effect |
reflection_free(effect#) | reflection_free@# | Destroy effect |
| LENGTH | ||
reflection_length#(effect#, value) | reflection_length#@#n | Set height (0–1) |
reflection_length(effect#) | reflection_length@# | Get height |
| OPACITY | ||
reflection_opacity#(effect#, value) | reflection_opacity#@#n | Set opacity (0–1) |
reflection_opacity(effect#) | reflection_opacity@# | Get opacity |
| OFFSET | ||
reflection_offset#(effect#, pixels) | reflection_offset#@#n | Set gap (pixels) |
reflection_offset(effect#) | reflection_offset@# | Get gap |
| EFFECT CONTROL | ||
reflection_enabled#(effect#, value) | reflection_enabled#@#n | Enable/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$@n | Code to text |
reflection_clearerror() | reflection_clearerror@ | Clear error state |
See Also
| Library | Description |
|---|---|
ShadowEffectLib | Drop shadow effects |
GlowEffectLib | Outer glow effects |
InnerGlowEffectLib | Inner glow effects |
