Code Monkey home page Code Monkey logo

Comments (6)

Hades948 avatar Hades948 commented on May 25, 2024 2

I recently added UI resizing and I've noticed that I can get it to reliably happen for all of my text boxes, just at different sizes. I think the textbox size that it happens at changes for different fonts/strings. I took this GIF with just whatever the default Java font is when you do new Font(null, Font.PLAIN, 28):
litiengine_issue_474
I also recreated this issue with the "Monospaced" font (Using "Monospaced" instead of null in the Font constructor).

from litiengine.

hedfol avatar hedfol commented on May 25, 2024 1

Hi LITIENGINE community,

Can I make my first contribution by working on this issue?

I discovered the same cause that was already mentioned in a bug description: negative x position is produced by Align.getLocation(width, objectWidth) when a string line width (objectWidth) exceeds available space (width). This affects not just the LEFT but all values of Align. Similar issues occur with Valign enum:

gui-comp-text-overflow png

If these lines are removed:

if (objectWidth > width) {
return location;
}

if (objectHeight > height) {
return location;
}

position gets clamped:

gui-comp-text-overflow-clamp

However, two tests fail:

AlignTests > getLocation_InPoint(): expected: <-1.5> but was: <0.0>
AlignTests > getLocation_OffPoint(): expected: <0.45> but was: <0.0>
Test code:

@Test
void getLocation_OffPoint() {
// act
double offPointLocation = alignObject.getLocation(1.0, 1.1);
// assert
assertEquals(0.45, offPointLocation, 0.001); // 1.0 - 1.1 / 2.0
}
@Test
void getLocation_InPoint() {
// act
double inPointLocation = alignObject.getLocation(1.0, 5.0);
// assert
assertEquals(-1.5, inPointLocation, 0.001); // 1.0 - 5.0 / 2.0
}

Both alignment enums are used not only in GuiComponent.renderText() (related to this issue) but also in PhysicsEngine, CollisionEntity, and direct calls of TextRenderer methods. Is it necessary to separate text and entity alignments? For example: create a dedicated TextAlign enum, or just use a common Align but rename getLocation() to getTextLocation() and add getEntityLocation().

Either way an expected location behavior should be determined for all alignment values.

from litiengine.

nightm4re94 avatar nightm4re94 commented on May 25, 2024

I can reproduce this, but couldn't pinpoint the source of this issue.
What I can say for sure is that it depends on the font used due to the differences in glyph width:
image

from litiengine.

Gamebuster19901 avatar Gamebuster19901 commented on May 25, 2024

I remember also having issues with text rendering in java in one of my own projects.

I had to render the text using a GlyphVector to calculate bounds and stuff because it would just be wrong very often, however I've never seen it wrong by that much.

Just from a visual glance, it looks like the text's x-coordinate is being set to -(w*0.5) where w is the width of the line of text being rendered.

from litiengine.

nightm4re94 avatar nightm4re94 commented on May 25, 2024

Hi @hedfol , thank you for your detailed assessment! We welcome your contribution in this regard. I would neither create separate classes nor methods for this, but an overload to the getLocation method with an additional boolean parameter that lets the user decide which behaviour to choose. Since the current logic seems to be assuming the entity case, we should leave the uses of getLocation in entities untouched and only replace the uses in text scenarios with the new overload.

from litiengine.

hedfol avatar hedfol commented on May 25, 2024

Thanks @nightm4re94 , that's an easy solution! I've created a PR with suggested changes.

from litiengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.