mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat(ui): add auto-scaling option for button and slider text
This commit is contained in:
@@ -30,6 +30,8 @@ public:
|
||||
Button& set_default_image(TextureManager& texture_manager);
|
||||
Button& set_text(const std::string& text);
|
||||
|
||||
Button& set_auto_scale(bool auto_scale);
|
||||
|
||||
float scale() const;
|
||||
template <typename F> Button& set_clicked(F&& f) {
|
||||
m_clicked = std::forward<F>(f);
|
||||
@@ -39,6 +41,8 @@ public:
|
||||
private:
|
||||
static constexpr float PADDING = 5.0f;
|
||||
static constexpr float DEFAULT_SCALE = 3.0f;
|
||||
static constexpr float TEXT_SCALE = 0.6f;
|
||||
|
||||
static constexpr const char* DEFAULT_BUTTON_IMAGE =
|
||||
"texture/ui/button001.png";
|
||||
std::function<void()> m_clicked;
|
||||
@@ -48,6 +52,7 @@ private:
|
||||
float m_width = NORMAL_BUTTON_WIDTH;
|
||||
float m_height = NORMAL_BUTTON_HEIGHT;
|
||||
float m_scale = DEFAULT_SCALE;
|
||||
bool m_auto_scale = false;
|
||||
void on_render(Renderer& renderer) override;
|
||||
void on_update(float dt) override;
|
||||
void update_text_scale();
|
||||
|
||||
@@ -30,12 +30,13 @@ public:
|
||||
TextureManager& texture_manager);
|
||||
|
||||
Slider& set_default_image(TextureManager& texture_manager);
|
||||
|
||||
Slider& set_auto_scale(bool auto_scale);
|
||||
bool handle_mouse_move_event(const MouseMoveEvent& e) override;
|
||||
bool handle_mouse_button_event(const MouseButtonEvent& e) override;
|
||||
|
||||
private:
|
||||
static constexpr float PADDING = 5.0f;
|
||||
static constexpr float TEXT_SCALE = 0.6f;
|
||||
static constexpr float DEFAULT_SCALE = 3.0f;
|
||||
static constexpr const char* DEFAULT_TRACK_IMAGE =
|
||||
"texture/ui/slider_track001.png";
|
||||
@@ -51,6 +52,7 @@ private:
|
||||
float m_xpos = 0.0f;
|
||||
bool m_dragging = false;
|
||||
bool m_inside = false;
|
||||
bool m_auto_scale = false;
|
||||
float* m_float_value = nullptr;
|
||||
int* m_int_value = nullptr;
|
||||
float m_min = 0;
|
||||
|
||||
Reference in New Issue
Block a user