feat(ui): add item slot tooltip and make window size static

This commit is contained in:
2026-07-21 19:51:04 +08:00
parent 68f7924f07
commit 234746babb
16 changed files with 73 additions and 34 deletions

View File

@@ -12,4 +12,7 @@ enum class Anchor {
BOTTOM_LEFT,
BOTTOM_CENTER,
BOTTOM_RIGHT,
FOLLOW_MOUSE
};

View File

@@ -2,6 +2,7 @@
#include "Cubed/gameplay/block.hpp"
#include "Cubed/ui/image.hpp"
#include "Cubed/ui/label.hpp"
#include "Cubed/ui/widget.hpp"
namespace Cubed {
class TextureManager;
@@ -21,9 +22,13 @@ private:
static constexpr const char* DEFAULT_SLOT_PATH = "texture/ui/slot.png";
void on_render(Renderer& renderer) override;
void on_update(float dt) override;
bool handle_mouse_move_event(const MouseMoveEvent& e) override;
bool handle_window_resize_event(const WindowResizeEvent& e) override;
std::unique_ptr<Image> m_background;
std::unique_ptr<Image> m_foreground;
std::unique_ptr<Label> m_label;
BlockType m_block_type;
float m_scale = 1.0f;
bool m_hovered = false;
};
} // namespace Cubed

View File

@@ -31,7 +31,7 @@ public:
virtual void render(Renderer& renderer);
virtual Widget& set_anchor(Anchor anchor);
virtual Widget& set_offset(glm::ivec2 offset);
virtual Widget& set_window_size(int width, int height);
static void set_window_size(int width, int height);
virtual Widget& set_visible(bool visible);
// Returns the final display size
@@ -65,8 +65,8 @@ public:
protected:
Widget* m_parent = nullptr;
float m_window_height = 0.0f;
float m_window_width = 0.0f;
static inline float m_window_height = 0.0f;
static inline float m_window_width = 0.0f;
// Center is at the top-left corner, position is at the top-left corner
Anchor m_anchor = Anchor::TOP_LEFT;
@@ -99,6 +99,7 @@ private:
*/
std::array<std::unique_ptr<Widget>, 4> m_border;
TraversalOrder m_order = TraversalOrder::BACK_TO_FRONT;
glm::vec2 m_mouse_pos;
float m_width = 0.0f;
float m_height = 0.0f;
};