Skip to content

Various mixed commits#332

Merged
texus merged 4 commits intotexus:1.xfrom
jjuhl:various-mixed-commits
Mar 8, 2026
Merged

Various mixed commits#332
texus merged 4 commits intotexus:1.xfrom
jjuhl:various-mixed-commits

Conversation

@jjuhl
Copy link
Contributor

@jjuhl jjuhl commented Mar 6, 2026

A mixed bag of stuff for you :)

@jjuhl
Copy link
Contributor Author

jjuhl commented Mar 6, 2026

Hmm, the failure in CI (linux-latest-dev) doesn't happen on my local machine. I'll just leave the PR as-is and maybe you can figure out what the issue is :)

@texus
Copy link
Owner

texus commented Mar 6, 2026

maybe you can figure out what the issue is :)

I checked other places where setEditCursorBlinkRate was used and found that is was being changed at

tgui::setEditCursorBlinkRate(std::chrono::milliseconds(100));

Unlike your code, my test didn't restore the original value when it's done. So if that test runs before yours then it will fail.
While you could technically fix the test in EditBox.cpp, it is actually the same as what you are testing, so I think you can just remove the entire "Blink rate" section in EditBox.cpp and keep the new one in Global.cpp.

TGUI_ASSERT(!(hi < lo), "The highest value must not be less than the lowest value");

Maybe !(hi < lo) can be replaced by hi >= lo?
Both are valid, with the negation it might read more like "you can't do this thing" as opposed to "you must do this thing", but I find it a bit weird to see a negated comparison.
This is nitpicking of course, if I wouldn't have already had to comment on setEditCursorBlinkRate then I wouldn't have bothered mentioning it and would have just merged it.

@jjuhl
Copy link
Contributor Author

jjuhl commented Mar 6, 2026

"Maybe !(hi < lo) can be replaced by hi >= lo?" - I considered that but rejected it since most types implement operator< but not necessarily other operators, so this is the form that would work for most types.

@jjuhl
Copy link
Contributor Author

jjuhl commented Mar 6, 2026

I'll update the PR regarding blink rate.

@texus
Copy link
Owner

texus commented Mar 6, 2026

I don't think the clamp function will ever be used on a non-numeric type that lacks a >= operator, but it is a valid point.
Using !(hi < lo) would indeed be better for not putting additional restrictions on the template type.

@jjuhl jjuhl force-pushed the various-mixed-commits branch from 762b54d to 82a921d Compare March 7, 2026 18:46
jjuhl added 4 commits March 8, 2026 14:01
As far as I can tell, tgui::clamp matches the behaviour and
precondition requirements of std::clamp exactly, but if a user passes
a value of 'hi' that is less than 'lo' then the returned result may be
surprising (not undefined, just not what you'd expect). To guard
against such surprises I think it is prudent to add an assert for
debug builds that checks the precondition - it costs nothing for
release builds but may save some users from a nasty surprise in debug
builds.
This adds tests for some (not all) global TGUI functions
declared/defined in Global.hpp/Global.cpp

Some of these were already fully or partially covered transitively by
other tests, but adding explicit tests doesn't hurt. This just makes
the tests explicit and expands the coverage.

Some global functions are not tested yet since I need to figure out
how to do that properly, but that doesn't detract from these tests.
@jjuhl jjuhl force-pushed the various-mixed-commits branch from 82a921d to 147a796 Compare March 8, 2026 13:01
@texus texus merged commit a3de3a2 into texus:1.x Mar 8, 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.

2 participants