A BaseView
is a rectangle within the views View hierarchy. It is the base
class for ContainerView
, ScrollView
.
The base view for all different views.
Process: Main
BaseView
is an [EventEmitter][event-emitter].
options
Object (optional)vibrant
boolean (optional) - Enables the vibrant visual effect. Default isfalse
.blurred
boolean (optional) - Enables the blurred visual effect. Default isfalse
.
Creates the new base view.
Objects created with new BaseView
emit the following events:
Returns:
event
Eventtype
string - The type of the event. Possible values are:left-mouse-down
,right-mouse-down
,other-mouse-down
,left-mouse-up
,right-mouse-up
,other-mouse-up
,mouse-move
,mouse-enter
,mouse-leave
.timestamp
Integer - Time when event was created, starts from when machine was booted.button
Integer - The mouse button being pressed,1
is for left button,2
is for right button,3
is for middle button.positionInView
Point - Relative position inside the view where the event happened.positionInWindow
Point - Relative position inside the window.
Emitted when pressing mouse buttons. Calling event.preventDefault()
will prevent the view from receiving the mouse down event.
Returns:
event
Eventtype
string - The type of the event. Possible values are:left-mouse-down
,right-mouse-down
,other-mouse-down
,left-mouse-up
,right-mouse-up
,other-mouse-up
,mouse-move
,mouse-enter
,mouse-leave
.timestamp
Integer - Time when event was created, starts from when machine was booted.button
Integer - The mouse button being pressed,1
is for left button,2
is for right button,3
is for middle button.positionInView
Point - Relative position inside the view where the event happened.positionInWindow
Point - Relative position inside the window.
Emitted when releasing mouse buttons. Calling event.preventDefault()
will prevent the view from receiving the mouse down event.
Returns:
event
Eventtype
string - The type of the event. Possible values are:left-mouse-down
,right-mouse-down
,other-mouse-down
,left-mouse-up
,right-mouse-up
,other-mouse-up
,mouse-move
,mouse-enter
,mouse-leave
.timestamp
Integer - Time when event was created, starts from when machine was booted.button
Integer - The mouse button being pressed,1
is for left button,2
is for right button,3
is for middle button.positionInView
Point - Relative position inside the view where the event happened.positionInWindow
Point - Relative position inside the window.
Emitted when user moves mouse in the view.
Returns:
event
Eventtype
string - The type of the event. Possible values are:left-mouse-down
,right-mouse-down
,other-mouse-down
,left-mouse-up
,right-mouse-up
,other-mouse-up
,mouse-move
,mouse-enter
,mouse-leave
.timestamp
Integer - Time when event was created, starts from when machine was booted.button
Integer - The mouse button being pressed,1
is for left button,2
is for right button,3
is for middle button.positionInView
Point - Relative position inside the view where the event happened.positionInWindow
Point - Relative position inside the window.
Emitted when mouse enters the view.
Returns:
event
Eventtype
string - The type of the event. Possible values are:left-mouse-down
,right-mouse-down
,other-mouse-down
,left-mouse-up
,right-mouse-up
,other-mouse-up
,mouse-move
,mouse-enter
,mouse-leave
.timestamp
Integer - Time when event was created, starts from when machine was booted.button
Integer - The mouse button being pressed,1
is for left button,2
is for right button,3
is for middle button.positionInView
Point - Relative position inside the view where the event happened.positionInWindow
Point - Relative position inside the window.
Emitted when mouse leaves the view.
Returns:
event
Event
Emitted when the mouse capture on view has been released.
Returns:
event
EventoldSize
Size - Size the view was before.newSize
Size - Size the view is being resized to.
Emitted when the view's size has been changed.
The BaseView
class has the following static methods:
Returns BaseView[]
- An array of all created views.
id
Integer
Returns BaseView | null
- The view with the given id
.
Objects created with new BaseView
have the following properties:
A Integer
property representing the unique ID of the view. Each ID is unique among all BaseView
instances of the entire Electron application.
A boolean
property that determines whether this view is (or inherits from) ContainerView
.
A Integer
representing z-index to set. Has no effect until parent's view.rearrangeChildViews()
is called.
A Boolean
representing whether this BaseView receives any mouse input. Any BaseView
with clickThrough = true
will still display but won't receive any mouse events.
Objects created with new BaseView
have the following instance methods:
bounds
Rectangle - The target position and size of the view, relative to its parent.options
Object (optional)fromBounds
Rectangle (optional) - The initial position and size of the view, relative to its parent.duration
Float (optional) - A duration of the animation (in seconds). Default is 1.0.timingFunction
string (optional) - One of the following values:linear
,easeIn
,easeOut
,easeInEaseOut
,default
. Default islinear
.timingControlPoints
Object (optional)x1
Float (optional) - A floating point number representing the x position of the c1 control point.y1
Float (optional) - A floating point number representing the y position of the c1 control point.x2
Float (optional) - A floating point number representing the x position of the c2 control point.y2
Float (optional) - A floating point number representing the y position of the c2 control point.
Resizes and moves the view to the supplied bounds relative to its parent.
In case one of the values : duration
, timingFunction
, timingControlPoints
is specified, the resizing / moving is animated.
It's possible to specify a function that defines the pacing of an animation as a timing curve.
The function maps an input time normalized to the range [0,1] to an output time also in the range [0,1].
You can specify a media timing function by supplying your own cubic Bézier curve control points using the timingControlPoints
options or by using one of the predefined timing functions.
You can configure the timing function with the predefined timing function specified by name:
linear
- Linear pacing, which causes an animation to occur evenly over its durationeaseIn
- Ease-in pacing, which causes an animation to begin slowly and then speed up as it progresseseaseOut
- Ease-out pacing, which causes an animation to begin quickly and then slow as it progresseseaseInEaseOut
- Ease-in-ease-out pacing, which causes an animation to begin slowly, accelerate through the middle of its duration, and then slow again before completingdefault
- Similar to 3t^2 - 2t^3, one of the basic Hermite blending functions.
When you supply your own cubic Bézier curve control points, then the function is modeled as a cubic Bézier curve. The end points of the Bézier curve are automatically set to (0.0,0.0) and (1.0,1.0). The control points defining the Bézier curve are: [(0.0,0.0), (c1x,c1y), (c2x,c2y), (1.0,1.0)].
Returns Rectangle
Returns the position and size of the view, relative to its parent.
from
BaseView
Returns Point
- Offset from from
view.
Converts (0, 0)
point from the coordinate system of a given from
to that of the view.
both from
and the view must belong to the same BrowserWindow
.
Returns Point
- Offset the window that owns the view.
Converts (0, 0)
point from window base coordinates to that of the view.
visible
boolean - Whether this view is visible. Default istrue
.
Returns boolean
- Whether the view is visible.
Returns boolean
- Whether the view and its parent are visible.
Move the keyboard focus to the view.
Returns boolean
- Whether this view currently has the focus.
focusable
boolean - Whether this view can be focused on.
Returns boolean
- Returns true
if this view is focusable, enabled and drawn.
color
string - Color in#aarrggbb
or#argb
form. The alpha channel is optional.
Change the background color of the view.
material
string - Can beappearanceBased
,light
,dark
,titlebar
. Default isappearanceBased
.
Sets the material shown by the vibrant view.
appearanceBased
- The default material for the view’s effective appearance.light
- The material with a light effect. *dark
- The material with a dark effect. *titlebar
- The material for a window’s titlebar.
This function works when view
is created with vibrant
option.
Returns string
- The material shown by the vibrant view.
This function works when view
is created with vibrant
option.
mode
string - Can bebehindWindow
,withinWindow
. Default isbehindWindow
.
Sets whether the vibrant view blends with what's either behind or within the window.
behindWindow
- The mode that blends and blurs the vibrant view with the contents behind the window, such as the desktop or other windows.withinWindow
- The mode that blends and blurs the vibrant view with contents behind the view in the current window only.
This function works when view
is created with vibrant
option.
Returns string
- Whether the vibrant view blends with what's either behind or within the window.
This function works when view
is created with vibrant
option.
red
Float - The red component of the color .green
Float - The green component of the color .blue
Float - The blue component of the color .alpha
Float - The opacity value of the color .
Sets a color for blurred view from the specified components in the sRGB colorspace.
This function works when view
is created with blurred
option.
white
Float - The grayscale value of the color. Default is 1.0.alpha
Float - The opacity value of the color . Default is 0.7.
Sets a color for blurred view using the given opacity and grayscale values.
The layer will be tinted using the tint color. By default it is a 70% White Color.
This function works when view
is created with blurred
option.
white
Float - The grayscale value of the color. Default is 1.0.alpha
Float - The opacity value of the color . Default is 0.7.
Sets a color for blurred view with the specified white and alpha values in the GenericGamma22 colorspace.
This function works when view
is created with blurred
option.
radius
Float - The strength of the Gaussian Blur filter. Default is 20.
This function works when view
is created with blurred
option.
Returns Float
- The strength of the Gaussian Blur filter.
This function works when view
is created with blurred
option.
factor
Float - The saturation of the colors (To get more vibrant colors). Default is 2.0.
This function works when view
is created with blurred
option.
Returns Float
- The saturation factor.
This function works when view
is created with blurred
option.
Set mouse capture to the view.
Release mouse capture if the view has mouse capture.
Returns boolean
- Whether the view has mouse capture.
Enable mouse events.
enable
boolean - Whether the mouse tracking is enabled. Default isfalse
.
Returns boolean
- Whether the mouse tracking is enabled.
options
Objectradius
Number - Radius of each corner that is rounded.topLeft
Boolean (optional) - Iftrue
, top left corner will be rounded withradius
value.false
by default.topRight
Boolean (optional) - Iftrue
, top right corner will be rounded withradius
value.false
by default.bottomLeft
Boolean (optional) - Iftrue
, bottom left corner will be rounded withradius
value.false
by default.bottomRight
Boolean (optional) - Iftrue
, bottom right corner will be rounded withradius
value.false
by default.
options
Objectleft
Number (optional) - How many pixels to clip from the left side of the browser view.top
Number (optional) - How many pixels to clip from the top of the browser view.right
Number (optional) - How many pixels to clip from the right side of the browser view.bottom
Number (optional) - How many pixels to clip from the bottom side of the browser view.
Makes the scaling of the view equal to the window's base coordinate system.
options
ObjectscaleX
number (optional) - Specifies the x value for the new unit size.scaleY
number (optional) - Specifies the y value for the new unit size.adjustFrame
string (optional) - Adjusts the bounds (frame) to the scaled bounds.anchorX
string (optional) - The x coordinate of the anchor point when scaling. It can be one of the following values:left
,center
,right
. It can be also the number between 1 and 100 (specifying the percentage).anchorY
string (optional) - The y coordinate of the anchor point when scaling. It can be one of the following values:top
,center
,bottom
. It can be also the number between 1 and 100 (specifying the percentage).animation
Object (optional)duration
Float (optional) - A duration of the animation (in seconds). Default is 1.0.timingFunction
string (optional) - One of the following values:linear
,easeIn
,easeOut
,easeInEaseOut
,default
. Default islinear
.timingControlPoints
Object (optional)x1
Float (optional) - A floating point number representing the x position of the c1 control point.y1
Float (optional) - A floating point number representing the y position of the c1 control point.x2
Float (optional) - A floating point number representing the x position of the c2 control point.y2
Float (optional) - A floating point number representing the y position of the c2 control point.
Scales the view’s coordinate system so that the unit square scales to the specified dimensions.
In case when animation
is specified, the scaling and resizing / moving is animated.
The function does the simultaneous translation animation to keep the view's anchor during the zoom animation.
It's possible to specify a function that defines the pacing of an animation as a timing curve.
The function maps an input time normalized to the range [0,1] to an output time also in the range [0,1].
You can specify a media timing function by supplying your own cubic Bézier curve control points using the timingControlPoints
options or by using one of the predefined timing functions.
You can configure the timing function with the predefined timing function specified by name:
linear
- Linear pacing, which causes an animation to occur evenly over its durationeaseIn
- Ease-in pacing, which causes an animation to begin slowly and then speed up as it progresseseaseOut
- Ease-out pacing, which causes an animation to begin quickly and then slow as it progresseseaseInEaseOut
- Ease-in-ease-out pacing, which causes an animation to begin slowly, accelerate through the middle of its duration, and then slow again before completingdefault
- Similar to 3t^2 - 2t^3, one of the basic Hermite blending functions.
When you supply your own cubic Bézier curve control points, then the function is modeled as a cubic Bézier curve. The end points of the Bézier curve are automatically set to (0.0,0.0) and (1.0,1.0). The control points defining the Bézier curve are: [(0.0,0.0), (c1x,c1y), (c2x,c2y), (1.0,1.0)].
Returns the unit square scale of x dimension.
Returns the unit square scale of x dimension.
opacity
number - between 0.0 (fully transparent) and 1.0 (fully opaque)options
Object (optional)duration
Float (optional) - A duration of the animation (in seconds). Default is 1.0.timingFunction
string (optional) - One of the following values:linear
,easeIn
,easeOut
,easeInEaseOut
,default
. Default islinear
.timingControlPoints
Object (optional)x1
Float (optional) - A floating point number representing the x position of the c1 control point.y1
Float (optional) - A floating point number representing the y position of the c1 control point.x2
Float (optional) - A floating point number representing the x position of the c2 control point.y2
Float (optional) - A floating point number representing the y position of the c2 control point.
Sets the opacity of the view. Out of bound number values are clamped to the [0, 1] range.
In case one of the values : duration
, timingFunction
, timingControlPoints
is specified, the opacity change is animated.
Returns number
- between 0.0 (fully transparent) and 1.0 (fully opaque).
Returns BaseView || null
- The parent view, otherwise returns null
.
Returns BrowserWindow || null
- The window that the view belongs to, otherwise returns null
.
Note: The view can belongs to either a view or a window.