-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/new gui layout #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix/new gui layout #418
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
680a5cb
feat: new pagination, row texts and guis
TheBjoRedCraft afd7a55
feat: new pagination, row texts and guis
TheBjoRedCraft e98c87b
feat: new pagination, row texts and guis
TheBjoRedCraft 873e612
feat: new pagination, row texts and guis
TheBjoRedCraft ea8ee5a
feat: new pagination, row texts and guis
TheBjoRedCraft bdf7018
Merge remote-tracking branch 'origin/version/26.2' into fix/new-gui-l…
TheBjoRedCraft 12af0ed
feat: new pagination, row texts and guis
TheBjoRedCraft 916cb68
Merge remote-tracking branch 'origin/version/26.2' into fix/new-gui-l…
TheBjoRedCraft df74a4a
fix: fix title not valid after modifiying it
TheBjoRedCraft fa33435
Merge branch 'version/26.2' into fix/new-gui-layout
TheBjoRedCraft 67e55a6
Update ABI reference
TheBjoRedCraft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
148 changes: 148 additions & 0 deletions
148
.../src/main/kotlin/dev/slne/surf/api/core/inventory/framework/internal/DefaultFontWidths.kt
This file contains hidden or 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,148 @@ | ||
| package dev.slne.surf.api.core.inventory.framework.internal | ||
|
|
||
| import dev.slne.surf.api.core.util.freeze | ||
| import dev.slne.surf.api.shared.api.util.InternalSurfApi | ||
| import it.unimi.dsi.fastutil.ints.Int2IntMap | ||
| import it.unimi.dsi.fastutil.ints.Int2IntMaps | ||
| import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap | ||
| import net.kyori.adventure.text.Component | ||
| import net.kyori.adventure.text.format.TextDecoration | ||
|
|
||
| /** | ||
| * Advance widths of the vanilla `minecraft:default` font, used to lay out header text that is | ||
| * rendered in the client's own font instead of a fixed-width resource-pack font. | ||
| * | ||
| * An *advance* is the number of pixels the render cursor moves on for one glyph — the glyph's own | ||
| * width plus the one pixel of spacing the font renderer inserts after it. Every code point not | ||
| * listed in [advances] advances by [DEFAULT_ADVANCE]; bold text adds [BOLD_EXTRA_ADVANCE] on top of | ||
| * every glyph. | ||
| * | ||
| * The table is measured off the three bitmap sheets of the vanilla font (`ascii.png`, | ||
| * `accented.png`, `nonlatin_european.png`), so it covers Latin, Latin Extended, Greek and Cyrillic | ||
| * exactly. Glyphs outside those sheets — CJK from the Unifont fallback, custom resource-pack glyphs | ||
| * — are measured as [DEFAULT_ADVANCE], so pass an override map for them via the `charWidths` | ||
| * parameter of the platform header components if they must be measured exactly. | ||
| * | ||
| * This is internal infrastructure — use the platform `TextAlignment` / header DSL instead. | ||
| */ | ||
| @InternalSurfApi | ||
| object DefaultFontWidths { | ||
|
|
||
| /** Advance of a glyph the vanilla font renders at its regular width (5px glyph + 1px spacing). */ | ||
| const val DEFAULT_ADVANCE = 6 | ||
|
|
||
| /** Extra advance the font renderer adds to every glyph of bold text. */ | ||
| const val BOLD_EXTRA_ADVANCE = 1 | ||
|
|
||
| /** Advance of a space, which the vanilla font takes from its space provider. */ | ||
| const val SPACE_ADVANCE = 4 | ||
|
|
||
| /** | ||
| * Every glyph of the vanilla font sheets whose advance is not [DEFAULT_ADVANCE], grouped by | ||
| * that advance. Generated by measuring the sheets, see [advances]. | ||
| */ | ||
| private val ADVANCES_BY_WIDTH = mapOf( | ||
| 2 to "!',.:;i|¡¦·ıǀǃʻˌ˙;·і׃ויןᛁᛌᛧ᛬ᴉị⁏ⁱ⏽⸵⹁יִ𐌹", | ||
| 3 to "`l´ìíįĺļɩɭ̧ίιՙ՚՛՝լ׳᛫ᛵᶅᶖḷἱί‘’‚•′‵⁽⁾₍₎ꞁוֹ", | ||
| 4 to "\"()*I[]t{}¨¹ÌÍÎÏîïĪīĮİľŀţŧſƖƗƚƫƭǁǏǐțȴɨɪʇʈΙΪϊІЇїӀ՜՞׆זנװױײ჻ჼᚨᚭᚮᚲᚽᚿᛂᛆᛊᛍᛐᛓᛙᛚḮḯḹḻḽṫṭṯṱẗẛỈỉỊἰὶῑῒΐῙ‐‑‹›‼⁎⁑⁒⁺⁻⁼₁₊₋₌∥⋆⏴⏵⏸◘◦♀♩♭♮ײַוּ", | ||
| 5 to "<>fkª°²³ºĨĩĬĭijķĸłťƙǩȊȋȶɟɬʞκгкѓќҕӄӷԼՒէւג״ჯᚠᚡᚦᚧᚩᚪᚫᚱᚳᚴᚵᚹᛈᛑᛒᛔᛕᛛᛩᛴᶂḟḬḭḱḳḵẜẝỽἶἷῐῖῗῘ“”„″‶⁊⁰⁴⁵⁶⁷⁸⁹ⁿ₀₂₃₄₅₆₇₈₉∁⌡▌●ꝛכּ", | ||
| 7 to "@~«¶»ÐĐđħŁƀƄƅƇƈƉƑƓƝƬƳǤǥȽɃɇɈɉɊɋɌɍɖɗɠɲɳɻʄʆʐʛʠʮσϔЊЋДЦЪдщъыђњћѢѣѴѵѶѷҊҋҌҍҒҗҚҞҠҢңҤҥҨҩҲҳҵҶҷӅӆӉӊӍӎӹӺԆԇԎԏԤԥԦԧԨԩԬԭԮԯԳԴԹԺԽՂՄՌգդզժխղմնվքևֈႫႯჱᛃᛟᶁᶃᶆᶇᶍᶎᶏᶐᶑᶒᶓᶕᶗᶙỻỿἅἸἾἿῚΊ–‴‷⁋₣₫€₭₺₽₾⅟⇵√∝≈≡≢⏩⏪⏯▶▷◀◁⛄✔✘❌ⱥⴁⴂⴆⴎⴏⴝꚀꚁꚈꚉꚊꚋꚎꚒꚓꚗꜩꞕꞨꟆfl🔥🪓", | ||
| 8 to "¤©®¼½¾ďĦʼnƁƊƠơƢƣƤƯưƴljȡȵɄɎɏɚɝɷʉʧʪʫʯΆΈΉΌΎΏωώЂЉЖФШЫЮюљҴҼҽҾҿӁӜӸԄԅտփႡႢႥႦႧႪႭႮႰႳႻჀჅლᛠᛢᛪᛳᵬᵭᵯᵰᵱᵲᵳᵴỚớỜờỞởỠỡỢợỨứỪừỬửỮữỰựỺἻἽὠὡὢὣὤὥὦὧὼώᾠᾡᾢᾣᾤᾥᾦᾧῲῳῴῶῷ…‰※⁂⁈⁉₦₩₪₱₳₴₷₻℗⅙⅚←→⇄∀∅∛∜∞≔⌀⌂⌘⌚⌛⌠⏭⏮⏳⏻⏼║╖╗╜╝╢╣░◎☂☃☄★☆☈☔☠☻♫♬⚀⚁⚂⚃⚄⚅⚐⚑⚓⚔⚗⛨✂✉✎❄❤⧈⭐⭘⯪⯫ⱢⱱꜨff�🔔🛡🧪🪣", | ||
| 9 to "ƕǶʦʨЩҖҦҧԂԃԈԉԊԋԔԕԖԗԠԡԢԣᵺἈἉἎἏἘἙἨἩἮἯἺἼὈὉὙὟὨὩὮᾈᾉᾎᾏᾘᾙᾞᾟᾨᾩᾮᾺΆῈΈῊΉῪΎῬῸΌῺΏ—‱⁗™⅐⅑⅓⅔⅕⅖⅗⅛⅜⅝⅞↉↔⇏⇒⇔─┌└├┬┴┼═╒╓╔╘╙╚╞╟╠╤╥╦╧╨╩╪╫╬▀▄█▐▒▓☀☁☽⛈⛏ꚅꚖꜹꜻꜽffi🌊🌧🍖🎣🏹🔱🗡", | ||
| 10 to "ÆæŒœDŽDždžLJLjNJNjnjǢǣDZDzdzǼǽȸȹɶʣʤʥʩϓӔӕԘԙԪԫᴂᴔᵫἊἋἌἍἚἛἜἝἪἫἬἭἹὊὋὌὍὛὝὪὫὬὭὯᾊᾋᾌᾍᾚᾛᾜᾝᾪᾫᾬᾭᾯ⁇₧₨₯№ℹ⅒⅘①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ⓪☐☑☒☜☞☮☯⚠ꚄꜲꜳꜴꜵꜶꜷꜸꜺꜼꝎꝏꭣfflstﬓﬔﬕﬖﬗ", | ||
| ) | ||
|
|
||
| /** | ||
| * Per-code-point advance overrides for every glyph of the vanilla font sheets that is not | ||
| * [DEFAULT_ADVANCE] pixels wide. | ||
| * | ||
| * Measured off `ascii.png`, `accented.png` and `nonlatin_european.png` themselves, so these are | ||
| * the advances the client actually uses — Latin, Latin Extended, Greek and Cyrillic included. | ||
| * | ||
| * Suitable as the `charWidths` argument of [TextAlignmentMath.textWidth] when [DEFAULT_ADVANCE] | ||
| * is passed as its `charSize` and `0` as its `charSpacing`. | ||
| */ | ||
| val advances: Int2IntMap = Int2IntOpenHashMap(1100).apply { | ||
| // Measured off the vanilla font sheets (ascii.png, accented.png, nonlatin_european.png): | ||
| // advance = width of the drawn pixels plus the one pixel the renderer adds after a glyph. | ||
| // The space is the exception - it carries no pixels and comes from the space provider. | ||
| put(' '.code, SPACE_ADVANCE) | ||
|
|
||
| for ((advance, glyphs) in ADVANCES_BY_WIDTH) { | ||
| for (glyph in glyphs) put(glyph.code, advance) | ||
| } | ||
| }.freeze() | ||
|
|
||
| /** | ||
| * Returns the advance of [codePoint] in the vanilla font. | ||
| * | ||
| * [overrides] wins over [advances], which in turn wins over [DEFAULT_ADVANCE]. | ||
| * | ||
| * @param codePoint the Unicode code point to measure | ||
| * @param bold whether the glyph is rendered bold | ||
| * @param overrides per-code-point advance overrides for glyphs this table does not cover | ||
| */ | ||
| fun charWidth( | ||
| codePoint: Int, | ||
| bold: Boolean = false, | ||
| overrides: Int2IntMap = Int2IntMaps.EMPTY_MAP, | ||
| ): Int { | ||
| val advance = when { | ||
| overrides.containsKey(codePoint) -> overrides.get(codePoint) | ||
| advances.containsKey(codePoint) -> advances.get(codePoint) | ||
| else -> DEFAULT_ADVANCE | ||
| } | ||
|
|
||
| return advance + if (bold) BOLD_EXTRA_ADVANCE else 0 | ||
| } | ||
|
|
||
| /** | ||
| * Returns the total number of pixels [text] advances the render cursor by when rendered in the | ||
| * vanilla font. | ||
| * | ||
| * Walks [text] per Unicode **code point**, so a surrogate pair counts as the single glyph it | ||
| * renders as. Returns `0` for an empty string. | ||
| * | ||
| * @param text the string to measure, exactly as it is rendered | ||
| * @param bold whether the text is rendered bold | ||
| * @param overrides per-code-point advance overrides for glyphs this table does not cover | ||
| */ | ||
| fun textWidth( | ||
| text: String, | ||
| bold: Boolean = false, | ||
| overrides: Int2IntMap = Int2IntMaps.EMPTY_MAP, | ||
| ): Int { | ||
| var width = 0 | ||
| var index = 0 | ||
| while (index < text.length) { | ||
| val codePoint = text.codePointAt(index) | ||
| width += charWidth(codePoint, bold, overrides) | ||
| index += Character.charCount(codePoint) | ||
| } | ||
|
|
||
| return width | ||
| } | ||
|
|
||
| /** | ||
| * Returns the total number of pixels [component] advances the render cursor by when rendered in | ||
| * the vanilla font. | ||
| * | ||
| * Convenience wrapper around [layoutViewText] with the metrics of the vanilla font: no extra | ||
| * spacing and no casing transformation, so the component is measured exactly as it is. | ||
| * | ||
| * @param component the component to measure, exactly as it is rendered | ||
| * @param bold the [TextDecoration.BOLD] state inherited from the surrounding style | ||
| * @param overrides per-code-point advance overrides for glyphs this table does not cover | ||
| */ | ||
| fun componentWidth( | ||
| component: Component, | ||
| bold: Boolean = false, | ||
| overrides: Int2IntMap = Int2IntMaps.EMPTY_MAP, | ||
| ): Int = layoutViewText( | ||
| component = component, | ||
| charSpacing = 0, | ||
| uppercase = false, | ||
| spaceShift = null, | ||
| bold = bold, | ||
| ) { codePoint, glyphBold -> charWidth(codePoint, glyphBold, overrides) }.width | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.