mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
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:
@@ -63,6 +63,7 @@ bool Button::handle_mouse_button_event(const MouseButtonEvent& e) {
|
||||
Button& Button::set_scale(float scale) {
|
||||
m_scale = scale;
|
||||
update_text_scale();
|
||||
update_border();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ ChatBox& ChatBox::set_scale(float scale) {
|
||||
if (m_text_field) {
|
||||
m_text_field->set_scale(scale);
|
||||
}
|
||||
|
||||
update_border();
|
||||
return *this;
|
||||
}
|
||||
ChatBox& ChatBox::set_text_scale(float scale) {
|
||||
|
||||
@@ -46,6 +46,7 @@ Image& Image::set_texture(const Texture* texture, bool change_size) {
|
||||
|
||||
Image& Image::set_scale(float scale) {
|
||||
m_scale = scale;
|
||||
update_border();
|
||||
return *this;
|
||||
}
|
||||
float Image::scale() const { return m_scale; }
|
||||
@@ -68,7 +69,7 @@ float Image::width() const {
|
||||
if (m_fill_parent || m_fill_width) {
|
||||
return Widget::width();
|
||||
}
|
||||
return Widget::height() * m_scale;
|
||||
return Widget::width() * m_scale;
|
||||
}
|
||||
|
||||
const Texture* Image::texture() const { return m_texture; }
|
||||
|
||||
@@ -15,6 +15,7 @@ Label& Label::set_color(Color color) {
|
||||
}
|
||||
Label& Label::set_scale(float scale) {
|
||||
m_scale = scale;
|
||||
update_border();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ void TextField::update_input_area() {
|
||||
TextField& TextField::set_scale(float scale) {
|
||||
m_scale = scale;
|
||||
m_cursor->set_height(std::max(1.0f, height() - DELTA_CUROUR_HEIGHT));
|
||||
|
||||
update_border();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -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::update_border() {
|
||||
if (!supports_border()) {
|
||||
return;
|
||||
}
|
||||
auto w = width();
|
||||
auto h = height();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user