Add Window::DragTo()
This commit is contained in:
@@ -77,6 +77,7 @@ namespace JUI {
|
||||
/// @see class Draggable.
|
||||
bool IsDraggable() const;
|
||||
|
||||
/// Sets the window to have the ability to be dragged around by the mouse.
|
||||
void SetDraggable(bool value);
|
||||
|
||||
/// Returns whether this Window is able to be 'Docked' into another widget.
|
||||
@@ -126,7 +127,6 @@ namespace JUI {
|
||||
/// @see class Clickable.
|
||||
void OnRelease(const Vector2& m_pos, const MouseButton& m_btn, bool still_hovering) override;
|
||||
|
||||
|
||||
/// @see class Hoverable.
|
||||
void OnHover(const J3ML::LinearAlgebra::Vector2 &MousePos) override
|
||||
{
|
||||
@@ -150,11 +150,11 @@ namespace JUI {
|
||||
void UpdateInternalWidgetsTitlebarHeight();
|
||||
protected:
|
||||
|
||||
JUI::Rect* Topbar;
|
||||
JUI::Rect* Viewport;
|
||||
JUI::Text* TitleLabel;
|
||||
JUI::ImageButton* exit_btn;
|
||||
JUI::ImageButton* fs_btn;
|
||||
JUI::Rect* Topbar = nullptr;
|
||||
JUI::Rect* Viewport = nullptr;
|
||||
JUI::Text* TitleLabel = nullptr;
|
||||
JUI::ImageButton* exit_btn = nullptr;
|
||||
JUI::ImageButton* fs_btn = nullptr;
|
||||
std::string title = "JUI Window";
|
||||
bool resizable = true;
|
||||
bool focused = false;
|
||||
@@ -163,8 +163,10 @@ namespace JUI {
|
||||
bool dockable = false;
|
||||
int titlebar_height = Style::Window::TitlebarHeight;
|
||||
int title_font_size = 16;
|
||||
Vector2 max_size;
|
||||
Vector2 min_size; //= {30, 30};
|
||||
Vector2 max_size = {800, 600};
|
||||
Vector2 min_size = {200, 100}; //= {30, 30};
|
||||
UDim2 size_when_restart_began;
|
||||
|
||||
void DragTo(const Vector2 &pos);
|
||||
};
|
||||
}
|
||||
|
@@ -154,11 +154,19 @@ namespace JUI {
|
||||
this->SetResize(false);
|
||||
}
|
||||
|
||||
|
||||
void Window::DragTo(const Vector2& pos)
|
||||
{
|
||||
this->Position(UDim2{(int) pos.x, (int) pos.y, 0, 0});
|
||||
}
|
||||
|
||||
void Window::Update(float delta) {
|
||||
|
||||
|
||||
if (dragging) {
|
||||
//jlog::Debug(std::format("mpos {} {}", last_known_mouse_pos.x, last_known_mouse_pos.y));
|
||||
Vector2 mpos = last_known_mouse_pos - initial_drag_offset;
|
||||
this->Position(UDim2{(int) mpos.x, (int) mpos.y, 0, 0});
|
||||
// Move the window with the mouse, accounting for initial offset of window-mouse when we first clicked.
|
||||
Vector2 goal = last_known_mouse_pos - initial_drag_offset;
|
||||
DragTo(goal);
|
||||
}
|
||||
|
||||
if (resizing) {
|
||||
@@ -183,7 +191,6 @@ namespace JUI {
|
||||
float needed_amt_to_resize = min_size.y - abs_size.y;
|
||||
Size(Size() + UDim2(0, needed_amt_to_resize, 0, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Widget::Update(delta);
|
||||
|
Reference in New Issue
Block a user