View
Base class for GUI components.
Module | require("yue.gui") |
Type | Class |
Inherits | Responder |
View
provides methods to receive and change various style properties.
Methods
offsetfromview(view)
Return offset from view
.
Parameters
View
view
Return
Vector2dF
offsetfromwindow()
Return offset from the window that owns the view.
Return
Vector2dF
getbounds()
Return the position and size of the view, relative to its parent.
Return
RectF
getboundsinscreen()
Return the position and size of the view in the screen.
Return
RectF
layout()
Make the view re-recalculate its layout.
schedulepaint()
Schedule to repaint the whole view.
schedulepaintrect(rect)
Schedule to repaint the rect
area in view.
Parameters
RectF
rect
setvisible(visible)
Show/Hide the view.
Parameters
boolean
visible
isvisible()
Return whether the view is visible.
Return
boolean
isvisibleinhierarchy()
Return whether the view and its ancestors are visible.
Return
boolean
setenabled(enable)
Set whether the view is enabled.
The enabled state of each view is not affected by its parent, disabling a container-like view does not have any effect.
Parameters
boolean
enable
isenabled()
Return whether the view is enabled.
Return
boolean
focus()
Move the keyboard focus to the view.
hasfocus()
Return whether the view has keyboard focus.
Return
boolean
setfocusable(focusable)
Set whether the view can be focused on.
Parameters
boolean
focusable
isfocusable()
Return whether the view can be focused on.
Return
boolean
setmousedowncanmovewindow(can)
Set whether dragging mouse would move the window.
For most platforms this method only works for frameless windows, having this feature may also prevent mouse events to happen.
On macOS the Container
view has this feature turned on by default. To
turn this feature on for the view, the view's parent view must also has
this feature turned on.
On Windows the view with this feature will be treated as titlebar, e.g. double-clicking would maximize the window, right-clicking may show the system menu.
Parameters
boolean
can
ismousedowncanmovewindow()
Return whether dragging the view would move the window.
Return
boolean
dodrag(data, operations)
Like DoDragWithOptions
but do not set drag image.
Parameters
table
datainteger
operations
Return
integer
dodragwithoptions(data, operations, options)
Start a drag session.
The return value is a DragOperation
indicating the result of
dragging.
This method should only be called in the on_mouse_down
event, when user
starts to drag the cursor.
This method is blocking that it does not return until the drag session is finished or cancelled. During the call a nested UI message loop will run and other events will still be emitted.
Note that on macOS certain views may have IsMouseDownCanMoveWindow
defaulting to true
, which will prevent drag session to start. Make sure
to call SetMouseDownCanMoveWindow(false)
for drag sources.
Parameters
table
data - An array ofClipboard::Data
that will be passed to drop target.integer
operations - Must be one or more ofDragOperation
masks, indicates which drag operations are supported.DragOptions
options
Return
integer
canceldrag()
Cancel current drag session if the view is being used as drag source.
isdragging()
Return whether the view is being used as drag source.
Return
boolean
registerdraggedtypes(types)
Make the view a drag destination that accepets types
.
Parameters
table
types - An array ofClipboard::Data::Type
.
setcursor(cursor)
Set the cursor to show when hovering the view.
On Linux, setting cursor would force the view to own its own GDK window.
For certain views like Label
, this may have remove the view's background
color.
Parameters
Cursor
cursor
settooltip(tooltip)
Set the tooltip
for the view.
This method will clear all tooltips added by addtooltipforrect
.
Parameters
string
tooltip
addtooltipforrect(tooltip, rect)
Add tooltip
for a defined rect
in the view and return an ID for it.
Parameters
string
tooltipRectF
rect
Return
integer
removetooltip(id)
Remove tooltip added by addtooltipforrect
with id
.
Parameters
integer
id
setfont(font)
Change the font used for drawing text in the view.
This methods only works for View
s that display text, like Label
or
Entry
.
Parameters
Font
font
setcolor(color)
Change the color used for drawing text in the view.
This methods only works for View
s that display text, like Label
or
Entry
.
Parameters
Color
color
setbackgroundcolor(color)
Change the background color of the view.
Parameters
Color
color
setstyle(styles)
Change the styles of the view.
Available style properties can be found at Layout System.
Parameters
table
styles - A key-value dictionary that defines the name and value of the style properties, key must be string, and value must be either string or number.
getcomputedlayout()
Return string representation of the view's layout.
Return
string
getminimumsize()
Return the minimum size needed to show the view.
Return
SizeF
getparent()
Return parent view.
Return
View
getwindow()
Return the window that the view belongs to.
Return
Window
Events
ondragleave(self, info)
Emitted when cursor leaves the view while dragging.
This event will also be emitted before the handle_drop
event when user
drops the data on the view.
Parameters
View
selfDraggingInfo
info
Preventable
No.onsizechanged(self)
Emitted when the view's size has been changed.
Parameters
View
self
Preventable
No.onfocusin(self)
Emitted when the view gets keyboard focus.
Parameters
View
self
Preventable
Yes.onfocusout(self)
Emitted when the view loses keyboard focus.
Parameters
View
self
Preventable
Yes.Delegates
handledragenter(self, info, point)
Called when user drags the cursor over the view for the first time.
A DragOperation
should be returned, indicating which dragging
operation the destination will perform when cursor is released.
This delegate will not be called if the view has not registered dragged types, or if the dragged data does not belong to the registered type.
On Linux the dragged data is not yet available when this is called, you
should usually only read data in the handle_drop
delegate.
Parameters
View
selfDraggingInfo
infoPointF
point
Return
integer
handledragupdate(self, info, point)
Called when user moves the cursor over the view while dragging.
A DragOperation
should be returned, indicating which dragging
operation the destination will perform when cursor is released.
If this delegate is not implemented, the return value of previous
handle_drag_enter
call will be returned.
This delegate is usually used when implementing a custom view with
multiple dropping areas, you only need to implement handle_drag_enter
for simple tasks.
On Linux the dragged data is not yet available when this is called, you
should usually only read data in the handle_drop
delegate.
Parameters
View
selfDraggingInfo
infoPointF
point
Return
integer
handledrop(self, info, point)
Called when user releases the dragged data on the view.
Returning true
will inform the drag source that the data has been
accepted with the drag operation returned by previous handle_drag_enter
or handle_drag_update
call.
If the drag operation is Move
, the drag source may also take actions
to "remove" the data on its side.
Returning false
will inform the drag source that the drag has been
cancelled, and operating system may display some visual effects.
Parameters
View
selfDraggingInfo
infoPointF
point
Return
boolean