Fix integer division & uninitialized alignment
This commit is contained in:
		@ -8,6 +8,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
enum class Alignment { LEFT, RIGHT, CENTER };
 | 
					enum class Alignment { LEFT, RIGHT, CENTER };
 | 
				
			||||||
struct PositionInfo {
 | 
					struct PositionInfo {
 | 
				
			||||||
 | 
					  PositionInfo();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  int x;
 | 
					  int x;
 | 
				
			||||||
  int y;
 | 
					  int y;
 | 
				
			||||||
  Alignment align;
 | 
					  Alignment align;
 | 
				
			||||||
 | 
				
			|||||||
@ -7,13 +7,15 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <stdexcept>
 | 
					#include <stdexcept>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PositionInfo::PositionInfo() : x{0}, y{0}, align{Alignment::LEFT} {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Widget::Widget(SDL_Renderer* renderer) : renderer{renderer}, rect{0, 0, 0, 0} {}
 | 
					Widget::Widget(SDL_Renderer* renderer) : renderer{renderer}, rect{0, 0, 0, 0} {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Widget::~Widget() {}
 | 
					Widget::~Widget() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Widget::set_width(int width, bool preserve_aspect_ratio) {
 | 
					void Widget::set_width(int width, bool preserve_aspect_ratio) {
 | 
				
			||||||
  if (preserve_aspect_ratio) {
 | 
					  if (preserve_aspect_ratio) {
 | 
				
			||||||
    float scale = width / rect.w;
 | 
					    float scale = ((float)width) / rect.w;
 | 
				
			||||||
    rect.h = round(rect.h * scale);
 | 
					    rect.h = round(rect.h * scale);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  rect.w = width;
 | 
					  rect.w = width;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user