Browse Source

Made a reusable system for calling custom methods in visual components.

David Piuva 5 years ago
parent
commit
14b279445c

+ 8 - 0
Source/DFPSR/api/guiAPI.cpp

@@ -230,6 +230,14 @@ String dsr::component_getProperty(const Component& component, const ReadableStri
 	}
 	}
 }
 }
 
 
+void dsr::component_call(const Component& component, const ReadableString& methodName, const ReadableString& arguments) {
+	MUST_EXIST(component, component_call);
+	component->call(methodName, arguments);
+}
+void dsr::component_call(const Component& component, const ReadableString& methodName) {
+	component_call(component, methodName, U"");
+}
+
 void dsr::window_applyTheme(const Window& window, const VisualTheme& theme) {
 void dsr::window_applyTheme(const Window& window, const VisualTheme& theme) {
 	MUST_EXIST(window, window_applyTheme);
 	MUST_EXIST(window, window_applyTheme);
 	MUST_EXIST(theme, window_applyTheme);
 	MUST_EXIST(theme, window_applyTheme);

+ 4 - 0
Source/DFPSR/api/guiAPI.h

@@ -180,6 +180,10 @@ namespace dsr {
 	//     Returns an empty string when propertyName isn't found.
 	//     Returns an empty string when propertyName isn't found.
 	String component_getProperty(const Component& component, const ReadableString& propertyName, bool mustExist = true);
 	String component_getProperty(const Component& component, const ReadableString& propertyName, bool mustExist = true);
 
 
+	// Call a named method in the component using optional text arguments
+	void component_call(const Component& component, const ReadableString& methodName);
+	void component_call(const Component& component, const ReadableString& methodName, const ReadableString& arguments);
+
 // Component events
 // Component events
 	// The main activation of clickable components.
 	// The main activation of clickable components.
 	//   The pressed callback doesn't take any arguments, because it should be possible to generate from multiple input methods.
 	//   The pressed callback doesn't take any arguments, because it should be possible to generate from multiple input methods.

+ 4 - 0
Source/DFPSR/gui/VisualComponent.cpp

@@ -351,3 +351,7 @@ VisualTheme VisualComponent::getTheme() const {
 
 
 void VisualComponent::changedTheme(VisualTheme newTheme) {}
 void VisualComponent::changedTheme(VisualTheme newTheme) {}
 
 
+String VisualComponent::call(const ReadableString &methodName, const ReadableString &arguments) {
+	throwError("Unimplemented custom call received");
+	return U"";
+}

+ 2 - 0
Source/DFPSR/gui/VisualComponent.h

@@ -205,6 +205,8 @@ public:
 	virtual void changedAttribute(const ReadableString &name) {};
 	virtual void changedAttribute(const ReadableString &name) {};
 	// Override to be notified about location changes
 	// Override to be notified about location changes
 	virtual void changedLocation(IRect &oldLocation, IRect &newLocation) {};
 	virtual void changedLocation(IRect &oldLocation, IRect &newLocation) {};
+	// Custom call handler to manipulate components across a generic API
+	virtual String call(const ReadableString &methodName, const ReadableString &arguments);
 };
 };
 
 
 }
 }