-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify creation of scrollbox widgets
- Loading branch information
Showing
11 changed files
with
168 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Common/src/main/java/mezz/jei/common/gui/elements/DrawableWrappedText.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package mezz.jei.common.gui.elements; | ||
|
||
import mezz.jei.api.gui.drawable.IDrawable; | ||
import mezz.jei.common.util.StringUtil; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.locale.Language; | ||
import net.minecraft.network.chat.FormattedText; | ||
import net.minecraft.util.FormattedCharSequence; | ||
|
||
import java.util.List; | ||
|
||
public class DrawableWrappedText implements IDrawable { | ||
private static final int lineSpacing = 2; | ||
|
||
private final List<FormattedText> descriptionLines; | ||
private final int lineHeight; | ||
private final int width; | ||
private final int height; | ||
|
||
public DrawableWrappedText(List<FormattedText> text, int maxWidth) { | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
this.lineHeight = minecraft.font.lineHeight + lineSpacing; | ||
this.descriptionLines = StringUtil.splitLines(text, maxWidth); | ||
this.width = maxWidth; | ||
this.height = lineHeight * descriptionLines.size() - lineSpacing; | ||
} | ||
|
||
@Override | ||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
@Override | ||
public int getHeight() { | ||
return height; | ||
} | ||
|
||
@Override | ||
public void draw(GuiGraphics guiGraphics, int xOffset, int yOffset) { | ||
Language language = Language.getInstance(); | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
Font font = minecraft.font; | ||
|
||
int yPos = 0; | ||
for (FormattedText descriptionLine : descriptionLines) { | ||
FormattedCharSequence charSequence = language.getVisualOrder(descriptionLine); | ||
guiGraphics.drawString(font, charSequence, 0, yPos, 0xFF000000, false); | ||
yPos += lineHeight; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 35 additions & 5 deletions
40
CommonApi/src/main/java/mezz/jei/api/gui/widgets/IScrollBoxWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,48 @@ | ||
package mezz.jei.api.gui.widgets; | ||
|
||
import mezz.jei.api.gui.drawable.IDrawable; | ||
import mezz.jei.api.gui.inputs.IJeiInputHandler; | ||
import mezz.jei.api.helpers.IGuiHelper; | ||
import mezz.jei.api.recipe.category.IRecipeCategory; | ||
import net.minecraft.network.chat.FormattedText; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A smooth-scrolling area with a scrollbar. | ||
* | ||
* Create one with {@link IGuiHelper#createScrollBoxWidget}, and then | ||
* add it to your recipe in {@link IRecipeCategory#createRecipeExtras} | ||
* using {@link IRecipeExtrasBuilder#addWidget} and {@link IRecipeExtrasBuilder#addInputHandler}. | ||
* Create one with {@link IRecipeExtrasBuilder#addScrollBoxWidget}. | ||
* | ||
* @since 19.8.0 | ||
*/ | ||
public interface IScrollBoxWidget extends IRecipeWidget, IJeiInputHandler { | ||
/** | ||
* Get the width available for displaying contents in the scroll box. | ||
* The scroll bar takes up some of the space, so this can be used in order to create accurately-sized contents. | ||
* | ||
* @since 19.18.9 | ||
*/ | ||
int getContentAreaWidth(); | ||
|
||
/** | ||
* Get the visible height for displaying contents in the scroll box. | ||
* The actual height of the contents can be taller, because the box can scroll to show more. | ||
* | ||
* @since 19.18.9 | ||
*/ | ||
int getContentAreaHeight(); | ||
|
||
/** | ||
* Set the contents to display inside the scroll box. | ||
* The drawable width should match {@link #getContentAreaWidth()}, and the height can be any height. | ||
* | ||
* @since 19.18.9 | ||
*/ | ||
IScrollBoxWidget setContents(IDrawable contents); | ||
|
||
/** | ||
* Display text in the scroll box. | ||
* Text will be automatically wrapped in order to fit inside of {@link #getContentAreaWidth()}. | ||
* | ||
* @since 19.18.9 | ||
*/ | ||
IScrollBoxWidget setContents(List<FormattedText> text); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.