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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a child widget to this widget's list of children.voidAdds thisWidgetto the screen by registering it with theWidgetManager.voidMoves thisWidgetto the front of the rendering order, ensuring it is drawn above other widgets.voiddrawArc(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.voidDraws an arc segment with the specified center, radius, start angle, and end angle.voiddrawCircle(int x, int y, float radius, NanoColor color) Draws a circle at the specified position with the given radius and color.voiddrawEllipse(int x, int y, int width, int height, NanoColor color) Draws an ellipse at the specified position with the given size and color.voiddrawImage(int imageId, int x, int y, int width, int height, float opacity) Draws an image at the specified position with the given size.voidDraws a line from (x1, y1) to (x2, y2) with the specified color and thickness.voidDraws a filled rectangle with the specified position, size, and color.voiddrawRectOutline(int x, int y, int width, int height, float lineWidth, NanoColor color) Draws a rectangle with a stroke and no fillvoiddrawRoundedRect(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.voiddrawRoundedRectOutline(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.voidDraws text on the screen using NanoVG.Returns the absolute (root) parent of thisWidget.Gets an unmodifiable view of the list of child widgets.intReturns the height of theWidget.intGets the maximum horizontal scroll offset of the widget.intGets the maximum vertical scroll offset of the widget.intGets the speed at which the widget scrolls in response to mouse wheel movements.intGets the current horizontal scroll offset of the widget.intGets the current vertical scroll offset of the widget.intgetWidth()Returns the width of theWidget.intgetX()Returns the relative x-coordinate of the top-left corner of theWidget.intgetXA()Returns the absolute x-coordinate of the top-left corner of theWidget.intgetY()Returns the relative y-coordinate of the top-left corner of theWidget.intgetYA()Returns the absolute y-coordinate of the top-left corner of theWidget.voidintersectScissor(int x, int y, int width, int height) Intersects current scissor rectangle with the specified rectangle.booleanChecks if the window is set to always be on top of other windows.booleanChecks if the mouse pointer is currently over thisWidget.booleanisPointOver(int x, int y) Checks if a point with coordinates (x, y) is within the bounds of theWidget.booleanReturns whether theWidgetis scrollable.booleanChecks if scrolling is currently locked for thisWidget.booleanReturns the current visibility of theWidget.booleanbooleanChecks if theWidgetis at least partially within the visible bounds of the window.voidInitializes theWidgetvoidonKeyPress(int key) Called when a key is pressed while theWidgethas focus.voidonKeyRelease(int key) Called when a key is released while theWidgethas focus.voidonKeyRepeat(int key) Called when a key is held down and repeatedly pressed while theWidgethas focus.voidonLeftMouseDown(int x, int y) Called when the left mouse button is pressed down over theWidget.voidonLeftMouseDownOutside(int x, int y) Handles the left mouse button down event outside any visible widgetvoidonLeftMouseUp(int x, int y) Called when the left mouse button is released over theWidget.voidonLeftMouseUpOutside(int x, int y) Handles the left mouse button up event outside any visible widgetvoidonMouseEnter(int x, int y) Called when the mouse cursor enters the bounds of thisWidget.voidonMouseExit(int x, int y) Called when the mouse cursor exits the bounds of thisWidget.voidonMouseMove(int x, int y) Called when the mouse is moved over theWidget.voidonMouseMoveOutside(int x, int y) Handles the mouse move event outside any visible widgetvoidonMouseWheel(int x, int y, int delta) Called when the mouse wheel is scrolled over theWidget.voidonRightMouseDown(int x, int y) Called when the right mouse button is pressed down over theWidget.voidonRightMouseDownOutside(int x, int y) Handles the right mouse button down event outside any visible widgetvoidonRightMouseUp(int x, int y) Called when the right mouse button is released over theWidget.voidonRightMouseUpOutside(int x, int y) Handles the right mouse button up event outside any visible widgetvoidFinal rendering, after the main render and rendering of child elementsvoidWidget pre-rendering (before main rendering and updating)voidremoveChild(Widget widget) Removes a child widget from this widget's list of children.voidRemoves thisWidgetfrom the screen by unregistering it from theWidgetManager.abstract voidrender()Renders theWidgetvoidUpdates and renders all child widgets of thisWidget.voidsetAlwaysOnTop(boolean alwaysOnTop) Sets whether the window should always be on top of other windows.voidsetHeight(int height) Sets the height of theWidget.voidsetMaxScrollX(int maxScrollX) Sets the maximum horizontal scroll offset of the widget.voidsetMaxScrollY(int maxScrollY) Sets the maximum vertical scroll offset of the widget.voidsetScrollable(boolean scrollable) Sets the scrollable property of theWidget.voidsetScrollLock(boolean scrollLock) Sets the scrolling lock state for thisWidget.voidsetScrollSpeed(int scrollSpeed) Sets the speed at which the widget scrolls in response to mouse wheel movements.voidsetScrollX(int scrollX) Sets the current horizontal scroll offset of the widget.voidsetScrollY(int scrollY) Sets the current vertical scroll offset of the widget.voidsetVisible(boolean visible) Sets the visibility of theWidget.voidsetWidth(int width) Sets the width of theWidget.voidsetX(int x) Sets the relative x-coordinate of the top-left corner of theWidget.voidsetXA(int x) Sets the absolute x-coordinate of the top-left corner of theWidget.voidsetY(int y) Sets the relative y-coordinate of the top-left corner of theWidget.voidsetYA(int y) Sets the absolute y-coordinate of the top-left corner of theWidget.voidupdate()Updates theWidget
-
Field Details
-
hovered
public boolean hoveredIndicates whether theWidgetis currently hovered by the mouse cursor.
-
-
Constructor Details
-
Method Details
-
isScrollable
public boolean isScrollable()Returns whether theWidgetis scrollable.- Returns:
trueif theWidgetis scrollable,falseotherwise.
-
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:
trueif scrolling is locked,falseotherwise.
-
setScrollLock
public void setScrollLock(boolean scrollLock) Sets the scrolling lock state for thisWidget.- Parameters:
scrollLock-trueto lock scrolling,falseto 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 theWidgethas focus.- Parameters:
key- the code of the key that was pressed
-
onKeyRelease
public void onKeyRelease(int key) Called when a key is released while theWidgethas 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 theWidgethas 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-trueif 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:
trueif the window is always on top; otherwisefalse
-
bringToTop
public void bringToTop()Moves thisWidgetto 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:
trueif the point is within the bounds of theWidget, otherwisefalse
-
isHovered
public boolean isHovered()Checks if the mouse pointer is currently over thisWidget.- Returns:
trueif the mouse pointer is over the widget, otherwisefalse
-
setVisible
public void setVisible(boolean visible) Sets the visibility of theWidget.- Parameters:
visible-trueif the element should be visible, otherwisefalse
-
isVisible
public boolean isVisible()Returns the current visibility of theWidget.- Returns:
trueif the element is visible, otherwisefalse
-
isVisibleWithinParent
public boolean isVisibleWithinParent()Checks if thisWidgetis at least partially visible within the boundaries of its absolute parentWidget. If theWidgethas no absolute parent (i.e., it is the root widget), it is considered fully visible by default.- Returns:
trueif any part of the widget is within the visible bounds of its absolute parent,falseotherwise.
-
isVisibleWithinWindow
public boolean isVisibleWithinWindow()Checks if theWidgetis at least partially within the visible bounds of the window.- Returns:
trueif any part of theWidgetis within the window bounds,falseotherwise.
-
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 thisWidgetto the screen by registering it with theWidgetManager. TheWidgetwill be managed and rendered as part of the UI. -
removeFromScreen
public void removeFromScreen()Removes thisWidgetfrom the screen by unregistering it from theWidgetManager. TheWidgetwill 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
-