fix(ui): update borders on scale change and correct Image width

- Added update_border() calls in set_scale() for Button, ChatBox, Image, Label, and TextField.
- Fixed Image::width() to multiply by width instead of height.
- Added early return in Widget::update_border() if border is not supported.
This commit is contained in:
2026-07-21 16:09:13 +08:00
parent 4c9d69b0cd
commit 666fe873f5
6 changed files with 9 additions and 3 deletions

View File

@@ -63,6 +63,7 @@ bool Button::handle_mouse_button_event(const MouseButtonEvent& e) {
Button& Button::set_scale(float scale) { Button& Button::set_scale(float scale) {
m_scale = scale; m_scale = scale;
update_text_scale(); update_text_scale();
update_border();
return *this; return *this;
} }

View File

@@ -37,7 +37,7 @@ ChatBox& ChatBox::set_scale(float scale) {
if (m_text_field) { if (m_text_field) {
m_text_field->set_scale(scale); m_text_field->set_scale(scale);
} }
update_border();
return *this; return *this;
} }
ChatBox& ChatBox::set_text_scale(float scale) { ChatBox& ChatBox::set_text_scale(float scale) {

View File

@@ -46,6 +46,7 @@ Image& Image::set_texture(const Texture* texture, bool change_size) {
Image& Image::set_scale(float scale) { Image& Image::set_scale(float scale) {
m_scale = scale; m_scale = scale;
update_border();
return *this; return *this;
} }
float Image::scale() const { return m_scale; } float Image::scale() const { return m_scale; }
@@ -68,7 +69,7 @@ float Image::width() const {
if (m_fill_parent || m_fill_width) { if (m_fill_parent || m_fill_width) {
return Widget::width(); return Widget::width();
} }
return Widget::height() * m_scale; return Widget::width() * m_scale;
} }
const Texture* Image::texture() const { return m_texture; } const Texture* Image::texture() const { return m_texture; }

View File

@@ -15,6 +15,7 @@ Label& Label::set_color(Color color) {
} }
Label& Label::set_scale(float scale) { Label& Label::set_scale(float scale) {
m_scale = scale; m_scale = scale;
update_border();
return *this; return *this;
} }

View File

@@ -107,7 +107,7 @@ void TextField::update_input_area() {
TextField& TextField::set_scale(float scale) { TextField& TextField::set_scale(float scale) {
m_scale = scale; m_scale = scale;
m_cursor->set_height(std::max(1.0f, height() - DELTA_CUROUR_HEIGHT)); m_cursor->set_height(std::max(1.0f, height() - DELTA_CUROUR_HEIGHT));
update_border();
return *this; return *this;
} }

View File

@@ -121,6 +121,9 @@ void Widget::set_width_internal(float width) { m_width = width; }
void Widget::set_height_internal(float height) { m_height = height; } void Widget::set_height_internal(float height) { m_height = height; }
void Widget::update_border() { void Widget::update_border() {
if (!supports_border()) {
return;
}
auto w = width(); auto w = width();
auto h = height(); auto h = height();
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {