We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello,
How would you like to create a notifiable property for GObject ?
function my_callback(MyObject $object, GParamSpec $param, mixed $user_data) { echo $param->name . " changed", PHP_EOL; } $object = new MyObject(); $object->connect("signal::notify::zoom", "my_callback", "my_data", NULL); $object->zoom = 100; // this emit signal "notify::zoom" who call the callback of each connection.
Output : zoom changed
zoom changed
Add class property after declaration and before his instantiation.
<?php class MyObject extends GObject { $zoom; } $spec = GParamSpecUint("zoom", "Zoom prop", "Set zoom", 0, 100, 51, GParam::CONSTRUCT_ONLY); GObjectClass::InstallProperty(MyObject::class, 1, $spec); //unset($spec)
A possible alternative( That I don't like) :
<?php class MyObject extends GObject { $zoom; public function __construct() { parent::__contrust(); static $installed_class = 0; if (!$installed_class) { $spec = GParamSpecUint("zoom", "Zoom prop", "Set zoom", 0, 100, 51, GParam::CONSTRUCT_ONLY); GObjectClass::InstallProperty(MyObject::class, 1, $spec); $installed_class = 1; } } }
Add class property using annotations.
<?php class MyObject extends GObject { /** * @g_param_spec_uint( * name: "zoom", * nick: "Zoom prop", * "Set zoom", * 0, 100, 51, * G_PARAM_CONSTRUCT | G_PARAM_READWRITE) */ $zoom; }
A possible alternative :
<?php class MyObject extends GObject { /** Set zoom * @property(readwrite) uint $zoom Zoom property * @range(0, 100) */ int $zoom = 51; }
And even like that
<?php class MyObject extends GObject { #[GPropertyUint("zoom", "Zoom prop", "Set zoom", 0, 100, 51, GParam::CONSTRUCT | GParam::READWRITE)] int $zoom; }
All members of GObject child classes are notifiable automatically properties.
<?php class MyObject extends GObject { public int $zoom = 51;// Type declaration required }
What do you think of this topic?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hello,
How would you like to create a notifiable property for GObject ?
Use :
Output :
zoom changed
Example 1 :
Add class property after declaration and before his instantiation.
A possible alternative( That I don't like) :
Example 2 :
Add class property using annotations.
A possible alternative :
And even like that
Example 3 :
All members of GObject child classes are notifiable automatically properties.
What do you think of this topic?
The text was updated successfully, but these errors were encountered: