Skip to content

Commit

Permalink
New: drawCenteredText in NanoVGHelper (#279)
Browse files Browse the repository at this point in the history
* draw centered text

* icon

* Delete icon.svg

* Add files via upload

* Delete icon.svg

* run apiDump

* remove nvgFill call

---------

Co-authored-by: Wyvest <[email protected]>
  • Loading branch information
badjavadev and Wyvest authored Dec 20, 2023
1 parent 0e5f7ab commit 45faf24
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/OneConfig.api
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,7 @@ public abstract interface class cc/polyfrost/oneconfig/renderer/NanoVGHelper {
public static final field INSTANCE Lcc/polyfrost/oneconfig/renderer/NanoVGHelper;
public abstract fun color (JI)Lorg/lwjgl/nanovg/NVGColor;
public abstract fun drawBorderedText (Ljava/lang/String;FFII)I
public abstract fun drawCenteredText (JLjava/lang/String;FFIFLcc/polyfrost/oneconfig/renderer/font/Font;)V
public abstract fun drawCircle (JFFFI)V
public abstract fun drawDropShadow (JFFFFFFF)V
public abstract fun drawEllipse (JFFFFI)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,28 @@ public void drawText(long vg, String text, float x, float y, int color, float si
nvgColor.free();
}

/**
* Draws a centered String with the given parameters.
*
* @param vg The NanoVG context.
* @param text The text.
* @param x The x position.
* @param y The y position.
* @param color The color.
* @param size The size.
* @param font The font.
* @see cc.polyfrost.oneconfig.renderer.font.Font
*/
@Override
public void drawCenteredText(long vg, String text, float x, float y, int color, float size, Font font) {
nvgBeginPath(vg);
nvgFontSize(vg, size);
nvgFontFace(vg, font.getName());
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
NVGColor nvgColor = color(vg, color);
nvgText(vg, x, y, text);
nvgColor.free();
}

@Override
public void drawWrappedString(long vg, String text, float x, float y, float width, int color, float size, Font font) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/cc/polyfrost/oneconfig/renderer/NanoVGHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,20 @@ public interface NanoVGHelper {
*/
void drawText(long vg, String text, float x, float y, int color, float size, Font font);

/**
* Draws a centered String with the given parameters.
*
* @param vg The NanoVG context.
* @param text The text.
* @param x The x position.
* @param y The y position.
* @param color The color.
* @param size The size.
* @param font The font.
* @see Font
*/
void drawCenteredText(long vg, String text, float x, float y, int color, float size, Font font);

/**
* Draws a String wrapped at the given width, with the given parameters.
*
Expand Down

0 comments on commit 45faf24

Please sign in to comment.