Package com.avrix.ui.widgets
Class Widget
java.lang.Object
com.avrix.ui.widgets.Widget
- Direct Known Subclasses:
BoxLayoutWidget
,CheckboxWidget
,ColorPickerWidget
,LabelWidget
,ModalWidget
,PanelWidget
,RadioButtonWidget
,SliderWidget
Abstract base class for all UI
Widget
's. This class provides the basic interface and functionality
for UI elements that can be rendered and interacted with.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a child widget to this widget's list of children.void
Adds thisWidget
to the screen by registering it with theWidgetManager
.void
Moves thisWidget
to the front of the rendering order, ensuring it is drawn above other widgets.void
drawArc
(int x, int y, float radius, float thickness, float startAngle, float endAngle, NanoColor color) Draws an arc segment with the specified center, radius, start angle, end angle, and thickness.void
Draws an arc segment with the specified center, radius, start angle, and end angle.void
drawCircle
(int x, int y, float radius, NanoColor color) Draws a circle at the specified position with the given radius and color.void
drawEllipse
(int x, int y, int width, int height, NanoColor color) Draws an ellipse at the specified position with the given size and color.void
drawImage
(int imageId, int x, int y, int width, int height, float opacity) Draws an image at the specified position with the given size.void
Draws a line from (x1, y1) to (x2, y2) with the specified color and thickness.void
Draws a filled rectangle with the specified position, size, and color.void
drawRectOutline
(int x, int y, int width, int height, float lineWidth, NanoColor color) Draws a rectangle with a stroke and no fillvoid
drawRoundedRect
(int x, int y, int width, int height, float radius, NanoColor color) Draws a filled rectangle with rounded corners with the specified position, size, radius, and color.void
drawRoundedRectOutline
(int x, int y, int width, int height, int radius, float lineWidth, NanoColor color) Draws a rectangle with rounded corners and a stroke without fill.void
Draws text on the screen using NanoVG.Returns the absolute (root) parent of thisWidget
.Gets an unmodifiable view of the list of child widgets.int
Returns the height of theWidget
.int
Gets the maximum horizontal scroll offset of the widget.int
Gets the maximum vertical scroll offset of the widget.int
Gets the speed at which the widget scrolls in response to mouse wheel movements.int
Gets the current horizontal scroll offset of the widget.int
Gets the current vertical scroll offset of the widget.int
getWidth()
Returns the width of theWidget
.int
getX()
Returns the relative x-coordinate of the top-left corner of theWidget
.int
getXA()
Returns the absolute x-coordinate of the top-left corner of theWidget
.int
getY()
Returns the relative y-coordinate of the top-left corner of theWidget
.int
getYA()
Returns the absolute y-coordinate of the top-left corner of theWidget
.void
intersectScissor
(int x, int y, int width, int height) Intersects current scissor rectangle with the specified rectangle.boolean
Checks if the window is set to always be on top of other windows.boolean
Checks if the mouse pointer is currently over thisWidget
.boolean
isPointOver
(int x, int y) Checks if a point with coordinates (x, y) is within the bounds of theWidget
.boolean
Returns whether theWidget
is scrollable.boolean
Checks if scrolling is currently locked for thisWidget
.boolean
Returns the current visibility of theWidget
.boolean
boolean
Checks if theWidget
is at least partially within the visible bounds of the window.void
Initializes theWidget
void
onKeyPress
(int key) Called when a key is pressed while theWidget
has focus.void
onKeyRelease
(int key) Called when a key is released while theWidget
has focus.void
onKeyRepeat
(int key) Called when a key is held down and repeatedly pressed while theWidget
has focus.void
onLeftMouseDown
(int x, int y) Called when the left mouse button is pressed down over theWidget
.void
onLeftMouseDownOutside
(int x, int y) Handles the left mouse button down event outside any visible widgetvoid
onLeftMouseUp
(int x, int y) Called when the left mouse button is released over theWidget
.void
onLeftMouseUpOutside
(int x, int y) Handles the left mouse button up event outside any visible widgetvoid
onMouseEnter
(int x, int y) Called when the mouse cursor enters the bounds of thisWidget
.void
onMouseExit
(int x, int y) Called when the mouse cursor exits the bounds of thisWidget
.void
onMouseMove
(int x, int y) Called when the mouse is moved over theWidget
.void
onMouseMoveOutside
(int x, int y) Handles the mouse move event outside any visible widgetvoid
onMouseWheel
(int x, int y, int delta) Called when the mouse wheel is scrolled over theWidget
.void
onRightMouseDown
(int x, int y) Called when the right mouse button is pressed down over theWidget
.void
onRightMouseDownOutside
(int x, int y) Handles the right mouse button down event outside any visible widgetvoid
onRightMouseUp
(int x, int y) Called when the right mouse button is released over theWidget
.void
onRightMouseUpOutside
(int x, int y) Handles the right mouse button up event outside any visible widgetvoid
Final rendering, after the main render and rendering of child elementsvoid
Widget pre-rendering (before main rendering and updating)void
removeChild
(Widget widget) Removes a child widget from this widget's list of children.void
Removes thisWidget
from the screen by unregistering it from theWidgetManager
.abstract void
render()
Renders theWidget
void
Updates and renders all child widgets of thisWidget
.void
setAlwaysOnTop
(boolean alwaysOnTop) Sets whether the window should always be on top of other windows.void
setHeight
(int height) Sets the height of theWidget
.void
setMaxScrollX
(int maxScrollX) Sets the maximum horizontal scroll offset of the widget.void
setMaxScrollY
(int maxScrollY) Sets the maximum vertical scroll offset of the widget.void
setScrollable
(boolean scrollable) Sets the scrollable property of theWidget
.void
setScrollLock
(boolean scrollLock) Sets the scrolling lock state for thisWidget
.void
setScrollSpeed
(int scrollSpeed) Sets the speed at which the widget scrolls in response to mouse wheel movements.void
setScrollX
(int scrollX) Sets the current horizontal scroll offset of the widget.void
setScrollY
(int scrollY) Sets the current vertical scroll offset of the widget.void
setVisible
(boolean visible) Sets the visibility of theWidget
.void
setWidth
(int width) Sets the width of theWidget
.void
setX
(int x) Sets the relative x-coordinate of the top-left corner of theWidget
.void
setXA
(int x) Sets the absolute x-coordinate of the top-left corner of theWidget
.void
setY
(int y) Sets the relative y-coordinate of the top-left corner of theWidget
.void
setYA
(int y) Sets the absolute y-coordinate of the top-left corner of theWidget
.void
update()
Updates theWidget
-
Field Details
-
hovered
public boolean hoveredIndicates whether theWidget
is currently hovered by the mouse cursor.
-
-
Constructor Details
-
Method Details
-
isScrollable
public boolean isScrollable()Returns whether theWidget
is scrollable.- Returns:
true
if theWidget
is scrollable,false
otherwise.
-
setScrollable
public void setScrollable(boolean scrollable) Sets the scrollable property of theWidget
.- Parameters:
scrollable
- the new scrollable value to set
-
isScrollLock
public boolean isScrollLock()Checks if scrolling is currently locked for thisWidget
.- Returns:
true
if scrolling is locked,false
otherwise.
-
setScrollLock
public void setScrollLock(boolean scrollLock) Sets the scrolling lock state for thisWidget
.- Parameters:
scrollLock
-true
to lock scrolling,false
to unlock it.
-
getParent
-
getAbsoluteParent
-
getScrollX
public int getScrollX()Gets the current horizontal scroll offset of the widget.- Returns:
- the current horizontal scroll offset
-
setScrollX
public void setScrollX(int scrollX) Sets the current horizontal scroll offset of the widget.- Parameters:
scrollX
- the new horizontal scroll offset
-
getMaxScrollX
public int getMaxScrollX()Gets the maximum horizontal scroll offset of the widget. This value represents the farthest point that the content can be scrolled horizontally.- Returns:
- the maximum horizontal scroll offset
-
setMaxScrollX
public void setMaxScrollX(int maxScrollX) Sets the maximum horizontal scroll offset of the widget. This value determines the limit for horizontal scrolling based on the content width.- Parameters:
maxScrollX
- the new maximum horizontal scroll offset
-
getScrollY
public int getScrollY()Gets the current vertical scroll offset of the widget.- Returns:
- the current vertical scroll offset
-
setScrollY
public void setScrollY(int scrollY) Sets the current vertical scroll offset of the widget.- Parameters:
scrollY
- the new vertical scroll offset
-
getMaxScrollY
public int getMaxScrollY()Gets the maximum vertical scroll offset of the widget. This value represents the farthest point that the content can be scrolled vertically.- Returns:
- the maximum vertical scroll offset
-
setMaxScrollY
public void setMaxScrollY(int maxScrollY) Sets the maximum vertical scroll offset of the widget. This value determines the limit for vertical scrolling based on the content height.- Parameters:
maxScrollY
- the new maximum vertical scroll offset
-
getScrollSpeed
public int getScrollSpeed()Gets the speed at which the widget scrolls in response to mouse wheel movements. This value determines how many pixels the scroll offset changes per wheel tick.- Returns:
- the scroll speed
-
setScrollSpeed
public void setScrollSpeed(int scrollSpeed) Sets the speed at which the widget scrolls in response to mouse wheel movements. This value determines how many pixels the scroll offset changes per wheel tick.- Parameters:
scrollSpeed
- the new scroll speed
-
renderChildren
public void renderChildren()Updates and renders all child widgets of thisWidget
. This method recursively calls the update and render methods on each child widget, ensuring that the rendering order respects the hierarchy of widgets. -
addChild
Adds a child widget to this widget's list of children.- Parameters:
widget
- the widget to add as a child
-
removeChild
Removes a child widget from this widget's list of children.- Parameters:
widget
- the widget to remove from the list of children
-
getChildren
Gets an unmodifiable view of the list of child widgets.- Returns:
- an unmodifiable list of child widgets
-
onInitialize
public void onInitialize()Initializes theWidget
-
onMouseMove
public void onMouseMove(int x, int y) Called when the mouse is moved over theWidget
.- Parameters:
x
- relative x-coordinate of mouse positiony
- relative y-coordinate of the mouse position
-
onLeftMouseDown
public void onLeftMouseDown(int x, int y) Called when the left mouse button is pressed down over theWidget
.- Parameters:
x
- relative x-coordinate of the mouse positiony
- relative y-coordinate of the mouse position
-
onLeftMouseUp
public void onLeftMouseUp(int x, int y) Called when the left mouse button is released over theWidget
.- Parameters:
x
- relative x-coordinate of the mouse positiony
- relative y-coordinate of the mouse position
-
onRightMouseDown
public void onRightMouseDown(int x, int y) Called when the right mouse button is pressed down over theWidget
.- Parameters:
x
- relative x-coordinate of the mouse positiony
- relative y-coordinate of the mouse position
-
onRightMouseUp
public void onRightMouseUp(int x, int y) Called when the right mouse button is released over theWidget
.- Parameters:
x
- relative x-coordinate of the mouse positiony
- relative y-coordinate of the mouse position
-
onMouseWheel
public void onMouseWheel(int x, int y, int delta) Called when the mouse wheel is scrolled over theWidget
.- Parameters:
x
- relative x-coordinate of the mouse positiony
- relative y-coordinate of the mouse positiondelta
- direction of mouse wheel movement - (1 - up, -1 - down)
-
onMouseEnter
public void onMouseEnter(int x, int y) Called when the mouse cursor enters the bounds of thisWidget
.- Parameters:
x
- absolute x-coordinate of the mouse positiony
- absolute y-coordinate of the mouse position
-
onMouseExit
public void onMouseExit(int x, int y) Called when the mouse cursor exits the bounds of thisWidget
.- Parameters:
x
- absolute x-coordinate of the mouse positiony
- absolute y-coordinate of the mouse position
-
onMouseMoveOutside
public void onMouseMoveOutside(int x, int y) Handles the mouse move event outside any visible widget- Parameters:
x
- absolute x-coordinate of the mouse positiony
- absolute y-coordinate of the mouse position
-
onLeftMouseDownOutside
public void onLeftMouseDownOutside(int x, int y) Handles the left mouse button down event outside any visible widget- Parameters:
x
- absolute x-coordinate of the mouse positiony
- absolute y-coordinate of the mouse position
-
onLeftMouseUpOutside
public void onLeftMouseUpOutside(int x, int y) Handles the left mouse button up event outside any visible widget- Parameters:
x
- absolute x-coordinate of the mouse positiony
- absolute y-coordinate of the mouse position
-
onRightMouseDownOutside
public void onRightMouseDownOutside(int x, int y) Handles the right mouse button down event outside any visible widget- Parameters:
x
- absolute x-coordinate of the mouse positiony
- absolute y-coordinate of the mouse position
-
onRightMouseUpOutside
public void onRightMouseUpOutside(int x, int y) Handles the right mouse button up event outside any visible widget- Parameters:
x
- absolute x-coordinate of the mouse positiony
- absolute y-coordinate of the mouse position
-
onKeyPress
public void onKeyPress(int key) Called when a key is pressed while theWidget
has focus.- Parameters:
key
- the code of the key that was pressed
-
onKeyRelease
public void onKeyRelease(int key) Called when a key is released while theWidget
has focus.- Parameters:
key
- the code of the key that was released
-
onKeyRepeat
public void onKeyRepeat(int key) Called when a key is held down and repeatedly pressed while theWidget
has focus.- Parameters:
key
- the code of the key that is being repeatedly pressed
-
setAlwaysOnTop
public void setAlwaysOnTop(boolean alwaysOnTop) Sets whether the window should always be on top of other windows.- Parameters:
alwaysOnTop
-true
if the window should always be on top; otherwisefalse
-
isAlwaysOnTop
public boolean isAlwaysOnTop()Checks if the window is set to always be on top of other windows.- Returns:
true
if the window is always on top; otherwisefalse
-
bringToTop
public void bringToTop()Moves thisWidget
to the front of the rendering order, ensuring it is drawn above other widgets. -
isPointOver
public boolean isPointOver(int x, int y) Checks if a point with coordinates (x, y) is within the bounds of theWidget
.- Parameters:
x
- the x-coordinate of the point to checky
- the y-coordinate of the point to check- Returns:
true
if the point is within the bounds of theWidget
, otherwisefalse
-
isHovered
public boolean isHovered()Checks if the mouse pointer is currently over thisWidget
.- Returns:
true
if the mouse pointer is over the widget, otherwisefalse
-
setVisible
public void setVisible(boolean visible) Sets the visibility of theWidget
.- Parameters:
visible
-true
if the element should be visible, otherwisefalse
-
isVisible
public boolean isVisible()Returns the current visibility of theWidget
.- Returns:
true
if the element is visible, otherwisefalse
-
isVisibleWithinParent
public boolean isVisibleWithinParent()Checks if thisWidget
is at least partially visible within the boundaries of its absolute parentWidget
. If theWidget
has no absolute parent (i.e., it is the root widget), it is considered fully visible by default.- Returns:
true
if any part of the widget is within the visible bounds of its absolute parent,false
otherwise.
-
isVisibleWithinWindow
public boolean isVisibleWithinWindow()Checks if theWidget
is at least partially within the visible bounds of the window.- Returns:
true
if any part of theWidget
is within the window bounds,false
otherwise.
-
getX
public int getX()Returns the relative x-coordinate of the top-left corner of theWidget
.- Returns:
- the relative x-coordinate of the top-left corner of the
Widget
(if not a child, coincides with absolute coordinates)
-
getY
public int getY()Returns the relative y-coordinate of the top-left corner of theWidget
.- Returns:
- the relative y-coordinate of the top-left corner of the
Widget
(if not a child, coincides with absolute coordinates)
-
getXA
public int getXA()Returns the absolute x-coordinate of the top-left corner of theWidget
.- Returns:
- the absolute x-coordinate of the top-left corner of the
Widget
-
getYA
public int getYA()Returns the absolute y-coordinate of the top-left corner of theWidget
.- Returns:
- the absolute y-coordinate of the top-left corner of the
Widget
-
getWidth
public int getWidth()Returns the width of theWidget
.- Returns:
- the width of the
Widget
-
getHeight
public int getHeight()Returns the height of theWidget
.- Returns:
- the height of the
Widget
-
setX
public void setX(int x) Sets the relative x-coordinate of the top-left corner of theWidget
.- Parameters:
x
- the new relative x-coordinate of the top-left corner of theWidget
-
setY
public void setY(int y) Sets the relative y-coordinate of the top-left corner of theWidget
.- Parameters:
y
- the new relative y-coordinate of the top-left corner of theWidget
-
setXA
public void setXA(int x) Sets the absolute x-coordinate of the top-left corner of theWidget
.- Parameters:
x
- the new absolute x-coordinate of the top-left corner of theWidget
-
setYA
public void setYA(int y) Sets the absolute y-coordinate of the top-left corner of theWidget
.- Parameters:
y
- the new absolute y-coordinate of the top-left corner of theWidget
-
setWidth
public void setWidth(int width) Sets the width of theWidget
.- Parameters:
width
- the new width of theWidget
-
setHeight
public void setHeight(int height) Sets the height of theWidget
.- Parameters:
height
- the new height of theWidget
-
addToScreen
public void addToScreen()Adds thisWidget
to the screen by registering it with theWidgetManager
. TheWidget
will be managed and rendered as part of the UI. -
removeFromScreen
public void removeFromScreen()Removes thisWidget
from the screen by unregistering it from theWidgetManager
. TheWidget
will no longer be managed or rendered as part of the UI. -
drawRectOutline
Draws a rectangle with a stroke and no fill- Parameters:
x
- relative X coordinate of the top left corner of the rectangley
- relative Y coordinate of the top left corner of the rectanglewidth
- the width of the rectangleheight
- height of the rectanglelineWidth
- the width of the stroke line in pixelscolor
- the color of the outline
-
drawRoundedRectOutline
public void drawRoundedRectOutline(int x, int y, int width, int height, int radius, float lineWidth, NanoColor color) Draws a rectangle with rounded corners and a stroke without fill.- Parameters:
x
- relative X coordinate of the top left corner of the rectangley
- relative Y coordinate of the top left corner of the rectanglewidth
- the width of the rectangleheight
- height of the rectangleradius
- corner radiuslineWidth
- the width of the stroke line in pixelscolor
- the color of the outline
-
drawRect
Draws a filled rectangle with the specified position, size, and color.- Parameters:
x
- relative x-coordinate of the top-left corner of the rectangley
- relative y-coordinate of the top-left corner of the rectanglewidth
- the width of the rectangleheight
- the height of the rectanglecolor
- the color to fill the rectangle with
-
drawText
Draws text on the screen using NanoVG.- Parameters:
text
- the text to be drawnfontName
- the name of the font to be usedx
- relative x-coordinate of the text's positiony
- relative y-coordinate of the text's positionfontSize
- the size of the fontcolor
- the color of the text
-
drawRoundedRect
Draws a filled rectangle with rounded corners with the specified position, size, radius, and color.- Parameters:
x
- relative x-coordinate of the top-left corner of the rectangley
- relative y-coordinate of the top-left corner of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangleradius
- the radius of the cornerscolor
- the color to fill the rectangle with
-
drawEllipse
Draws an ellipse at the specified position with the given size and color.- Parameters:
x
- relative x-coordinate of the ellipse's centery
- relative y-coordinate of the ellipse's centerwidth
- the width of the ellipseheight
- the height of the ellipsecolor
- the color of the ellipse
-
drawLine
Draws a line from (x1, y1) to (x2, y2) with the specified color and thickness.- Parameters:
x1
- relative x-coordinate of the start point of the liney1
- relative y-coordinate of the start point of the linex2
- relative x-coordinate of the end point of the liney2
- relative y-coordinate of the end point of the linewidth
- the thickness of the linecolor
- the color of the line
-
drawCircle
Draws a circle at the specified position with the given radius and color.- Parameters:
x
- relative x-coordinate of the circle's centery
- relative y-coordinate of the circle's centerradius
- the radius of the circlecolor
- the color of the circle
-
drawArc
Draws an arc segment with the specified center, radius, start angle, and end angle.- Parameters:
x
- relative x-coordinate of the center of the arcy
- relative y-coordinate of the center of the arcradius
- the radius of the arcstartAngle
- the starting angle of the arc (in radians)endAngle
- the ending angle of the arc (in radians)color
- the color of the arc segment
-
drawArc
public void drawArc(int x, int y, float radius, float thickness, float startAngle, float endAngle, NanoColor color) Draws an arc segment with the specified center, radius, start angle, end angle, and thickness.- Parameters:
x
- relative x-coordinate of the center of the arcy
- relative y-coordinate of the center of the arcradius
- the radius of the arcstartAngle
- the starting angle of the arc (in radians)endAngle
- the ending angle of the arc (in radians)thickness
- the thickness of the arc segmentcolor
- the color of the arc segment
-
drawImage
public void drawImage(int imageId, int x, int y, int width, int height, float opacity) Draws an image at the specified position with the given size.- Parameters:
imageId
- the identifier of the image to drawx
- relative x-coordinate of the image's positiony
- relative y-coordinate of the image's positionwidth
- the width of the imageheight
- the height of the imageopacity
- image opacity (from 0 to 1)
-
intersectScissor
public void intersectScissor(int x, int y, int width, int height) Intersects current scissor rectangle with the specified rectangle. The scissor rectangle is transformed by the current transform.Saves the current render state before starting.
- Parameters:
x
- relative x-coordinate of the intersecting scissor region.y
- relative y-coordinate of the intersecting scissor region.width
- the width of the intersecting scissor region.height
- the height of the intersecting scissor region.
-
preRender
public void preRender()Widget pre-rendering (before main rendering and updating) -
update
public void update()Updates theWidget
-
render
public abstract void render()Renders theWidget
-
postRender
public void postRender()Final rendering, after the main render and rendering of child elements
-