Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将对象内的文本居中,并根据对象的宽度和高度调整大小_C++_Math - Fatal编程技术网

C++ 将对象内的文本居中,并根据对象的宽度和高度调整大小

C++ 将对象内的文本居中,并根据对象的宽度和高度调整大小,c++,math,C++,Math,我有一个矩形对象,显示的宽度为50,高度为100 我有一个文本标签,我想在屏幕上的矩形内居中并调整其大小 根据文本大小,文本范围从0-100+到矩形大小 下面是我正在做的: int rectangle_width = 50; int rectangle_height = 100; // i'm calculating the center of the rectangle text_x_positon = rectangle_width/2; text_y_positon = rec

我有一个矩形对象,显示的宽度为50,高度为100

我有一个文本标签,我想在屏幕上的矩形内居中并调整其大小

根据文本大小,文本范围从0-100+到矩形大小

下面是我正在做的:

int rectangle_width = 50;

int rectangle_height = 100;

// i'm calculating the center of the rectangle 


text_x_positon = rectangle_width/2;

text_y_positon = rectangle_height/2;

// calculating the size of the text label according to rectangle free space

int size = (rectangle_width/rectangle_height)*10;

label(text_x_positon, text_y_positon, size);

问题是,有时文本比矩形小或大,请帮助我解决这个问题,并告诉我正确的方法。

尝试使用text\u x\u position=rectangle\u width/2-text\u width/2完成此操作的坦克