mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
feat(ui): add lightbox viewer for screenshots
Add a lightbox to preview screenshots on click. Introduce Button::set_texture for image-backed buttons, add widget getters for window size and visibility, and block background input while the lightbox is open. Close the lightbox with Escape or a left-click.
This commit is contained in:
@@ -28,6 +28,7 @@ public:
|
||||
Button& set_background_image(const std::string& path,
|
||||
TextureManager& texture_manager);
|
||||
Button& set_default_image(TextureManager& texture_manager);
|
||||
Button& set_texture(const Texture* texture, bool change_button_size);
|
||||
virtual Button& set_text(const std::string& text);
|
||||
|
||||
Button& set_auto_scale(bool auto_scale);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/ui/image.hpp"
|
||||
#include "Cubed/ui/ui_manager.hpp"
|
||||
namespace Cubed {
|
||||
class Texture;
|
||||
class ScreenshotScene;
|
||||
class ScreenshotUI : public UIManager {
|
||||
public:
|
||||
@@ -17,9 +19,23 @@ public:
|
||||
|
||||
void update_layout(int width, int height);
|
||||
|
||||
void open_lightbox(const Texture* image);
|
||||
|
||||
private:
|
||||
bool handle_window_resize_event(const WindowResizeEvent& e) override;
|
||||
struct ImageInfo {
|
||||
const Texture* texture = nullptr;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
};
|
||||
|
||||
ScreenshotScene& m_scene;
|
||||
std::vector<ImageInfo> m_image_infos;
|
||||
Widget* m_lightbox = nullptr;
|
||||
Image* m_lightbox_image = nullptr;
|
||||
bool handle_window_resize_event(const WindowResizeEvent& e) override;
|
||||
bool handle_key_event(const KeyEvent& e) override;
|
||||
bool handle_mouse_button_event(const MouseButtonEvent& e) override;
|
||||
bool handle_mouse_move_event(const MouseMoveEvent& e) override;
|
||||
bool handle_mouse_wheel_event(const MouseWheelEvent& e) override;
|
||||
};
|
||||
} // namespace Cubed
|
||||
@@ -28,6 +28,11 @@ public:
|
||||
Widget& operator=(Widget&&) = delete;
|
||||
|
||||
Widget(Widget* parent);
|
||||
|
||||
static void set_window_size(int width, int height);
|
||||
static int get_window_height();
|
||||
static int get_window_width();
|
||||
|
||||
virtual ~Widget() = default;
|
||||
virtual void update(float dt);
|
||||
virtual void render(Renderer& renderer);
|
||||
@@ -35,7 +40,7 @@ public:
|
||||
virtual Widget& set_offset(glm::vec2 offset);
|
||||
virtual Widget& add_offset(glm::vec2 offset);
|
||||
virtual glm::vec2 get_offset() const;
|
||||
static void set_window_size(int width, int height);
|
||||
|
||||
virtual Widget& set_visible(bool visible);
|
||||
// Returns the final display size
|
||||
|
||||
@@ -58,6 +63,8 @@ public:
|
||||
virtual bool handle_window_resize_event(const WindowResizeEvent& e);
|
||||
virtual bool handle_mouse_move_event(const MouseMoveEvent& e);
|
||||
virtual bool handle_text_input_event(const TextInputEvent& e);
|
||||
|
||||
virtual bool is_visible() const;
|
||||
void set_order(TraversalOrder order);
|
||||
|
||||
template <typename T, typename... Args> T& add_child(Args&&... args) {
|
||||
|
||||
Reference in New Issue
Block a user