Skip to content

Conversation

@jjuhl
Copy link
Contributor

@jjuhl jjuhl commented Jan 11, 2026

Hi Texus

A mixed bag of changes for you :)

/Jesper Juhl

PS. If merged, this also closes #290

jjuhl added 7 commits January 11, 2026 16:05
No need to copy when a const& will do.
It's more readable and avoids using magic numbers which makes it less
error prone when refactoring.
if
    tgui::keyboard::openVirtualKeyboard(const Widget* requestingWidget, FloatRect inputRect)
is passed a requestingWidget that is nullptr, then we'll invoke undefined behaviour (and probably crash) when we do
    const auto* gui = requestingWidget->getParentGui();

Add an assert for debug builds to catch the problem and also test the
pointer and just return without doing anything if it is nullptr for
release builds.

Sure, the function is deprecated and people shouldn't be using it, but
as long as it remains in the library I believe it should do its best
to work properly and not cause problems (and help people spot issues).
The language is named (uppercase) C++, not c++.
When initializing with a cast, use auto to avoid repeating the type
(and to make sure you don't accidentally use the wrong type on the
left hand side of =).
Some text files were missing a newline at the end. That's annoying for
a few reasons:

  - If you `cat` the file you end up with your shell prompt on the
  same line as the last line of the file output.

  - When creating patches/diff's you end up with an annoying "\ No
  newline at end of file" line in the output.

  - When passing files to other tools that work on a line-by-line
  basis you may end up with problems for the last line if the tool is
  not prepared to handle lines that don't end with a \n but just EOF.
@jjuhl jjuhl force-pushed the mixed-bag-of-changes branch 3 times, most recently from 10899b1 to bc80517 Compare January 11, 2026 15:53
Adding +0.5 to a floating point value and then casting (truncating) to
an integer is not the right way to do rounding. Although it may seem
to do the right thing most of the time it has issues in several corner
cases. The correct thing to do is to use
std::round/std::lround/std::llround that know how to do the rounding
correctly including for the corner cases (and additionally, the
compilers know those functions well and often generate more optimized
code for them than random arithmetic).
@jjuhl jjuhl force-pushed the mixed-bag-of-changes branch from bc80517 to 943703f Compare January 11, 2026 16:01
@texus texus merged commit 936de23 into texus:1.x Jan 11, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potentially incorrect rounding

2 participants