Allow setting CGUISize properties directly
Previously, modifying individual CGUISize properties (left, top, right,
bottom) via JavaScript had no effect unless the entire size object was
copied, modified, and reassigned—resulting in verbose and error-prone
code.
This update introduces proper JavaScript property accessors, enabling
direct reading and writing of CGUISize members. The result is a more
intuitive and scriptable API.
Key Changes:
- Implemented JavaScript get/set accessors for each CGUISize property,
directly interacting with the native object.
- Retained support for string assignments to CGUISize
- Maintained the GUISize JS object for backward compatibility, also
marked as deprecated.
- Improved CGUISimpleSetting<CGUISize> to allow partial updates via
direct property access.
- allow assigning size from object with pixel and percent values
You can now assign size using an object with properties like:
size = {
left: number, right: number, top: number, bottom: number,
rleft: number, rright: number, rtop: number, rbottom: number
}
- One or more properties can be specified, the missing properties with
fill as zero.
- Assignment triggers an immediate update event.
Delayed Setting Notifications:
- Introduced a mechanism for delayed setting notifications, currently
only used in CGUISimpleSetting<CGUISize>, to avoid redundant
recalculations.
- Ensured that getComputedSize triggers any pending delayed
notifications before returning the size.
This change significantly enhances the developer experience and brings
the behavior in line with typical expectations for direct property
manipulation in JavaScript.
2025-06-04 14:22:34 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2020-11-21 09:49:06 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2020-11-21 09:49:06 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2020-11-21 09:49:06 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2020-11-21 09:49:06 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This file is included directly into actual implementation files.
|
|
|
|
|
|
2020-12-13 07:06:18 -08:00
|
|
|
#include "JSInterface_GUIProxy.h"
|
|
|
|
|
|
|
|
|
|
#include "gui/CGUI.h"
|
|
|
|
|
#include "gui/CGUISetting.h"
|
|
|
|
|
#include "gui/ObjectBases/IGUIObject.h"
|
|
|
|
|
#include "ps/CLogger.h"
|
2021-04-09 11:01:47 -07:00
|
|
|
#include "scriptinterface/FunctionWrapper.h"
|
2023-07-07 13:12:16 -07:00
|
|
|
#include "scriptinterface/Object.h"
|
2020-12-13 07:06:18 -08:00
|
|
|
#include "scriptinterface/ScriptExtraHeaders.h"
|
2021-05-15 06:54:58 -07:00
|
|
|
#include "scriptinterface/ScriptRequest.h"
|
2020-12-13 07:06:18 -08:00
|
|
|
|
|
|
|
|
#include <string>
|
2022-12-04 11:56:12 -08:00
|
|
|
#include <string_view>
|
2020-12-13 07:06:18 -08:00
|
|
|
|
Allow setting CGUISize properties directly
Previously, modifying individual CGUISize properties (left, top, right,
bottom) via JavaScript had no effect unless the entire size object was
copied, modified, and reassigned—resulting in verbose and error-prone
code.
This update introduces proper JavaScript property accessors, enabling
direct reading and writing of CGUISize members. The result is a more
intuitive and scriptable API.
Key Changes:
- Implemented JavaScript get/set accessors for each CGUISize property,
directly interacting with the native object.
- Retained support for string assignments to CGUISize
- Maintained the GUISize JS object for backward compatibility, also
marked as deprecated.
- Improved CGUISimpleSetting<CGUISize> to allow partial updates via
direct property access.
- allow assigning size from object with pixel and percent values
You can now assign size using an object with properties like:
size = {
left: number, right: number, top: number, bottom: number,
rleft: number, rright: number, rtop: number, rbottom: number
}
- One or more properties can be specified, the missing properties with
fill as zero.
- Assignment triggers an immediate update event.
Delayed Setting Notifications:
- Introduced a mechanism for delayed setting notifications, currently
only used in CGUISimpleSetting<CGUISize>, to avoid redundant
recalculations.
- Ensured that getComputedSize triggers any pending delayed
notifications before returning the size.
This change significantly enhances the developer experience and brings
the behavior in line with typical expectations for direct property
manipulation in JavaScript.
2025-06-04 14:22:34 -07:00
|
|
|
#ifndef INCLUDED_JSI_GUIPROXY_IMP
|
|
|
|
|
#define INCLUDED_JSI_GUIPROXY_IMP
|
|
|
|
|
|
2020-11-21 09:49:06 -08:00
|
|
|
template <typename T>
|
|
|
|
|
JSI_GUIProxy<T>& JSI_GUIProxy<T>::Singleton()
|
|
|
|
|
{
|
|
|
|
|
static JSI_GUIProxy<T> s;
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 11:01:47 -07:00
|
|
|
// Call this for every specialised type. You will need to override IGUIObject::CreateJSObject() in your class interface.
|
|
|
|
|
#define DECLARE_GUIPROXY(Type) \
|
|
|
|
|
void Type::CreateJSObject() \
|
|
|
|
|
{ \
|
|
|
|
|
ScriptRequest rq(m_pGUI.GetScriptInterface()); \
|
|
|
|
|
using ProxyHandler = JSI_GUIProxy<std::remove_pointer_t<decltype(this)>>; \
|
|
|
|
|
m_JSObject = ProxyHandler::CreateJSObject(rq, this, GetGUI().GetProxyData(&ProxyHandler::Singleton())); \
|
|
|
|
|
} \
|
|
|
|
|
template class JSI_GUIProxy<Type>;
|
|
|
|
|
|
2020-12-13 07:06:18 -08:00
|
|
|
// Use a common namespace to avoid duplicating the symbols un-necessarily.
|
|
|
|
|
namespace JSInterface_GUIProxy
|
2020-11-21 09:49:06 -08:00
|
|
|
{
|
2021-04-30 06:20:43 -07:00
|
|
|
// All proxy objects share a class definition.
|
|
|
|
|
JSClass& ClassDefinition()
|
2020-11-21 09:49:06 -08:00
|
|
|
{
|
2021-04-30 06:20:43 -07:00
|
|
|
static JSClass c = PROXY_CLASS_DEF("GUIObjectProxy", JSCLASS_HAS_CACHED_PROTO(JSProto_Proxy) | JSCLASS_HAS_RESERVED_SLOTS(1));
|
|
|
|
|
return c;
|
2020-11-21 09:49:06 -08:00
|
|
|
}
|
2020-12-13 07:06:18 -08:00
|
|
|
|
|
|
|
|
// Default implementation of the cache via unordered_map
|
|
|
|
|
class MapCache : public GUIProxyProps
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~MapCache() {};
|
|
|
|
|
|
|
|
|
|
virtual bool has(const std::string& name) const override
|
|
|
|
|
{
|
|
|
|
|
return m_Functions.find(name) != m_Functions.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual JSObject* get(const std::string& name) const override
|
|
|
|
|
{
|
|
|
|
|
return m_Functions.at(name).get();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 11:01:47 -07:00
|
|
|
virtual bool setFunction(const ScriptRequest& rq, const std::string& name, JSFunction* function) override
|
2020-12-13 07:06:18 -08:00
|
|
|
{
|
2021-04-09 11:01:47 -07:00
|
|
|
m_Functions[name].init(rq.cx, JS_GetFunctionObject(function));
|
2020-12-13 07:06:18 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
std::unordered_map<std::string, JS::PersistentRootedObject> m_Functions;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 06:20:43 -07:00
|
|
|
template<>
|
|
|
|
|
IGUIObject* IGUIProxyObject::FromPrivateSlot<IGUIObject>(JSObject* obj)
|
|
|
|
|
{
|
|
|
|
|
if (!obj)
|
|
|
|
|
return nullptr;
|
2023-01-10 09:06:47 -08:00
|
|
|
if (JS::GetClass(obj) != &JSInterface_GUIProxy::ClassDefinition())
|
2021-04-30 06:20:43 -07:00
|
|
|
return nullptr;
|
|
|
|
|
return UnsafeFromPrivateSlot<IGUIObject>(obj);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-13 07:06:18 -08:00
|
|
|
// The default propcache is a MapCache.
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct JSI_GUIProxy<T>::PropCache
|
|
|
|
|
{
|
|
|
|
|
using type = JSInterface_GUIProxy::MapCache;
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-30 06:20:43 -07:00
|
|
|
template <typename T>
|
|
|
|
|
T* JSI_GUIProxy<T>::FromPrivateSlot(const ScriptRequest&, JS::CallArgs& args)
|
|
|
|
|
{
|
|
|
|
|
// Call the unsafe version - this is only ever called from actual proxy objects.
|
|
|
|
|
return IGUIProxyObject::UnsafeFromPrivateSlot<T>(args.thisv().toObjectOrNull());
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-13 07:06:18 -08:00
|
|
|
template <typename T>
|
|
|
|
|
bool JSI_GUIProxy<T>::PropGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const
|
|
|
|
|
{
|
|
|
|
|
using PropertyCache = typename PropCache::type;
|
|
|
|
|
// Since we know at compile time what the type actually is, avoid the virtual call.
|
|
|
|
|
const PropertyCache* data = static_cast<const PropertyCache*>(static_cast<const GUIProxyProps*>(js::GetProxyReservedSlot(proxy, 0).toPrivate()));
|
|
|
|
|
if (data->has(propName))
|
|
|
|
|
{
|
|
|
|
|
vp.setObjectOrNull(data->get(propName));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
std::pair<const js::BaseProxyHandler*, GUIProxyProps*> JSI_GUIProxy<T>::CreateData(ScriptInterface& scriptInterface)
|
|
|
|
|
{
|
|
|
|
|
using PropertyCache = typename PropCache::type;
|
|
|
|
|
PropertyCache* data = new PropertyCache();
|
|
|
|
|
ScriptRequest rq(scriptInterface);
|
2021-04-09 11:01:47 -07:00
|
|
|
|
|
|
|
|
// Functions common to all children of IGUIObject.
|
|
|
|
|
JSI_GUIProxy<IGUIObject>::CreateFunctions(rq, data);
|
|
|
|
|
|
|
|
|
|
// Let derived classes register their own interface.
|
|
|
|
|
if constexpr (!std::is_same_v<T, IGUIObject>)
|
|
|
|
|
CreateFunctions(rq, data);
|
2020-12-13 07:06:18 -08:00
|
|
|
return { &Singleton(), data };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
2021-04-09 11:01:47 -07:00
|
|
|
template<auto callable>
|
|
|
|
|
void JSI_GUIProxy<T>::CreateFunction(const ScriptRequest& rq, GUIProxyProps* cache, const std::string& name)
|
|
|
|
|
{
|
2021-04-30 06:20:43 -07:00
|
|
|
cache->setFunction(rq, name, ScriptFunction::Create<callable, FromPrivateSlot>(rq, name.c_str()));
|
2021-04-09 11:01:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
std::unique_ptr<IGUIProxyObject> JSI_GUIProxy<T>::CreateJSObject(const ScriptRequest& rq, T* ptr, GUIProxyProps* dataPtr)
|
2020-12-13 07:06:18 -08:00
|
|
|
{
|
|
|
|
|
js::ProxyOptions options;
|
2021-04-30 06:20:43 -07:00
|
|
|
options.setClass(&JSInterface_GUIProxy::ClassDefinition());
|
2020-12-13 07:06:18 -08:00
|
|
|
|
2021-04-09 11:01:47 -07:00
|
|
|
auto ret = std::make_unique<IGUIProxyObject>();
|
|
|
|
|
ret->m_Ptr = static_cast<IGUIObject*>(ptr);
|
|
|
|
|
|
2020-12-13 07:06:18 -08:00
|
|
|
JS::RootedValue cppObj(rq.cx), data(rq.cx);
|
2021-04-09 11:01:47 -07:00
|
|
|
cppObj.get().setPrivate(ret->m_Ptr);
|
2020-12-13 07:06:18 -08:00
|
|
|
data.get().setPrivate(static_cast<void*>(dataPtr));
|
2021-04-09 11:01:47 -07:00
|
|
|
ret->m_Object.init(rq.cx, js::NewProxyObject(rq.cx, &Singleton(), cppObj, nullptr, options));
|
|
|
|
|
js::SetProxyReservedSlot(ret->m_Object, 0, data);
|
|
|
|
|
return ret;
|
2020-11-21 09:49:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2025-06-03 05:13:41 -07:00
|
|
|
bool JSI_GUIProxy<T>::get(JSContext* cx, JS::HandleObject proxy, JS::HandleValue /*receiver*/,
|
|
|
|
|
JS::HandleId id, JS::MutableHandleValue vp) const
|
2020-11-21 09:49:06 -08:00
|
|
|
{
|
2021-05-15 06:54:58 -07:00
|
|
|
ScriptRequest rq(cx);
|
2020-11-21 09:49:06 -08:00
|
|
|
|
2021-04-09 11:01:47 -07:00
|
|
|
T* e = IGUIProxyObject::FromPrivateSlot<T>(proxy.get());
|
2020-11-21 09:49:06 -08:00
|
|
|
if (!e)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
JS::RootedValue idval(rq.cx);
|
|
|
|
|
if (!JS_IdToValue(rq.cx, id, &idval))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
std::string propName;
|
2021-05-13 02:43:33 -07:00
|
|
|
if (!Script::FromJSVal(rq, idval, propName))
|
2020-11-21 09:49:06 -08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Return function properties. Specializable.
|
2020-12-13 07:06:18 -08:00
|
|
|
if (PropGetter(proxy, propName, vp))
|
2020-11-21 09:49:06 -08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Use onWhatever to access event handlers
|
|
|
|
|
if (propName.substr(0, 2) == "on")
|
|
|
|
|
{
|
|
|
|
|
CStr eventName(propName.substr(2));
|
|
|
|
|
std::map<CStr, JS::Heap<JSObject*>>::iterator it = e->m_ScriptHandlers.find(eventName);
|
|
|
|
|
if (it == e->m_ScriptHandlers.end())
|
|
|
|
|
vp.setNull();
|
|
|
|
|
else
|
|
|
|
|
vp.setObject(*it->second.get());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (propName == "parent")
|
|
|
|
|
{
|
|
|
|
|
IGUIObject* parent = e->GetParent();
|
|
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
|
vp.set(JS::ObjectValue(*parent->GetJSObject()));
|
|
|
|
|
else
|
|
|
|
|
vp.set(JS::NullValue());
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (propName == "children")
|
|
|
|
|
{
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::CreateArray(rq, vp);
|
2020-11-21 09:49:06 -08:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < e->m_Children.size(); ++i)
|
2021-05-13 10:23:52 -07:00
|
|
|
Script::SetPropertyInt(rq, vp, i, e->m_Children[i]);
|
2020-11-21 09:49:06 -08:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (propName == "name")
|
|
|
|
|
{
|
2021-05-13 02:43:33 -07:00
|
|
|
Script::ToJSVal(rq, vp, e->GetName());
|
2020-11-21 09:49:06 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (e->SettingExists(propName))
|
|
|
|
|
{
|
|
|
|
|
e->m_Settings[propName]->ToJSVal(rq, vp);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGERROR("Property '%s' does not exist!", propName.c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
bool JSI_GUIProxy<T>::set(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::HandleValue vp,
|
2025-06-03 05:13:41 -07:00
|
|
|
JS::HandleValue /*receiver*/, JS::ObjectOpResult& result) const
|
2020-11-21 09:49:06 -08:00
|
|
|
{
|
2021-04-09 11:01:47 -07:00
|
|
|
T* e = IGUIProxyObject::FromPrivateSlot<T>(proxy.get());
|
2020-11-21 09:49:06 -08:00
|
|
|
if (!e)
|
2020-12-06 06:03:02 -08:00
|
|
|
{
|
|
|
|
|
LOGERROR("C++ GUI Object could not be found");
|
|
|
|
|
return result.fail(JSMSG_OBJECT_REQUIRED);
|
|
|
|
|
}
|
2020-11-21 09:49:06 -08:00
|
|
|
|
2021-05-15 06:54:58 -07:00
|
|
|
ScriptRequest rq(cx);
|
2020-11-21 09:49:06 -08:00
|
|
|
|
|
|
|
|
JS::RootedValue idval(rq.cx);
|
|
|
|
|
if (!JS_IdToValue(rq.cx, id, &idval))
|
2020-12-06 06:03:02 -08:00
|
|
|
return result.fail(JSMSG_BAD_PROP_ID);
|
2020-11-21 09:49:06 -08:00
|
|
|
|
|
|
|
|
std::string propName;
|
2021-05-13 02:43:33 -07:00
|
|
|
if (!Script::FromJSVal(rq, idval, propName))
|
2020-12-06 06:03:02 -08:00
|
|
|
return result.fail(JSMSG_BAD_PROP_ID);
|
2020-11-21 09:49:06 -08:00
|
|
|
|
|
|
|
|
if (propName == "name")
|
|
|
|
|
{
|
|
|
|
|
std::string value;
|
2021-05-13 02:43:33 -07:00
|
|
|
if (!Script::FromJSVal(rq, vp, value))
|
2020-12-06 06:03:02 -08:00
|
|
|
return result.fail(JSMSG_BAD_PROP_ID);
|
2020-11-21 09:49:06 -08:00
|
|
|
e->SetName(value);
|
|
|
|
|
return result.succeed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JS::RootedObject vpObj(cx);
|
|
|
|
|
if (vp.isObject())
|
|
|
|
|
vpObj = &vp.toObject();
|
|
|
|
|
|
|
|
|
|
// Use onWhatever to set event handlers
|
|
|
|
|
if (propName.substr(0, 2) == "on")
|
|
|
|
|
{
|
2024-10-25 01:22:43 -07:00
|
|
|
if (vp.isPrimitive() || vp.isNull() || !JS::IsCallable(&vp.toObject()))
|
2020-11-21 09:49:06 -08:00
|
|
|
{
|
|
|
|
|
LOGERROR("on- event-handlers must be functions");
|
|
|
|
|
return result.fail(JSMSG_NOT_FUNCTION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CStr eventName(propName.substr(2));
|
|
|
|
|
e->SetScriptHandler(eventName, vpObj);
|
|
|
|
|
|
|
|
|
|
return result.succeed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e->SettingExists(propName))
|
|
|
|
|
return e->m_Settings[propName]->FromJSVal(rq, vp, true) ? result.succeed() : result.fail(JSMSG_USER_DEFINED_ERROR);
|
|
|
|
|
|
|
|
|
|
LOGERROR("Property '%s' does not exist!", propName.c_str());
|
2020-12-06 06:03:02 -08:00
|
|
|
return result.fail(JSMSG_BAD_PROP_ID);
|
2020-11-21 09:49:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
bool JSI_GUIProxy<T>::delete_(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::ObjectOpResult& result) const
|
|
|
|
|
{
|
2021-04-09 11:01:47 -07:00
|
|
|
T* e = IGUIProxyObject::FromPrivateSlot<T>(proxy.get());
|
2020-11-21 09:49:06 -08:00
|
|
|
if (!e)
|
2020-12-06 06:03:02 -08:00
|
|
|
{
|
|
|
|
|
LOGERROR("C++ GUI Object could not be found");
|
|
|
|
|
return result.fail(JSMSG_OBJECT_REQUIRED);
|
|
|
|
|
}
|
2020-11-21 09:49:06 -08:00
|
|
|
|
2021-05-15 06:54:58 -07:00
|
|
|
ScriptRequest rq(cx);
|
2020-11-21 09:49:06 -08:00
|
|
|
|
|
|
|
|
JS::RootedValue idval(rq.cx);
|
|
|
|
|
if (!JS_IdToValue(rq.cx, id, &idval))
|
2020-12-06 06:03:02 -08:00
|
|
|
return result.fail(JSMSG_BAD_PROP_ID);
|
2020-11-21 09:49:06 -08:00
|
|
|
|
|
|
|
|
std::string propName;
|
2021-05-13 02:43:33 -07:00
|
|
|
if (!Script::FromJSVal(rq, idval, propName))
|
2020-12-06 06:03:02 -08:00
|
|
|
return result.fail(JSMSG_BAD_PROP_ID);
|
2020-11-21 09:49:06 -08:00
|
|
|
|
|
|
|
|
// event handlers
|
2022-12-04 11:56:12 -08:00
|
|
|
if (std::string_view{propName}.substr(0, 2) == "on")
|
2020-11-21 09:49:06 -08:00
|
|
|
{
|
|
|
|
|
CStr eventName(propName.substr(2));
|
|
|
|
|
e->UnsetScriptHandler(eventName);
|
|
|
|
|
return result.succeed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGERROR("Only event handlers can be deleted from GUI objects!");
|
2020-12-06 06:03:02 -08:00
|
|
|
return result.fail(JSMSG_BAD_PROP_ID);
|
2020-11-21 09:49:06 -08:00
|
|
|
}
|
Allow setting CGUISize properties directly
Previously, modifying individual CGUISize properties (left, top, right,
bottom) via JavaScript had no effect unless the entire size object was
copied, modified, and reassigned—resulting in verbose and error-prone
code.
This update introduces proper JavaScript property accessors, enabling
direct reading and writing of CGUISize members. The result is a more
intuitive and scriptable API.
Key Changes:
- Implemented JavaScript get/set accessors for each CGUISize property,
directly interacting with the native object.
- Retained support for string assignments to CGUISize
- Maintained the GUISize JS object for backward compatibility, also
marked as deprecated.
- Improved CGUISimpleSetting<CGUISize> to allow partial updates via
direct property access.
- allow assigning size from object with pixel and percent values
You can now assign size using an object with properties like:
size = {
left: number, right: number, top: number, bottom: number,
rleft: number, rright: number, rtop: number, rbottom: number
}
- One or more properties can be specified, the missing properties with
fill as zero.
- Assignment triggers an immediate update event.
Delayed Setting Notifications:
- Introduced a mechanism for delayed setting notifications, currently
only used in CGUISimpleSetting<CGUISize>, to avoid redundant
recalculations.
- Ensured that getComputedSize triggers any pending delayed
notifications before returning the size.
This change significantly enhances the developer experience and brings
the behavior in line with typical expectations for direct property
manipulation in JavaScript.
2025-06-04 14:22:34 -07:00
|
|
|
#endif // INCLUDED_JSI_GUIPROXY_IMP
|