rtk.Popup
¶
An rtk.Viewport
that behaves as a modal pop-up which hijacks focus until the
popup is closed. Because popups are viewports, scrolling of the child widget is
supported.
Unlike other widgets, rtk.Popup
s don't need to be explicitly added to some
parent container. They are automatically inserted into the current rtk.Window
when opened and removed when closed.
Also, unlike the parent rtk.Viewport
class, rtk.Popup
widgets have a drop shadow by
default. Set shadow to false to explicitly disable.
The following examples assume an rtk.Window
has already been created and is (or is
about to be) open.
local button = some_container:add(rtk.Button{"Open Popup"})
local popup = rtk.Popup{
child=rtk.Text{'Hello world!'},
anchor=button,
}
button.onclick = function(b, event)
popup:open()
end
local box = rtk.VBox{spacing=20}
local popup = rtk.Popup{child=box, padding=30, overlay='#000000cc', autoclose=false}
local text = box:add(rtk.Text{'Some very important message goes here.'})
local button = box:add(rtk.Button{'Close'}, {halign='right'})
button.onclick = function(b, event)
popup:close()
end
popup:open()
Used with the autoclose
attribute to influence how the popup should be closed in
response to events that occur outside the popup area.
rtk.Popup.AUTOCLOSE_DISABLED¶ | 'disabled' |
Autoclose is disabled. If the mouse is clicked outside the popup, it will not
be automatically closed. To close it you must explicitly call |
rtk.Popup.AUTOCLOSE_LOCAL¶ | 'local' |
Autoclose when the mouse is clicked outside the popup but still within the
bounds of the |
rtk.Popup.AUTOCLOSE_GLOBAL¶ | 'global' |
Autoclose when the mouse is clicked anywhere on the screen outside the popup,
which includes when the mouse is clicked outside the |
anchor | rtk.Widget or nil | read/write |
A widget against which to anchor the popup (default nil) |
margin | number | read/write |
When |
width_from_anchor | boolean | read/write |
When |
overlay | colortype or nil | read/write |
If set, paints an overlay over top of the window in the given color before drawing
the popup, which uses the theme's |
autoclose | autocloseconst | read/write |
Allows automatically closing the popup if the mouse is clicked outside the popup
bounds or when the |
opened | boolean | read-only |
True when the popup is |
open() | Opens the modal popup |
close() | Closes the popup |
A widget against which to anchor the popup (default nil). The popup will be placed
below the widget if there is sufficient room, otherwise will be placed above it,
depending on which side has more space. When shadow is
defined (as it is by default the rtk.Popup
s, the portion of the shadow against
the anchor widget will be significantly reduced so that the anchor isn't
obstructed.
When anchor
is set, the height will be constrained so that the popup is this many
pixels from the edge of the screen (default 20). When anchor
is not set, this
behaves like standard widget margin.
When anchor
is set, the width of the popup will be matched to the width of the
anchor (default true). This also has the effect of dropping the border of the
edge of the popup against the anchor.
If set, paints an overlay over top of the window in the given color before drawing
the popup, which uses the theme's popup_overlay
by default. The alpha channel of this color is respected, so if you want a
translucent overlay specify a lower alpha (e.g. #00000055
).
This option is useful for things like alert boxes and is a good visual cue that focus has been stolen by the popup.
This attribute is ignored if anchor
is defined, because otherwise the overlay would
be painted over the anchor widget.
Allows automatically closing the popup if the mouse is clicked outside the popup
bounds or when the rtk.Window
loses focus, depending on the setting (default
local).
True when the popup is open
. Calling close()
will set to false.
Opens the modal popup.
By default, the popup will be centered within the rtk.Window
unless
anchor
is defined, in which case the popup will be anchored to that
widget. Without an anchor
, to override the default positioning of
the popup, attrs
can be specified.
-- Open with default placement
popup:open()
-- Opens the popup centered horizontally while 30px from the top of the window
popup:open{valign='top', halign='center', tpadding=30}
attrs | (table or nil) | the cell attributes to use when the popup is added to the |
(rtk.Popup) | returns self for method chaining |
Closes the popup.
See also handlers for rtk.Widget.
onopen() | Called just before the popup is opened |
onclose() | Called just before the popup is closed |
Called just before the popup is opened.
This event handler has the opportunity block the popup from opening by returning false.
(bool) | Returning false will block the popup from opening, while any other return value will allow it to be opened. |
Called just before the popup is closed.
The event argument indicates the type of event that is causing the
popup to close, if any. This could be rtk.Event.MOUSEDOWN
because
the user clicked outside the popup and autoclose
was true, or it
could be rtk.Event.WINDOWCLOSE
because the main window is closing.
Except in the latter case, this event handler may block closure of the
popup by returning false. In the case of rtk.Event.WINDOWCLOSE
, this
can't be aborted and the return value is ignored.
event | (rtk.Event or nil) | the event, if any, that is causing the popup to close. It is nil when the popup is programmatically closed. |
(bool) | Returning false will block the popup from closing, while any other return value will allow its closure. |