Skip to content

Commit dfe0973

Browse files
committed
Renamed is_ready_ to is_valid_ and added region::is_valid()
1 parent 850ed32 commit dfe0973

File tree

7 files changed

+47
-35
lines changed

7 files changed

+47
-35
lines changed

include/lxgui/gui_region.hpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ class region : public utils::enable_observer_from_this<region> {
305305
*/
306306
bool is_visible() const;
307307

308+
/**
309+
* \brief Checks if this region has all its borders correctly defined.
310+
* \return 'true' if this region has all its borders correctly defined
311+
* \note To be valid, a region needs to have a defined position and size along
312+
* both the X and Y dimensions. This means either one anchor and a set size,
313+
* or two opposite anchors. For example, any anchor plus a call to set_dimensions().
314+
* Or a top_left plus a bottom_right anchors. Or a left plus a right anchors plus a
315+
* call to set_height().
316+
*/
317+
bool is_valid() const;
318+
308319
/**
309320
* \brief Changes this region's absolute dimensions (in pixels).
310321
* \param dimensions The new dimensions
@@ -794,7 +805,7 @@ class region : public utils::enable_observer_from_this<region> {
794805
bool is_manually_inherited_ = false;
795806
bool is_virtual_ = false;
796807
bool is_loaded_ = false;
797-
bool is_ready_ = true;
808+
bool is_valid_ = true;
798809

799810
std::array<std::optional<anchor>, 9> anchor_list_;
800811
bounds2<bool> defined_borders_;

include/lxgui/gui_text.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ class text {
437437

438438
renderer& renderer_;
439439

440-
bool is_ready_ = false;
441440
float scaling_factor_ = 1.0f;
442441
float tracking_ = 0.0f;
443442
float line_spacing_ = 1.0f;

src/gui_font_string.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ font_string::font_string(
2121
void font_string::render() const {
2222
base::render();
2323

24-
if (!text_ || !is_ready_ || !is_visible())
24+
if (!text_ || !is_valid_ || !is_visible())
2525
return;
2626

2727
text_->set_use_vertex_cache(is_vertex_cache_used_());
@@ -466,9 +466,9 @@ void font_string::update_borders_() {
466466
//#define DEBUG_LOG(msg) gui::out << (msg) << std::endl
467467
#define DEBUG_LOG(msg)
468468

469-
const bool old_ready = is_ready_;
469+
const bool old_valid = is_valid_;
470470
const auto old_border_list = borders_;
471-
is_ready_ = true;
471+
is_valid_ = true;
472472

473473
if (!anchor_list_.empty()) {
474474
float left = 0.0f, right = 0.0f, top = 0.0f, bottom = 0.0f;
@@ -501,14 +501,14 @@ void font_string::update_borders_() {
501501
box_width = text_->get_width();
502502

503503
if (!make_borders_(top, bottom, y_center, box_height)) {
504-
is_ready_ = false;
504+
is_valid_ = false;
505505
}
506506

507507
if (!make_borders_(left, right, x_center, box_width)) {
508-
is_ready_ = false;
508+
is_valid_ = false;
509509
}
510510

511-
if (is_ready_) {
511+
if (is_valid_) {
512512
if (right < left) {
513513
right = left + 1.0f;
514514
}
@@ -535,15 +535,15 @@ void font_string::update_borders_() {
535535
}
536536

537537
borders_ = bounds2f(0.0, 0.0, box_width, box_height);
538-
is_ready_ = false;
538+
is_valid_ = false;
539539
}
540540

541541
borders_.left = round_to_pixel(borders_.left);
542542
borders_.right = round_to_pixel(borders_.right);
543543
borders_.top = round_to_pixel(borders_.top);
544544
borders_.bottom = round_to_pixel(borders_.bottom);
545545

546-
if (borders_ != old_border_list || is_ready_ != old_ready) {
546+
if (borders_ != old_border_list || is_valid_ != old_valid) {
547547
DEBUG_LOG(" Fire redraw");
548548
notify_renderer_need_redraw();
549549
}

src/gui_frame.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ frame::~frame() {
6363
void frame::render() const {
6464
base::render();
6565

66-
if (!is_visible() || !is_ready_)
66+
if (!is_visible() || !is_valid_)
6767
return;
6868

6969
if (backdrop_) {
@@ -1500,14 +1500,14 @@ void frame::notify_mouse_in_frame(bool mouse_in_frame, const vector2f& /*positio
15001500
}
15011501

15021502
void frame::update_borders_() {
1503-
const bool old_ready = is_ready_;
1503+
const bool old_valid = is_valid_;
15041504
const auto old_border_list = borders_;
15051505

15061506
base::update_borders_();
15071507

15081508
check_position_();
15091509

1510-
if (borders_ != old_border_list || is_ready_ != old_ready) {
1510+
if (borders_ != old_border_list || is_valid_ != old_valid) {
15111511
if (borders_.width() != old_border_list.width() ||
15121512
borders_.height() != old_border_list.height()) {
15131513
alive_checker checker(*this);

src/gui_region.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ std::string region::serialize(const std::string& tab) const {
9292
std::ostringstream str;
9393

9494
str << tab << " # Name : " << name_ << " ("
95-
<< std::string(is_ready_ ? "ready" : "not ready")
95+
<< std::string(is_valid_ ? "valid" : "not valid")
9696
<< std::string(is_manually_inherited_ ? ", manually inherited" : "") << ")\n";
9797
str << tab << " # Raw name : " << raw_name_ << "\n";
9898
str << tab << " # Type : " << get_region_type() << "\n";
@@ -208,6 +208,10 @@ bool region::is_visible() const {
208208
return is_visible_;
209209
}
210210

211+
bool region::is_valid() const {
212+
return is_valid_;
213+
}
214+
211215
void region::set_dimensions(const vector2f& dimensions) {
212216
if (dimensions_ == dimensions)
213217
return;
@@ -668,10 +672,10 @@ void region::update_borders_() {
668672

669673
DEBUG_LOG(" Update anchors for " + lua_name_);
670674

671-
const bool old_is_ready = is_ready_;
675+
const bool old_is_ready = is_valid_;
672676
const auto old_border_list = borders_;
673677

674-
is_ready_ = true;
678+
is_valid_ = true;
675679

676680
if (!anchor_list_.empty()) {
677681
float left = 0.0f, right = 0.0f, top = 0.0f, bottom = 0.0f;
@@ -693,14 +697,14 @@ void region::update_borders_() {
693697

694698
DEBUG_LOG(" Make borders");
695699
if (!make_borders_(top, bottom, y_center, rounded_height)) {
696-
is_ready_ = false;
700+
is_valid_ = false;
697701
}
698702

699703
if (!make_borders_(left, right, x_center, rounded_width)) {
700-
is_ready_ = false;
704+
is_valid_ = false;
701705
}
702706

703-
if (is_ready_) {
707+
if (is_valid_) {
704708
if (right < left) {
705709
right = left + 1;
706710
}
@@ -714,7 +718,7 @@ void region::update_borders_() {
714718
}
715719
} else {
716720
borders_ = bounds2f(0.0, 0.0, dimensions_.x, dimensions_.y);
717-
is_ready_ = false;
721+
is_valid_ = false;
718722
}
719723

720724
DEBUG_LOG(" Final borders");
@@ -728,7 +732,7 @@ void region::update_borders_() {
728732
DEBUG_LOG(" top=" + utils::to_string(borders_.top));
729733
DEBUG_LOG(" bottom=" + utils::to_string(borders_.bottom));
730734

731-
if (borders_ != old_border_list || is_ready_ != old_is_ready) {
735+
if (borders_ != old_border_list || is_valid_ != old_is_ready) {
732736
DEBUG_LOG(" Fire redraw");
733737
notify_renderer_need_redraw();
734738
}
@@ -741,12 +745,12 @@ void region::notify_borders_need_update() {
741745
if (is_virtual())
742746
return;
743747

744-
const bool old_ready = is_ready_;
748+
const bool old_valid = is_valid_;
745749
const auto old_border_list = borders_;
746750

747751
update_borders_();
748752

749-
if (borders_ != old_border_list || is_ready_ != old_ready) {
753+
if (borders_ != old_border_list || is_valid_ != old_valid) {
750754
for (const auto& object : anchored_object_list_)
751755
object->notify_borders_need_update();
752756
}

src/gui_region_glues.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ void region::register_on_lua(sol::state& lua) {
261261
*/
262262
type.set_function("is_visible", member_function<&region::is_visible>());
263263

264+
/** @function is_valid
265+
*/
266+
type.set_function("is_valid", member_function<&region::is_valid>());
267+
264268
/** @function set_all_anchors
265269
*/
266270
type.set_function(

src/gui_text.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,7 @@ float get_string_width(const text& txt, const std::vector<item>& content) {
282282

283283
text::text(
284284
renderer& rdr, std::shared_ptr<const font> fnt, std::shared_ptr<const font> outline_font) :
285-
renderer_(rdr), font_(std::move(fnt)), outline_font_(std::move(outline_font)) {
286-
287-
if (!font_)
288-
return;
289-
290-
is_ready_ = true;
291-
}
285+
renderer_(rdr), font_(std::move(fnt)), outline_font_(std::move(outline_font)) {}
292286

293287
float text::get_line_height() const {
294288
if (font_)
@@ -400,7 +394,7 @@ float text::get_text_width() const {
400394
}
401395

402396
float text::get_text_height() const {
403-
if (!is_ready_)
397+
if (!font_)
404398
return 0.0f;
405399

406400
std::size_t count = std::count(unicode_text_.begin(), unicode_text_.end(), U'\n');
@@ -419,15 +413,15 @@ float text::get_string_width(const std::string& content) const {
419413
}
420414

421415
float text::get_string_width(const utils::ustring& content) const {
422-
if (!is_ready_)
416+
if (!font_)
423417
return 0.0f;
424418

425419
return parser::get_string_width(
426420
*this, parser::parse_string(renderer_, content, formatting_enabled_));
427421
}
428422

429423
float text::get_character_width(char32_t c) const {
430-
if (!is_ready_)
424+
if (!font_)
431425
return 0.0f;
432426
else if (c == U'\t')
433427
return 4.0f * font_->get_character_width(U' ') * scaling_factor_;
@@ -552,7 +546,7 @@ bool text::use_vertex_cache_() const {
552546
}
553547

554548
void text::render(const matrix4f& transform) const {
555-
if (!is_ready_ || unicode_text_.empty())
549+
if (!font_ || unicode_text_.empty())
556550
return;
557551

558552
update_();
@@ -624,7 +618,7 @@ float text::round_to_pixel_(float value, utils::rounding_method method) const {
624618
}
625619

626620
void text::update_() const {
627-
if (!is_ready_ || !update_cache_flag_)
621+
if (!font_ || !update_cache_flag_)
628622
return;
629623

630624
// Update the line list, read format tags, do word wrapping, ...

0 commit comments

Comments
 (0)