[Fix] Created get_text_width for menu button centering.
This commit is contained in:
		
							parent
							
								
									666b4f554b
								
							
						
					
					
						commit
						30ae57d0ba
					
				@ -116,3 +116,11 @@ void TextRenderer::render_text(const char* text, float x, float y, float scale,
 | 
			
		||||
  glBindVertexArray(0);
 | 
			
		||||
  glBindTexture(GL_TEXTURE_2D, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float TextRenderer::get_text_width(const char* text, float scale) {
 | 
			
		||||
  float width = 0.0f;
 | 
			
		||||
  for(const char* p = text; *p; p++) {
 | 
			
		||||
    width += (_chars[*p].advance >> 6) * scale;
 | 
			
		||||
  }
 | 
			
		||||
  return width;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -22,6 +22,8 @@ public:
 | 
			
		||||
 | 
			
		||||
  void load_font(const char* font_path, unsigned int font_size);
 | 
			
		||||
  void render_text(const char* text, float x, float y, float scale, const Color& color);
 | 
			
		||||
  float get_text_width(const char* text, float scale);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
  Shader* _txt_shader;
 | 
			
		||||
 | 
			
		||||
@ -113,11 +113,10 @@ void MainMenu::render(ShapeRenderer* shape_renderer, TextRenderer* txt_renderer)
 | 
			
		||||
                                button.rect.h, button_color);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * Draw button text centered.
 | 
			
		||||
     * TODO: Calculate text width for perfect centering.
 | 
			
		||||
     */
 | 
			
		||||
    txt_renderer->render_text(button.label.c_str(), button.rect.x + 50,
 | 
			
		||||
    /* Draw button text centered. */
 | 
			
		||||
    float text_width = txt_renderer->get_text_width(button.label.c_str(), 1.0f);
 | 
			
		||||
    float text_x = button.rect.x + (button.rect.w - text_width) / 2.0f;
 | 
			
		||||
    txt_renderer->render_text(button.label.c_str(), text_x,
 | 
			
		||||
                              button.rect.y + 18, 1.0f, text_color);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,6 @@ public:
 | 
			
		||||
      vfs_root(nullptr),
 | 
			
		||||
      is_vfs_a_copy(false) {}
 | 
			
		||||
 | 
			
		||||
  /* TODO: Implement recursive deletion of vfs_root. */
 | 
			
		||||
  ~Machine(void); /* Clean up VFS tree. */
 | 
			
		||||
 | 
			
		||||
  uint32_t id;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user