mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-17 10:12:12 +00:00
Fix width weirdness with add_overlay_text
Closes #9633 Fixes #9591 This could also have been fixed by simply adjust the clip rect origin on left alignment (such an adjustment was present for the other alignments), but honestly there's no reason to be messing with the clip rect here when we can set the width directly. The floating_label internals would set the maximum text width to clip rect if no max with was otherwise specified.
This commit is contained in:
parent
e8da69fe63
commit
8ee2a26634
|
@ -2658,7 +2658,7 @@ int game_lua_kernel::intf_set_floating_label(lua_State* L, bool spawn)
|
|||
font::remove_floating_label(*handle);
|
||||
}
|
||||
|
||||
SDL_Rect rect = game_display_->map_outside_area();
|
||||
const SDL_Rect rect = game_display_->map_outside_area();
|
||||
if(width_ratio > 0) {
|
||||
width = static_cast<int>(std::round(rect.w * width_ratio));
|
||||
}
|
||||
|
@ -2666,23 +2666,12 @@ int game_lua_kernel::intf_set_floating_label(lua_State* L, bool spawn)
|
|||
switch(alignment) {
|
||||
case font::ALIGN::LEFT_ALIGN:
|
||||
x = rect.x + loc.wml_x();
|
||||
if(width > 0) {
|
||||
rect.w = std::min(rect.w, width);
|
||||
}
|
||||
break;
|
||||
case font::ALIGN::CENTER_ALIGN:
|
||||
x = rect.x + rect.w / 2 + loc.wml_x();
|
||||
if(width > 0) {
|
||||
rect.w = std::min(rect.w, width);
|
||||
rect.x = x - rect.w / 2;
|
||||
}
|
||||
break;
|
||||
case font::ALIGN::RIGHT_ALIGN:
|
||||
x = rect.x + rect.w - loc.wml_x();
|
||||
if(width > 0) {
|
||||
rect.x = (rect.x + rect.w) - std::min(rect.w, width);
|
||||
rect.w = std::min(rect.w, width);
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch(vertical_alignment) {
|
||||
|
@ -2711,6 +2700,13 @@ int game_lua_kernel::intf_set_floating_label(lua_State* L, bool spawn)
|
|||
flabel.set_lifetime(milliseconds{lifetime}, milliseconds{fadeout});
|
||||
flabel.set_clip_rect(rect);
|
||||
|
||||
// Adjust fallback width (map area) to avoid text escaping when location != 0
|
||||
if(width > 0) {
|
||||
flabel.set_width(std::min(width, rect.w - loc.wml_x()));
|
||||
} else {
|
||||
flabel.set_width(rect.w - loc.wml_x());
|
||||
}
|
||||
|
||||
*handle = font::add_floating_label(flabel);
|
||||
lua_settop(L, handle_idx);
|
||||
if(luaL_newmetatable(L, labelKey)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user