From 2789d249361b4fdbb71abaadb61fdedd97d0d3a8 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 27 Nov 2024 15:59:39 -0600 Subject: [PATCH] properly measure scenario editor button clickable labels --- src/scenedit/scen.graphics.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/scenedit/scen.graphics.cpp b/src/scenedit/scen.graphics.cpp index 99888dacb..ab6453beb 100644 --- a/src/scenedit/scen.graphics.cpp +++ b/src/scenedit/scen.graphics.cpp @@ -443,6 +443,8 @@ void draw_lb() { draw_lb_slot(i,0); } +const int LEFT_BUTTON_SPACE = 2; + // mode 0 normal 1 click void draw_lb_slot (short which,short mode) { rectangle text_rect,from_rect; @@ -450,9 +452,12 @@ void draw_lb_slot (short which,short mode) { tileImage(mainPtr,left_buttons[which][0],bg[20]); if(left_button_status[which].mode == LB_CLEAR) return; + + int button_width = blue_button_from.width(); + text_rect = left_buttons[which][0]; if(left_button_status[which].action != LB_NO_ACTION) { - text_rect.left += 18; + text_rect.left += button_width + LEFT_BUTTON_SPACE; from_rect = blue_button_from; if(mode > 0) from_rect.offset(0,from_rect.height()); @@ -468,6 +473,13 @@ void draw_lb_slot (short which,short mode) { if(mode > 0) style.colour = Colours::BLUE; style.lineHeight = 12; + + // Arbitrary extra space on the right prevents labels from being forced to line wrap + text_rect.right += 10; + + // Measure the button's clickable width including the label + left_buttons[which][0].width() = button_width + LEFT_BUTTON_SPACE + string_length(left_button_status[which].label, style); + win_draw_string(mainPtr,text_rect,left_button_status[which].label,eTextMode::WRAP,style); }