mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Add scrollpanel widget
This PR introduces a new ScrollPanel component with the following capabilities: - Scroll Orientation Support: Allows scrolling in horizontal, vertical, or both directions, providing flexibility for different use cases. - Partial Object Rendering: Supports partial rendering of objects that are only partially visible within the scroll boundaries, improving visual accuracy and performance. - Boundary-Constrained Mouse Interaction: Handles mouse events strictly within the panel's visible boundaries, preventing interaction with objects outside the scrollable area. - Minimum Internal Size (min_width, min_height): Introduces support for virtual space management, allowing the panel to maintain a minimum internal size independent of its actual on-screen dimensions. Even when the panel is resized, this ensures that the content respects a defined virtual space (with min_width and min_height), effectively simulating a larger internal canvas. This is particularly useful for large content or scenarios where a more extensive scrollable area is required than the current visible panel.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "gui/ObjectBases/IGUIObject.h"
|
||||
#include "gui/SettingTypes/EScrollOrientation.h"
|
||||
#include "gui/SettingTypes/CGUIColor.h"
|
||||
#include "gui/SettingTypes/CGUIList.h"
|
||||
#include "gui/SettingTypes/CGUISeries.h"
|
||||
@@ -310,6 +311,49 @@ template<> bool Script::FromJSVal<EAlign>(const ScriptRequest& rq, JS::HandleVal
|
||||
return true;
|
||||
}
|
||||
|
||||
template<> void Script::ToJSVal<EScrollOrientation>(const ScriptRequest& rq, JS::MutableHandleValue ret, const EScrollOrientation& val)
|
||||
{
|
||||
std::string word;
|
||||
switch (val)
|
||||
{
|
||||
case EScrollOrientation::HORIZONTAL:
|
||||
word = "horizontal";
|
||||
break;
|
||||
case EScrollOrientation::VERTICAL:
|
||||
word = "vertical";
|
||||
break;
|
||||
case EScrollOrientation::BOTH:
|
||||
word = "both";
|
||||
break;
|
||||
default:
|
||||
word = "error";
|
||||
ScriptException::Raise(rq, "Invalid scroll orientation (should be 'vertical', 'horizontal' or 'both')");
|
||||
break;
|
||||
}
|
||||
ToJSVal(rq, ret, word);
|
||||
}
|
||||
|
||||
template <> bool Script::FromJSVal<EScrollOrientation>(const ScriptRequest& rq, JS::HandleValue v, EScrollOrientation& out)
|
||||
{
|
||||
std::string word;
|
||||
FromJSVal(rq, v, word);
|
||||
|
||||
if (word == "horizontal")
|
||||
out = EScrollOrientation::HORIZONTAL;
|
||||
else if (word == "vertical")
|
||||
out = EScrollOrientation::VERTICAL;
|
||||
else if (word == "both")
|
||||
out = EScrollOrientation::BOTH;
|
||||
else
|
||||
{
|
||||
out = EScrollOrientation::VERTICAL;
|
||||
LOGERROR("Invalid scroll orientation (should be 'vertical', 'horizontal' or 'both')");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<> void Script::ToJSVal<CGUISpriteInstance>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CGUISpriteInstance& val)
|
||||
{
|
||||
ToJSVal(rq, ret, val.GetName());
|
||||
|
||||
Reference in New Issue
Block a user