Prefer size property over struct field

This commit is contained in:
Mid 2025-09-19 23:11:03 +03:00
parent 05d0c75937
commit 0461199e64

View File

@ -254,7 +254,7 @@ static bool label_draw(struct k3MEvent *ev, uint8_t *ud) {
if(va != k3M_ALIGN_TOP) { if(va != k3M_ALIGN_TOP) {
struct k3RectF txtsz; struct k3RectF txtsz;
k3FontSz(this->font, this->sz, this->txt, this->w, &txtsz); k3FontSz(this->font, sz, this->txt, this->w, &txtsz);
if(va == k3M_ALIGN_CENTER) { if(va == k3M_ALIGN_CENTER) {
y += (this->h - txtsz.h) / 2; y += (this->h - txtsz.h) / 2;
} else if(va == k3M_ALIGN_BOTTOM) { } else if(va == k3M_ALIGN_BOTTOM) {
@ -271,8 +271,12 @@ static bool label_draw(struct k3MEvent *ev, uint8_t *ud) {
static bool label_measure(struct k3MEvent *ev, uint8_t *ud) { static bool label_measure(struct k3MEvent *ev, uint8_t *ud) {
struct k3MLabel *this = (void*) ev->target; struct k3MLabel *this = (void*) ev->target;
float sz = this->sz;
struct k3MProperty *prop = k3MFindProperty(this, k3M_PROP_FONT_SIZE, false);
if(prop) sz = prop->f[0];
struct k3RectF txtsz; struct k3RectF txtsz;
k3FontSz(this->font, this->sz, this->txt, -1, &txtsz); k3FontSz(this->font, sz, this->txt, -1, &txtsz);
this->w = ceilf(txtsz.w); this->w = ceilf(txtsz.w);
this->h = ceilf(txtsz.h); this->h = ceilf(txtsz.h);
@ -282,8 +286,12 @@ static bool label_measure(struct k3MEvent *ev, uint8_t *ud) {
static bool label_set_height_from_width(struct k3MEvent *ev, uint8_t *ud) { static bool label_set_height_from_width(struct k3MEvent *ev, uint8_t *ud) {
struct k3MLabel *this = (void*) ev->target; struct k3MLabel *this = (void*) ev->target;
float sz = this->sz;
struct k3MProperty *prop = k3MFindProperty(this, k3M_PROP_FONT_SIZE, false);
if(prop) sz = prop->f[0];
int16_t pxsz[2]; int16_t pxsz[2];
immdraw_font_size(this->font, this->sz, this->txt, this->w, pxsz); immdraw_font_size(this->font, sz, this->txt, this->w, pxsz);
this->h = pxsz[1]; this->h = pxsz[1];