panel work
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-04-01 21:02:40 -04:00
parent ac3059caf2
commit 183a8ce901
5 changed files with 170 additions and 37 deletions

View File

@ -103,7 +103,7 @@ public class MenuWorldSelect {
Label worldNameLabel = Label.createLabel("Input Name: ");
worldNameInputContainer.addChild(worldNameLabel);
TextInput worldNameInput = TextInput.createTextInput();
worldNameInput.setMinWidth(100);
worldNameInput.setMinWidth(150);
worldNameInput.setMaxWidthPercent(50);
worldNameInput.setText("World name");
worldNameInputContainer.addChild(worldNameInput);
@ -114,7 +114,7 @@ public class MenuWorldSelect {
Label worldSeedLabel = Label.createLabel("Input Seed: ");
worldSeedInputContainer.addChild(worldSeedLabel);
TextInput worldSeedInput = TextInput.createTextInput();
worldSeedInput.setMinWidth(100);
worldSeedInput.setMinWidth(150);
worldSeedInput.setMaxWidthPercent(50);
worldSeedInput.setText(System.currentTimeMillis() + "");
worldSeedInputContainer.addChild(worldSeedInput);

View File

@ -30,6 +30,11 @@ public class Button extends StandardContainerElement implements DrawableElement,
static float COLOR_FRAME_FOCUSED_DEFAULT = 0.1f;
static float COLOR_FRAME_UNFOCUSED_DEFAULT = 0.01f;
/**
* Default padding applied to buttons
*/
static final int DEFAULT_PADDING = 10;
/**
* The color of the backing element
*/
@ -40,6 +45,11 @@ public class Button extends StandardContainerElement implements DrawableElement,
*/
Vector3f frameColor = new Vector3f(COLOR_FRAME_FOCUSED_DEFAULT);
/**
* The color of the background of the frame
*/
Vector3f frameBackgroundColor = new Vector3f(COLOR_FRAME_UNFOCUSED_DEFAULT);
Vector3f boxPosition = new Vector3f();
Vector3f boxDimensions = new Vector3f();
Vector3f texPosition = new Vector3f(0,0,0);
@ -49,6 +59,11 @@ public class Button extends StandardContainerElement implements DrawableElement,
boolean visible = false;
boolean focused = false;
/**
* Controls whether the button draws its decorative frame or not
*/
boolean drawFrame = true;
FocusEventCallback onFocusCallback;
FocusEventCallback onLoseFocusCallback;
ClickEventCallback clickCallback;
@ -89,6 +104,10 @@ public class Button extends StandardContainerElement implements DrawableElement,
*/
public static Button createButton(String text, Runnable callback){
Button rVal = new Button();
rVal.setPaddingTop(DEFAULT_PADDING);
rVal.setPaddingRight(DEFAULT_PADDING);
rVal.setPaddingLeft(DEFAULT_PADDING);
rVal.setPaddingBottom(DEFAULT_PADDING);
Label rValLabel = Label.createLabel(text);
rValLabel.setText(text);
rVal.addChild(rValLabel);
@ -111,6 +130,10 @@ public class Button extends StandardContainerElement implements DrawableElement,
*/
public static Button createButtonCentered(String text, Runnable callback){
Button rVal = new Button();
rVal.setPaddingTop(DEFAULT_PADDING);
rVal.setPaddingRight(DEFAULT_PADDING);
rVal.setPaddingLeft(DEFAULT_PADDING);
rVal.setPaddingBottom(DEFAULT_PADDING);
Label rValLabel = Label.createLabel(text);
rValLabel.setText(text);
rVal.addChild(rValLabel);
@ -134,6 +157,10 @@ public class Button extends StandardContainerElement implements DrawableElement,
*/
public static Button createButtonCentered(String text, float fontSize, Runnable callback){
Button rVal = new Button();
rVal.setPaddingTop(DEFAULT_PADDING);
rVal.setPaddingRight(DEFAULT_PADDING);
rVal.setPaddingLeft(DEFAULT_PADDING);
rVal.setPaddingBottom(DEFAULT_PADDING);
Label rValLabel = Label.createLabel(text, fontSize);
rValLabel.setText(text);
rVal.addChild(rValLabel);
@ -234,20 +261,20 @@ public class Button extends StandardContainerElement implements DrawableElement,
openGLState.glViewport(framebuffer.getWidth(), framebuffer.getHeight());
//render background of window
if(this.isFocused()){
frameColor.set(COLOR_FRAME_FOCUSED_DEFAULT);
UIFrameUtils.drawFrame(
AssetDataStrings.UI_FRAME_TEXTURE_DEFAULT_3, frameColor, 48, 12,
this.getAbsoluteX(), this.getAbsoluteY(), this.getWidth(), this.getHeight(),
framebuffer, framebufferPosX, framebufferPosY
);
} else {
frameColor.set(COLOR_FRAME_UNFOCUSED_DEFAULT);
UIFrameUtils.drawFrame(
AssetDataStrings.UI_FRAME_TEXTURE_DEFAULT_3, frameColor, 48, 12,
this.getAbsoluteX(), this.getAbsoluteY(), this.getWidth(), this.getHeight(),
framebuffer, framebufferPosX, framebufferPosY
);
if(this.drawFrame){
if(this.isFocused()){
UIFrameUtils.drawFrame(
AssetDataStrings.UI_FRAME_TEXTURE_DEFAULT_3, frameColor, 48, 12,
this.getAbsoluteX(), this.getAbsoluteY(), this.getWidth(), this.getHeight(),
framebuffer, framebufferPosX, framebufferPosY
);
} else {
UIFrameUtils.drawFrame(
AssetDataStrings.UI_FRAME_TEXTURE_DEFAULT_3, frameBackgroundColor, 48, 12,
this.getAbsoluteX(), this.getAbsoluteY(), this.getWidth(), this.getHeight(),
framebuffer, framebufferPosX, framebufferPosY
);
}
}
//
@ -338,5 +365,21 @@ public class Button extends StandardContainerElement implements DrawableElement,
public void setColor(Vector3f color){
this.color.set(color);
}
/**
* Sets whether the button should draw its frame or not
* @param drawFrame true if it should draw its frame, false otherwise
*/
public void setDrawFrame(boolean drawFrame){
this.drawFrame = drawFrame;
}
/**
* Gets whether the button should draw its frame or not
* @return true if it should draw its frame, false otherwise
*/
public boolean getDrawFrame(){
return this.drawFrame;
}
}

View File

@ -26,7 +26,7 @@ public class Label extends StandardContainerElement implements DrawableElement {
String text = "";
int textPixelWidth = 0;
float fontSize = 1.0f;
float fontSize = DEFAULT_FONT_SIZE;
static final Vector3f windowDrawDebugColor = new Vector3f(1.0f,1.0f,1.0f);
@ -38,7 +38,7 @@ public class Label extends StandardContainerElement implements DrawableElement {
* @return the label element
*/
public static Label createLabel(String text){
Label rVal = new Label(1.0f);
Label rVal = new Label(DEFAULT_FONT_SIZE);
rVal.setText(text);
return rVal;
}

View File

@ -0,0 +1,96 @@
package electrosphere.renderer.ui.elements;
import org.joml.Vector3f;
import org.lwjgl.util.yoga.Yoga;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.ui.elementtypes.DrawableElement;
import electrosphere.renderer.ui.elementtypes.Element;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.frame.UIFrameUtils;
/**
* A panel that should contain other elements
*/
public class Panel extends StandardContainerElement implements DrawableElement {
static final Vector3f windowDrawDebugColor = new Vector3f(1.0f,1.0f,1.0f);
/**
* Default padding applied to buttons
*/
static final int DEFAULT_PADDING = 10;
/**
* The default color of the frame
*/
static float COLOR_FRAME_FOCUSED_DEFAULT = 0.1f;
/**
* The color of the frame
*/
Vector3f frameColor = new Vector3f(COLOR_FRAME_FOCUSED_DEFAULT);
/**
* Creates a label element
* @param text the text for the label
* @return the label element
*/
public static Panel createPanel(){
Panel rVal = new Panel();
rVal.setPaddingTop(DEFAULT_PADDING);
rVal.setPaddingRight(DEFAULT_PADDING);
rVal.setPaddingLeft(DEFAULT_PADDING);
rVal.setPaddingBottom(DEFAULT_PADDING);
return rVal;
}
/**
* Constructor
*/
private Panel(){
super();
Yoga.YGNodeStyleSetFlexDirection(this.yogaNode, Yoga.YGFlexDirectionRow);
}
public void setColor(Vector3f color){
for(Element character : childList){
((BitmapCharacter)character).setColor(color);
}
}
@Override
public void draw(
RenderPipelineState renderPipelineState,
OpenGLState openGLState,
Framebuffer framebuffer,
int framebufferPosX,
int framebufferPosY
) {
UIFrameUtils.drawFrame(
AssetDataStrings.UI_FRAME_TEXTURE_DEFAULT_3, frameColor, 48, 12,
this.getAbsoluteX(), this.getAbsoluteY(), this.getWidth(), this.getHeight(),
framebuffer, framebufferPosX, framebufferPosY
);
for(Element child : childList){
((DrawableElement)child).draw(
renderPipelineState,
openGLState,
framebuffer,
framebufferPosX,
framebufferPosY
);
}
}
public boolean handleEvent(Event event){
return true;
}
}

View File

@ -52,7 +52,7 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
String text = "";
int textPixelWidth = 0;
float fontSize = 1.0f;
float fontSize = Label.DEFAULT_FONT_SIZE;
Font font;
@ -72,7 +72,8 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
* @return The text input
*/
public static TextInput createTextInput(){
return new TextInput(Label.DEFAULT_FONT_SIZE);
TextInput rVal = new TextInput(Label.DEFAULT_FONT_SIZE);
return rVal;
}
/**
@ -84,13 +85,16 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
this.font = Globals.fontManager.getFont("default");
this.fontSize = fontSize;
this.color = new Vector3f(1,1,1);
setHeight((int)(font.getFontHeight() * fontSize));
this.setHeight((int)(font.getFontHeight() * fontSize));
Yoga.YGNodeStyleSetFlexDirection(this.yogaNode, Yoga.YGFlexDirectionRow);
Yoga.YGNodeStyleSetMinHeight(this.yogaNode, font.getFontHeight() * fontSize);
Yoga.YGNodeStyleSetMinWidth(this.yogaNode, 1);
}
void generateLetters(){
/**
* Generate letter elements
*/
private void generateLetters(){
for(Element el : getChildren()){
Globals.signalSystem.post(SignalType.YOGA_DESTROY, el);
}
@ -106,12 +110,12 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
public void setText(String text){
this.text = text;
textPixelWidth = 0;
this.textPixelWidth = 0;
for(int i = 0; i < text.length(); i++){
Vector3f bitMapDimension = this.font.getDimensionOfCharacterDiscrete(text.charAt(i));
textPixelWidth = textPixelWidth + (int)bitMapDimension.x;
this.textPixelWidth = this.textPixelWidth + (int)bitMapDimension.x;
}
generateLetters();
this.generateLetters();
}
public void setColor(Vector3f color){
@ -133,16 +137,6 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
int framebufferPosX,
int framebufferPosY
) {
//
//Draw decorations
float ndcWidth = (float)getWidth()/framebuffer.getWidth();
float ndcHeight = (float)getHeight()/framebuffer.getHeight();
float ndcX = (float)this.absoluteToFramebuffer(getAbsoluteX(),framebufferPosX)/framebuffer.getWidth();
float ndcY = (float)this.absoluteToFramebuffer(getAbsoluteY(),framebufferPosY)/framebuffer.getHeight();
boxPosition = new Vector3f(ndcX,ndcY,0);
boxDimensions = new Vector3f(ndcWidth,ndcHeight,0);
//this call binds the screen as the "texture" we're rendering to
//have to call before actually rendering
framebuffer.bind(openGLState);
@ -151,13 +145,13 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
//render background of window
if(this.isFocused()){
UIFrameUtils.drawFrame(
AssetDataStrings.UI_FRAME_TEXTURE_DEFAULT_3, backgroundColor, 48, 12,
AssetDataStrings.UI_FRAME_TEXTURE_DEFAULT_1, backgroundColor, 48, 12,
this.getAbsoluteX(), this.getAbsoluteY(), this.getWidth(), this.getHeight(),
framebuffer, framebufferPosX, framebufferPosY
);
} else {
UIFrameUtils.drawFrame(
AssetDataStrings.UI_FRAME_TEXTURE_DEFAULT_3, backgroundColor, 48, 12,
AssetDataStrings.UI_FRAME_TEXTURE_DEFAULT_2, backgroundColor, 48, 12,
this.getAbsoluteX(), this.getAbsoluteY(), this.getWidth(), this.getHeight(),
framebuffer, framebufferPosX, framebufferPosY
);