Skip to content

Commit

Permalink
[fix] button min-size
Browse files Browse the repository at this point in the history
  • Loading branch information
MrsRina committed Oct 24, 2024
1 parent 79b1801 commit 3484679
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
5 changes: 3 additions & 2 deletions include/ekg/ui/abstract/ui_abstract_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
} \

/**
* `self->`p_data->get_layer(layer)
* the reason for `self->` be removed, due some widgets like:
* `this->`p_data->get_layer(layer)
* the reason for `this->` be removed, due some widgets like:
* listbox which perform recursive iterations.
**/
#define ekg_layer(layer) (p_data->get_layer(layer))
Expand All @@ -65,6 +65,7 @@ namespace ekg::ui {
bool is_high_frequency {};
bool is_targeting_absolute_parent {};
bool is_just_created {};
bool is_dimension_auto_update_required {true};
public:
bool was_reloaded {};
bool was_refreshed {};
Expand Down
20 changes: 13 additions & 7 deletions src/ui/button/ui_button_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ void ekg::ui::button_widget::on_reload() {
float dimension_offset {static_cast<float>((int32_t) (text_height / 2.0f))};
float offset {ekg::find_min_offset(text_width, dimension_offset)};

this->dimension.w = ekg_min(this->dimension.w, text_width);
this->dimension.h = (text_height + dimension_offset) * static_cast<float>(p_ui->get_scaled_height());
if (this->is_dimension_auto_update_required) {
this->dimension.w = ekg_min(this->dimension.w, text_width);
this->dimension.h = (text_height + dimension_offset) * static_cast<float>(p_ui->get_scaled_height());

this->min_size.x = ekg_min(this->min_size.x, text_height);
this->min_size.y = ekg_min(this->min_size.y, this->dimension.h);
this->min_size.x = ekg_min(this->min_size.x, text_height);
this->min_size.y = ekg_min(this->min_size.y, this->dimension.h);
}

this->rect_text.w = text_width;
this->rect_text.h = text_height;
Expand All @@ -54,9 +56,13 @@ void ekg::ui::button_widget::on_reload() {
mask.insert({&this->rect_text, p_ui->get_text_align()});
mask.docknize();

ekg::rect &layout_mask {mask.get_rect()};
this->dimension.w = ekg_min(this->dimension.w, layout_mask.w);
this->dimension.h = ekg_min(this->dimension.h, layout_mask.h);
if (this->is_dimension_auto_update_required) {
ekg::rect &layout_mask {mask.get_rect()};
this->dimension.w = ekg_min(this->dimension.w, layout_mask.w);
this->dimension.h = ekg_min(this->dimension.h, layout_mask.h);
}

this->is_dimension_auto_update_required = false;
}

void ekg::ui::button_widget::on_event(ekg::os::io_event_serial &io_event_serial) {
Expand Down
9 changes: 4 additions & 5 deletions test/src/ekg_gui_showcase_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,12 +1220,13 @@ int32_t laboratory_testing() {
->set_resize(ekg::dock::left | ekg::dock::right | ekg::dock::bottom);

ekg::button("1", ekg::dock::fill);
ekg::button("2", ekg::dock::fill);
ekg::button("2", ekg::dock::none);
ekg::button("3", ekg::dock::fill);
ekg::button("1", ekg::dock::next | ekg::dock::fill);
ekg::button("4", ekg::dock::fill);
ekg::button("4", ekg::dock::none);
ekg::button("oi eu amo 🐄(s), 🐈(s), 🥞(s), e s-in-the-⬛", ekg::dock::fill);
ekg::button("3", ekg::dock::fill | ekg::dock::right);
ekg::button("Exit", ekg::dock::fill | ekg::dock::next)
ekg::button("Exit", ekg::dock::right | ekg::dock::bottom)
->set_width(60.0f)
->set_task(
new ekg::task {
Expand All @@ -1243,8 +1244,6 @@ int32_t laboratory_testing() {
ekg::action::activity
);

ekg::button("oi eu amo 🐄(s), 🐈(s), 🥞(s), e s-in-the-⬛", ekg::dock::right | ekg::dock::bottom | ekg::dock::fill);

ekg::pop_group();
ekg::vec3 clear_color {};

Expand Down

0 comments on commit 3484679

Please sign in to comment.