Closed d47081 closed 4 months ago
This is not a PHP-GTK problem
If you provide a full working code, i can help with your logic
This is the case?
<?php
/**
* custom label
*/
class CustomLabel extends \GtkLabel
{
private string $_subtitle;
public function set_subtitle(string $value): void
{
$this->_subtitle = $value;
}
public function get_subtitle(): string
{
return $this->_subtitle;
}
}
Gtk::init();
$window = new GtkWindow();
$window->set_size_request(500, 500);
$window->set_title("PHP-GTK");
// create the notebook
$notebook = new GtkNotebook();
$window->add($notebook);
$notebook->set_scrollable(true);
// store all labels
$labels = [];
// add page 1
$labels[] = new CustomLabel("Page 1");
$notebook->append_page(GtkButton::new_with_label("Container 1"), end($labels));
// add page 2
$labels[] = new CustomLabel("Page 2");
$notebook->append_page(GtkButton::new_with_label("Container 2"), end($labels));
// on switch page
$notebook->connect("switch-page", function($widget, $page, $index) use ($labels) {
// retriave custom label by tab index
$label = $labels[$index];
// use it
var_dump($label->set_subtitle("OK"));
var_dump($label);
});
// connect to signal that close program
$window->connect("destroy", function() {
Gtk::main_quit();
});
// show all and start
$window->show_all();
Gtk::main();
As PHP-GTK as a language bind, I need to do alot cast internally, so this destroy PHP classes and pass GTK class. You'll not able to create a PHP class in GTK heap. I cannot directly cast PHP class to a GPointer, you get it?
Thanks, seems that global array could help.
Just interested in solution where PHP-GTK able to return back the extended object constructed by PHP. Anyway, even if it's possible by PHP-CPP, it may cause assertion issues, so yes, closed maybe.
As PHP-GTK as a language bind, I need to do alot cast internally, so this destroy PHP classes and pass GTK class. You'll not able to create a PHP class in GTK heap. I cannot directly cast PHP class to a GPointer, you get it?
I don't understand exactly how does it work, but meant something like magic methods:
Php::Value GtkWidget_::__get(const Php::Value &name)
{
return Php::Base::__get(name);
}
This is more of a GTK issue, not PHP-CPP. I can't cast a PHP object to gpointer and store the original PHP class. So when I use a GTK method that returns a gpointer, I can't correlate it with the original PHP class
Maybe if I rewrite all extension to store a PHP object, and not a GTK instance https://github.com/scorninpc/php-gtk3/blob/master/src/G/GObject.h#L27 (or both) .... So maybe in PHP-GTK4 I can try something, but i dont thing it's will work with alot internal hard coded references
I found interesting situation in app development.
To receive selected
GtkNotebook
Label, I'm using this construction:where
$label->get_subtitle()
is extra-feature implemented byGtkLabel
extension class:Of course, I got
Fatal error: Undefined method get_subtitle
because this method not defined in PHP-GTK3But suppose it is possible to make extendable PHP classes support, or not?