mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat(ui): add item slot tooltip and make window size static
This commit is contained in:
@@ -12,4 +12,7 @@ enum class Anchor {
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_CENTER,
|
||||
BOTTOM_RIGHT,
|
||||
|
||||
FOLLOW_MOUSE
|
||||
|
||||
};
|
||||
@@ -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
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user