rtk.Shadow
¶
A utility class that renders a general purpose shadow frame. Useful, for example, to render a shadow around an rtk-based popup menu.
This is meant more for internal widget implementations but you're free to use this directly.
Only the frame is rendered based on the elevation
, not the inner part, so it does
not affect the coloring of translucent surfaces drawn over top.
The shadow quality isn't all that it might be. Consider this a WIP that will see future refinement.
-- Create a red translucent shadow
local shadow = rtk.Shadow('red#44')
-- Create a crimson colored box that's 50% the window size
local spacer = window:add(rtk.Spacer{w=0.5, h=0.5, bg='crimson'})
-- When the widget reflows, regenerate the shadow
spacer.onreflow = function(self)
shadow:set_rectangle(self.calc.w, self.calc.h, 40)
end
-- And when the is drawn, also draw the spacer at the widget's
-- position.
spacer.ondraw = function(self, offx, offy, alpha)
shadow:draw(self.calc.x + offx, self.calc.y + offy, alpha)
end
type | shadowtypeconst | read-only |
The type of shadow based on whether |
color | colortype | read/write |
The color of the shadow (defaults to |
w | number or nil | read-only |
The width that was last passed to |
h | number or nil | read-only |
The height that was last passed to |
radius | number or nil | read-only |
The radius that was last passed to |
elevation | number or nil | read-only |
The computed elevation based on the last call to |
rtk.Shadow() | Create a new Shadow instance |
set_rectangle() | Sets a rectangular shadow |
set_circle() | Sets a circular shadow |
draw() | Draws the shadow on the current drawing target |
The type of shadow based on whether set_rectangle()
or set_circle()
was called.
The color of the shadow (defaults to #00000055
)
The width that was last passed to set_rectangle()
The height that was last passed to set_rectangle()
The radius that was last passed to set_circle
()`
The computed elevation based on the last call to set_rectangle()
or set_circle
()`
Create a new Shadow instance
Sets a rectangular shadow.
When this is called, the internal shadow image is re-rendered, so it should only be called when the dimensions actually change, or when you want to change elevation.
w | (number) | the width of the content box the shadow is wrapping, where the shadow starts around the edges and expands outward beyond the given width |
h | (number) | like w but for height |
elevation | (number or nil) | affects the apparent height of object the shadow intends to apply to, which roughly corresponds to the number of pixels the shadow expands out to. |
t | (number or nil) | number of pixels for the top edge, or uses elevation if nil |
r | (number or nil) | number of pixels for the right edge, or uses elevation if nil |
b | (number or nil) | number of pixels for the bottom edge, or uses elevation if nil |
l | (number or nil) | number of pixels for the left edge, or uses elevation if nil |
Sets a circular shadow.
When this is called, the internal shadow image is re-rendered, so it should only be called when the radius changes, or when you want to change elevation.
radius | (number) | the radius of the inner content area in pixels, which the shadow will wrap and expand outward from |
elevation | (number or nil) | affects the apparent height of object the shadow intends to apply to, which roughly corresponds to the number of pixels the shadow expands out to. If nil, the elevation defaults to 2/3 of the radius. |
Draws the shadow on the current drawing target.
x | (number) | the x coordinate of the inner content box that the shadow wraps |
y | (number) | the y coordinate of the inner content box that the shadow wraps |
alpha | (number or nil) | the opacity of the shadow, which applies a multiplier to the calculated shadow opacity derived from elevation (default 1.0) |