@@ -19,14 +19,17 @@ namespace menu {
1919 // pointer to the string we should show
2020 const char *str;
2121
22+ // max length of the full range
23+ uint32_t max_length;
24+
2225 // range of the numeric popup
2326 klib::vector2i range;
2427 int32_t value;
2528
2629 public:
2730 numeric_popup ():
2831 next (nullptr ), cancel(nullptr ), str(nullptr ),
29- range{}, value(0 )
32+ max_length ( 0 ), range{}, value(0 )
3033 {}
3134
3235 /* *
@@ -47,6 +50,11 @@ namespace menu {
4750 this ->value = value;
4851 this ->range = {min, max};
4952
53+ this ->max_length = klib::max (
54+ klib::string::detail::count_chars (min),
55+ klib::string::detail::count_chars (max)
56+ );
57+
5058 // update the callbacks
5159 this ->next = next;
5260 this ->cancel = cancel;
@@ -108,29 +116,37 @@ namespace menu {
108116 // convert the number to a value
109117 klib::string::itoa (value, buffer);
110118
119+ // set the height to 40 pixels
120+ const int32_t h = 40 ;
121+
122+ // calculate the width. At least the same as the height
123+ const int32_t w = klib::max (h,
124+ ((max_length * screen_base::large_text::font::width) + 20 ) / 2
125+ );
126+
111127 // draw the rectangle arround the number
112128 screen_base::draw_rectangle (frame_buffer, klib::graphics::blue,
113- klib::vector2i{240 / 3 , (134 / 2 ) - 40 } - offset.cast <int32_t >(),
114- klib::vector2i{(240 / 3 ) * 2 , (134 / 2 ) + 40 } - offset.cast <int32_t >()
129+ klib::vector2i{( 240 / 2 ) - w , (134 / 2 ) - h } - offset.cast <int32_t >(),
130+ klib::vector2i{(240 / 2 ) + w , (134 / 2 ) + h } - offset.cast <int32_t >()
115131 );
116132
117133 // add 2 lines on both sides of the rectangle to round it a bit
118134 screen_base::draw_rectangle (frame_buffer, klib::graphics::blue,
119- klib::vector2i{240 / 3 - 1 , (134 / 2 ) - 39 } - offset.cast <int32_t >(),
120- klib::vector2i{(240 / 3 ) , (134 / 2 ) + 39 } - offset.cast <int32_t >()
135+ klib::vector2i{( 240 / 2 ) - (w - 1 ) , (134 / 2 ) - (h - 1 ) } - offset.cast <int32_t >(),
136+ klib::vector2i{(240 / 2 ) + w , (134 / 2 ) + (h - 1 ) } - offset.cast <int32_t >()
121137 );
122138 screen_base::draw_rectangle (frame_buffer, klib::graphics::blue,
123- klib::vector2i{240 / 3 - 2 , (134 / 2 ) - 38 } - offset.cast <int32_t >(),
124- klib::vector2i{(240 / 3 ) - 1 , (134 / 2 ) + 38 } - offset.cast <int32_t >()
139+ klib::vector2i{( 240 / 2 ) - (w - 2 ) , (134 / 2 ) - (h - 2 ) } - offset.cast <int32_t >(),
140+ klib::vector2i{(240 / 2 ) + (w - 1 ) , (134 / 2 ) + (h - 2 ) } - offset.cast <int32_t >()
125141 );
126142
127143 screen_base::draw_rectangle (frame_buffer, klib::graphics::blue,
128- klib::vector2i{(( 240 / 3 ) * 2 ) , (134 / 2 ) - 39 } - offset.cast <int32_t >(),
129- klib::vector2i{(( 240 / 3 ) * 2 ) + 1 , (134 / 2 ) + 39 } - offset.cast <int32_t >()
144+ klib::vector2i{(240 / 2 ) - w , (134 / 2 ) - (h - 1 ) } - offset.cast <int32_t >(),
145+ klib::vector2i{(240 / 2 ) + (w + 1 ) , (134 / 2 ) + (h - 1 ) } - offset.cast <int32_t >()
130146 );
131147 screen_base::draw_rectangle (frame_buffer, klib::graphics::blue,
132- klib::vector2i{(( 240 / 3 ) * 2 ) + 1 , (134 / 2 ) - 38 } - offset.cast <int32_t >(),
133- klib::vector2i{(( 240 / 3 ) * 2 ) + 2 , (134 / 2 ) + 38 } - offset.cast <int32_t >()
148+ klib::vector2i{(240 / 2 ) - (w + 1 ) , (134 / 2 ) - (h - 2 ) } - offset.cast <int32_t >(),
149+ klib::vector2i{(240 / 2 ) + (w + 2 ) , (134 / 2 ) + (h - 2 ) } - offset.cast <int32_t >()
134150 );
135151
136152 // draw the bigmaps of the arrows
0 commit comments