Class GuiSlider
java.lang.Object
codechicken.lib.gui.modular.lib.geometry.ConstrainedGeometry<T>
codechicken.lib.gui.modular.elements.GuiElement<GuiSlider>
codechicken.lib.gui.modular.elements.GuiSlider
- All Implemented Interfaces:
ElementEvents,GuiParent<GuiSlider>,TooltipHandler<GuiSlider>
This can be used as the base for anything that requires the linear movement of an element between two position.
e.g. Scroll bars, Slide controls and slide indicators.
Implementation is simple, Simply install a "Slide Element", this will be the moving element,
The movement of this element is confined to the bounds og the GuiSlider
The position of the slider is managed via the installed SliderState
Created by brandon3055 on 02/09/2023
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanThis should theoretically never be needed, But just in case...Fields inherited from class codechicken.lib.gui.modular.elements.GuiElement
hoverTime, initialized -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets up constraints to automatically control the slider element length.Binds the sliders position and size on the non-moving axis to the width and pos of theGuiSliderGuiElement<?>installSlider(GuiElement<?> slider) Install an element to be used as the sliding element.booleanbooleanmouseClicked(double mouseX, double mouseY, int button) Override this method to implement handling for the mouseClicked event.voidmouseMoved(double mouseX, double mouseY) Called whenever the cursor position changes.booleanmouseReleased(double mouseX, double mouseY, int button, boolean consumed) Root handler for mouseReleased event.booleanmouseScrolled(double mouseX, double mouseY, double scroll) Override this method to implement handling for the mouseScrolled event.setDragButton(int dragButton) setOutOfBoundsDist(double outOfBoundsDist) Set the out-of-bounds distance, If the cursor is dragged more than this distance from the slider bounds on the no-moving axis, the slider will snap back to its original position until the cursor moves back into bounds.setScrollableElement(GuiElement<?> scrollableElement) For use cases where this slider is controlling something like a scroll element.setScrollableElement(GuiElement<?> scrollableElement, boolean middleClickScroll) For use cases where this slider is controlling something like a scroll element.setScrollDragButton(int scrollDragButton) setSliderState(SliderState state) Set the slider state used by this slider element.static GuiSlider.ScrollBarvanillaScrollBar(GuiElement<?> parent, Axis axis) Vanilla does not really seem to have a standard for its scroll bars, But this is something that should at least fit in to a typical vanilla gui.Methods inherited from class codechicken.lib.gui.modular.elements.GuiElement
addChild, addJeiDropTargets, addJeiExclusions, adoptChild, applyQueuedChildUpdates, blockMouseEvents, blockMouseOver, bringChildToForeground, font, getChildren, getCombinedElementDepth, getJeiDropConsumer, getModularGui, getParent, getTooltip, getTooltipDelay, hoverTime, initElement, isDescendantOf, isEnabled, isJeiDropTarget, isJeiExcluded, isMouseOver, isOpaque, isRemoved, isTooltipEnabled, jeiExclude, mc, onScreenInit, removeChild, render, renderChild, renderOverlay, scaledScreenHeight, scaledScreenWidth, sendChildToBackground, sendChildToIndex, setEnabled, setEnabled, setEnableToolTip, setJeiDropTarget, setJeiExcluded, setOpaque, setRenderCull, setTooltip, setTooltipDelay, setZStacking, showToolTip, tick, toString, updateMouseOver, updateScreenData, zStackingMethods inherited from class codechicken.lib.gui.modular.lib.geometry.ConstrainedGeometry
addBoundsToRect, clearConstraints, clearGeometryCache, constrain, get, getChildBounds, getEnclosingRect, getParent, getPosition, getRectangle, placeInside, placeInside, placeOutside, placeOutside, setHeight, setPos, setSize, setWidth, setXPos, setYPos, strictMode, validate, xCenter, xMax, xMin, xSize, yCenter, yMax, yMin, ySizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface codechicken.lib.gui.modular.lib.ElementEvents
charTyped, charTyped, keyPressed, keyPressed, keyReleased, keyReleased, mouseClicked, mouseReleased, mouseScrolledMethods inherited from interface codechicken.lib.gui.modular.lib.geometry.GuiParent
addChild, getValueMethods inherited from interface codechicken.lib.gui.modular.lib.TooltipHandler
renderTooltip, setTooltip, setTooltip, setTooltip, setTooltipSingle, setTooltipSingle
-
Field Details
-
invertDragScroll
public boolean invertDragScrollThis should theoretically never be needed, But just in case...
-
-
Constructor Details
-
GuiSlider
Creates a basic gui slider that moves along the specified axis. This includes a default slider element the width of which is bound to the GuiSlider, And the length of which is controlled bySliderState.sliderRatio() -
GuiSlider
-
-
Method Details
-
vanillaScrollBar
Vanilla does not really seem to have a standard for its scroll bars, But this is something that should at least fit in to a typical vanilla gui. -
setSliderState
Set the slider state used by this slider element. The slider state is used to get and set the slider position. It also controls scroll speed. -
setScrollableElement
For use cases where this slider is controlling something like a scroll element. This enables scrolling when the cursor is over the scrollable element. It can also enable scrolling via middle-click + drag. -
setScrollableElement
For use cases where this slider is controlling something like a scroll element. This enables scrolling when the cursor is over the scrollable element. It can also enable scrolling via middle-click + drag. -
installSlider
Install an element to be used as the sliding element. The sliders minimum position (meaning either LEFT or TOP) on the moving axis will be constrained theGuiSliderAttempting to override this constraint after installing the slider element will break the slider.The size constraints, and position constraint for the non-moving axis need to be set by the implementor.
- See Also:
-
bindSliderLength
Sets up constraints to automatically control the slider element length. The slider element length will be controlled bySliderState.sliderRatio()This is used for things like gui scroll bars where the bar length changes based on the ratio of content in view. -
bindSliderWidth
Binds the sliders position and size on the non-moving axis to the width and pos of theGuiSlider -
getSlider
- Returns:
- the installed slider element.
-
isDragging
public boolean isDragging()- Returns:
- True if the slider is currently being dragged by the user.
-
setOutOfBoundsDist
Set the out-of-bounds distance, If the cursor is dragged more than this distance from the slider bounds on the no-moving axis, the slider will snap back to its original position until the cursor moves back into bounds. Default is 50, -1 will disable the snap-back functionality. -
setDragButton
- Parameters:
dragButton- The mouse button used to drag this slider (DefaultGuiButton.LEFT_CLICK)
-
setScrollDragButton
- Parameters:
scrollDragButton- The button used to scroll by clicking and dragging the defined scrollableElement (DefaultGuiButton.MIDDLE_CLICK)- See Also:
-
mouseClicked
public boolean mouseClicked(double mouseX, double mouseY, int button) Description copied from interface:ElementEventsOverride this method to implement handling for the mouseClicked event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can overrideElementEvents.mouseClicked(double, double, int, boolean)Note: You do not need to call super when overriding this interface method.
- Parameters:
mouseX- Mouse X positionmouseY- Mouse Y positionbutton- Mouse Button- Returns:
- true to consume event.
-
mouseReleased
public boolean mouseReleased(double mouseX, double mouseY, int button, boolean consumed) Description copied from interface:ElementEventsRoot handler for mouseReleased event. This method will always be called for all elements even if the event has already been consumed. There are a few uses for this method, but the fast majority of mouseReleased handling should be implemented viaElementEvents.mouseReleased(double, double, int)Note: If overriding this method, do so with caution, You must either return true (if you wish to consume the event) or you must return the result of the super call.
- Parameters:
mouseX- Mouse X positionmouseY- Mouse Y positionbutton- Mouse Buttonconsumed- Will be true if this action has already been consumed.- Returns:
- true if this event has been consumed.
-
mouseMoved
public void mouseMoved(double mouseX, double mouseY) Description copied from interface:ElementEventsCalled whenever the cursor position changes. Vanillas mouseDragged is not passed through because it is redundant. All mouse drag functionality can be archived using available events.- Parameters:
mouseX- new mouse X positionmouseY- new mouse Y position
-
mouseScrolled
public boolean mouseScrolled(double mouseX, double mouseY, double scroll) Description copied from interface:ElementEventsOverride this method to implement handling for the mouseScrolled event. This event propagates through the entire gui element stack from top to bottom, If eny element consumes the event it will not propagate any further. For rare cases where you need to receive this even if it has been consumed, you can overrideElementEvents.mouseScrolled(double, double, double, boolean)Note: You do not need to call super when overriding this interface method.
- Parameters:
mouseX- Mouse X positionmouseY- Mouse Y positionscroll- Scroll direction and amount- Returns:
- true to consume event.
-