gtk-rs / gtk4 Goto Github PK
View Code? Open in Web Editor NEWRust bindings of GTK 4
Home Page: https://gtk-rs.org/gtk4-rs/
License: MIT License
Rust bindings of GTK 4
Home Page: https://gtk-rs.org/gtk4-rs/
License: MIT License
When hexpand is used in sub classed object like ListBoxRow it throws
thread 'main' panicked at 'No parent class impl for "compute_expand"', /home/kavan/Documents/App/_build/build/target/cargo-home/git/checkouts/gtk4-rs-e74ad56283dfeb5e/78f7523/gtk4/src/subclass/widget.rs:186:18
page.rs
use glib::subclass;
use glib::{clone, glib_object_subclass, glib_wrapper};
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::subclass::{list_box_row::ListBoxRowImpl, widget::WidgetImpl};
use std::cell::RefCell;
use std::error::Error;
use crate::GRESOURCE_ID;
#[derive(Debug, Clone)]
pub struct Page_ {
id: RefCell<i64>,
name: RefCell<String>,
builder: gtk::Builder,
}
impl ObjectSubclass for Page_ {
const NAME: &'static str = "Page";
type Type = Page;
type ParentType = gtk::ListBoxRow;
type Instance = subclass::simple::InstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
glib_object_subclass!();
fn new() -> Self {
Self {
id: RefCell::new(0),
name: RefCell::new(String::new()),
builder: gtk::Builder::from_resource(&(GRESOURCE_ID.to_owned() + "/page-row.ui")),
}
}
}
impl ObjectImpl for Page_ {
fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj);
get_widget!(self.builder, gtk::Box, root);
obj.set_child(Some(&root));
}
}
glib_wrapper! {
pub struct Page(ObjectSubclass<Page_>)
@extends gtk::ListBoxRow, gtk::Widget;
}
impl WidgetImpl for Page_ {}
impl ListBoxRowImpl for Page_ {}
impl Page {
pub fn new() -> Result<Self, glib::BoolError> {
glib::Object::new(Self::static_type(), &[]).and_then(|a| {
a.downcast::<Self>()
.map_err(|e| glib_bool_error!("Faild to downcast {:?}", e.get_type()))
})
}
pub fn set_id(&self, id: i64) {
(*Page_::from_instance(self).id.borrow_mut()) = id
}
pub fn get_id(&self) -> i64 {
(*Page_::from_instance(self).id.borrow())
}
pub fn set_label(&self, text: String) {
let priv_ = Page_::from_instance(self);
get_widget!(priv_.builder, gtk::Label, name);
name.set_label(&text);
*priv_.name.borrow_mut() = text
}
pub fn get_label(&self) -> String {
(*Page_::from_instance(self).name.borrow()).to_owned()
}
}
page.ui
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkBox" id="root">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">horizontal</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">8</property>
<property name="margin-bottom">8</property>
<property name="spacing">8</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="icon-name">emoji-symbols-symbolic</property>
</object>
</child>
<child>
<object class="GtkLabel" id="name">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0.0</property>
<property name="hexpand">True</property>
<property name="label">Collection Name</property>
</object>
</child>
</object>
</interface>
Over at gnome gitlab @sophie-h created a python script that automatically generates composite template code for bindings from the ui files by parsing the xml, extracting the objects and creating fields (or functions in this case but that's an easily changed implementation detail) for every object that has an id.
I then rewrote it as a rust build script. It could also be reworked as a macro or something similar. You would only need to use the macro, specify a folder that contains your .ui files and it would automatically generate template code for you.
This has several advantages to manually writing template bindings:
Would this be a good addition to gtk-rs? If so, does anyone have any feedback on how to integrate it best? @bilelmoussaoui @sophie-h
Should be pretty easy
When I have a struct like:
#[derive(Debug, CompositeTemplate)]
#[template(resource = "/dev/Cogitri/test/ui/my_window.ui")]
pub struct MyWindow {
#[template_child]
pub add_data_button: TemplateChild<gtk::Button>,
}
And init it like so:
fn new() -> Self {
Self {
add_data_button: TemplateChild::default(),
}
}
I don't get any error message during compilation or when creating the object. However, once I access add_data_button
, the app crashes:
thread 'main' panicked at 'assertion failed: !self.ptr.is_null()', /var/home/rasmus/Projects/Jinsei/build/target/cargo-home/git/checkouts/gtk4-rs-e74ad56283dfeb5e/64d0e1c/gtk4/src/subclass/widget.rs:1000:13
stack backtrace:
0: std::panicking::begin_panic
at /var/home/rasmus/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:505
1: <gtk4::subclass::widget::TemplateChild<T> as core::ops::deref::Deref>::deref
at ./build/target/cargo-home/git/checkouts/gtk4-rs-e74ad56283dfeb5e/64d0e1c/gtk4/src/subclass/widget.rs:1000
2: health::windows::window::imp::HealthWindow::connect_handlers
at ./src/windows/window.rs:158
3: <health::windows::window::imp::HealthWindow as glib::subclass::object::ObjectImpl>::constructed
at ./src/windows/window.rs:129
4: glib::subclass::object::constructed
at ./build/target/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/c58fab4/glib/src/subclass/object.rs:109
5: <unknown>
6: g_object_newv
7: glib::object::Object::new_internal
at ./build/target/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/c58fab4/glib/src/object.rs:1165
8: glib::object::Object::with_type
at ./build/target/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/c58fab4/glib/src/object.rs:1105
9: glib::object::Object::new
at ./build/target/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/c58fab4/glib/src/object.rs:1074
10: health::windows::window::HealthWindow::new
at ./src/windows/window.rs:213
11: <health::core::application::imp::HealthApplication as gio::subclass::application::ApplicationImpl>::activate
at ./src/core/application.rs:57
12: gio::subclass::application::application_activate
at ./build/target/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/c58fab4/gio/src/subclass/application.rs:368
13: g_signal_emit_valist
14: g_signal_emit
15: <unknown>
16: <T as gio::subclass::application::ApplicationImplExt>::parent_local_command_line
at ./build/target/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/c58fab4/gio/src/subclass/application.rs:232
17: gio::subclass::application::ApplicationImpl::local_command_line
at ./build/target/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/c58fab4/gio/src/subclass/application.rs:99
18: gio::subclass::application::application_local_command_line
at ./build/target/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/c58fab4/gio/src/subclass/application.rs:411
19: g_application_run
20: <O as gio::application::ApplicationExtManual>::run
at ./build/target/cargo-home/git/checkouts/gtk-rs-48ef14c1f17c79fb/c58fab4/gio/src/application.rs:23
21: health::main
at ./src/main.rs:27
22: core::ops::function::FnOnce::call_once
at /var/home/rasmus/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:
Which makes sense, but it'd be nice if it either crashed during construction with a more helpful error message (or maybe even when compiling).
Tested w/ e0cbea5
This should be prevented by not inserting them if both features are selected.
See https://gitlab.gnome.org/GNOME/gtk/-/issues/3304 . We should override that here for now as nullable.
Was fixed for gtk3 in gtk-rs/gtk#1053
Some functions can't return a nullable like GtkEntry::get_text(), we should check those and fix the Gir.toml accordingly.
When looking at my usage of dialog.run()
I decided to just implement an async run()
.
The only solution I see is to connect to the "response" event and send the result through a channel. But I can also check how gtk3 implemented this.
Any thoughts?
After #51 is merged, there's still some work left to do:
bind_template_children
fnklass.bind_template_children()
instance_init()
so that init_template()
can be calledIn gtk4 doc GtkEventBox is no longer needed and has been removed. All widgets receive all events.
Error:
error[E0599]: no method named `connect_button_press_event` found for struct `gtk4::Box` in the current scope
--> demo.rs:11:10
|
11 | box_.connect_button_press_event(|btn| {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `gtk4::Box`
error: aborting due to previous error
Code:
use gio::prelude::*;
use gtk::prelude::*;
use std::env::args;
fn build_ui(application: >k::Application) {
let window = gtk::ApplicationWindow::new(application);
window.set_default_size(300, 200);
let box_ = gtk::Box::new(gtk::Orientation::Vertical, 0);
box_.connect_button_press_event(|btn| {
println!("Clicked!");
});
window.set_child(Some(&box_));
window.set_application(Some(application));
application.add_window(&window);
window.present();
}
pub fn main() {
let application = gtk::Application::new(Some("org.gnome.Sdk"), Default::default())
.expect("Initialization failed...");
application.connect_activate(|app| {
build_ui(app);
});
application.run(&args().collect::<Vec<_>>());
}
Here's a list of Classes/Interfaces along with their associate virtual methods
get_action_name
get_action_target_value
set_action_name
set_action_target_value
changed
value_changed
add_child
construct_child
custom_finished
custom_tag_end
custom_tag_start
get_id
get_internal_child
parser_finished
set_buildable_property
set_id
create_closure
get_type_from_function
get_type_from_name
activate
clicked
activate
add
apply_attributes
copy_context
create_context
event
focus
foreach_alloc
foreach
get_cell_property
get_preferred_height_for_width
get_preferred_height
get_preferred_width_for_height
get_preferred_width
get_request_mode
is_activatable
remove
set_cell_property
snapshot
allocate
get_preferred_height_for_width
get_preferred_width_for_height
reset
editing_done
remove_widget
start_editing
add_attribute
clear_attributes
clear
get_area
get_cells
pack_end
pack_start
reorder
set_cell_data_func
activate
editing_canceled
editing_started
get_aligned_area
get_preferred_height_for_width
get_preferred_height
get_preferred_width_for_height
get_preferred_width
get_request_mode
get_size
snapshot
start_editing
edited
toggled
add_palette
color_activated
get_rgba
set_rgba
changed
format_entry_text
resize
changed
delete_text
do_delete_text
do_insert_text
get_selection_bounds
get_text
insert_text
set_selection_bounds
activate
delete_text
deleted_text
get_length
get_text
insert_text
inserted_text
get_strictness
match
activate
font_activated
get_font_face
get_font_family
get_font_map
get_font_size
set_filter_func
set_font_map
compute_child_allocation
create_context
render
resize
commit
delete_surrounding
filter_keypress
focus_in
focus_out
get_preedit_string
get_surrounding
preedit_changed
preedit_end
preedit_start
reset
retrieve_surrounding
set_client_widget
set_cursor_location
set_surrounding
set_use_preedit
allocate
create_layout_child
get_request_mode
measure
root
unroot
activate
close
open
pause
play
realize
seek
unrealize
update_audio
hide
response
show
activate_default
closed
begin_print
create_custom_widget
custom_widget_apply
done
draw_page
end_print
paginate
preview
request_page_setup
status_changed
update_custom_widget
end_preview
got_page_size
is_selected
ready
render_page
adjust_bounds
change_value
get_range_border
move_slider
value_changed
changed
get_layout_offsets
value_changed
get_border
get_selection_in_range
is_selected
select_all
select_item
select_range
set_selection
unselect_all
unselect_item
unselect_range
add_controller
remove_controller
compare
get_order
changed
apply_tag
begin_user_action
changed
delete_range
end_user_action
insert_child_anchor
insert_paintable
insert_text
mark_deleted
mark_set
modified_changed
paste_done
redo
remove_tag
undo
backspace
copy_clipboard
create_buffer
cut_clipboard
delete_from_cursor
extend_selection
insert_at_cursor
insert_emoji
move_cursor
paste_clipboard
set_anchor
snapshot_layer
toggle_overwrite
toggled
drag_data_received
row_drop_possible
drag_data_delete
drag_data_get
row_draggable
get_column_type
get_flags
get_iter
get_n_columns
get_path
get_value
iter_children
iter_has_child
iter_n_children
iter_next
iter_nth_child
iter_parent
iter_previous
ref_node
row_changed
row_deleted
row_has_child_toggled
row_inserted
rows_reordered
unref_node
modify
visible
get_sort_column_id
has_default_sort_func
set_default_sort_func
set_sort_column_id
set_sort_func
sort_column_changed
columns_changed
cursor_changed
expand_collapse_cursor_row
move_cursor
row_activated
row_collapsed
row_expanded
select_all
select_cursor_parent
select_cursor_row
start_interactive_search
test_collapse_row
test_expand_row
toggle_cursor_row
unselect_all
contains
css_changed
focus
get_request_mode
grab_focus
hide
keynav_failed
map
measure
mnemonic_activate
move_focus
query_tooltip
realize
root
set_focus_child
show
size_allocate
snapshot
state_flags_changed
system_setting_changed
unmap
unrealize
unroot
window_added
window_removed
close
response
compute_expand
direction_changed
activate_default
activate_focus
close_request
enable_debugging
keys_changed
gdk:
attach_clipboard
content_changed
detach_clipboard
get_value
ref_formats
ref_storable_formats
write_mime_type_async
write_mime_type_finish
get_current_image
get_flags
get_intrinsic_aspect_ratio
get_intrinsic_height
get_intrinsic_width
snapshot
| ^^^^^^^^ multiple `set_name` found
|
= note: candidate #1 is defined in an impl of the trait `gtk4::EventControllerExt` for the type `O`
= note: candidate #2 is defined in an impl of the trait `gtk4::WidgetExt` for the type `O`
= note: candidate #3 is defined in an impl of the trait `gtk4::prelude::WidgetExtManual` for the type `O`
Subclassing GtkApplication and leaving all implementations blank does not call gtk::init()
. Docs for GtkApplication says it should be called in parent_startup()
.
Interestingly, widgets created through a template work without GTK being initialized
It would be nice to port most if not all the examples in the upstream gtk repository to Rust as a replacement of the current examples that are mostly a copy paste of the gtk3 ones.
see gtk-rs
Creating a dialog with a filter like
let gif_filter = gtk::FileFilter::new();
gif_filter.add_mime_type("image/gif");
gif_filter.set_name(Some("GIF (image/gif)"));
let file_chooser = gtk::FileChooserNativeBuilder::new()
.accept_label("Open")
.cancel_label("Cancel")
.modal(true)
.title("Open a GIF to display")
.transient_for(self)
.action(gtk::FileChooserAction::Open)
.filter(&gif_filter)
.build();
wouldn't show up which is normal as the filter isn't a prop as the builder somehow assumes? and should use the method in FileChooserExt::add_filter
to assign all those filters which would require writing the builder manually I guess
Works fine btw
let gif_filter = gtk::FileFilter::new();
gif_filter.add_mime_type("image/gif");
gif_filter.set_name(Some("GIF (image/gif)"));
let file_chooser = gtk::FileChooserNativeBuilder::new()
.accept_label("Open")
.cancel_label("Cancel")
.modal(true)
.title("Open a GIF to display")
.transient_for(self)
.action(gtk::FileChooserAction::Open)
.build();
file_chooser.add_filter(&gif_filter);
Currently all the crates either have a very poor README or not at all, we should clean things up before the first release.
Informations to include:
Documentation links / Crates.io link, C documentation link, a list of features of each crate
Near the bottom of gtk4-rs/gtk4/README.md it states that "gtk4 is available under the MIT License" which I find misleading, because gtk4 itself is LGPL. I believe this should say "gtk-rs" or similar instead of "gtk4".
The gtk_custom_layout_new
needs some manual bindings
gtk_widget_class_add_binding
gtk_widget_class_add_binding_action
gtk_widget_class_add_binding_signal
gtk_widget_class_add_shortcut
gtk_widget_class_bind_template_callback_full
gtk_widget_class_get_accessible_role
gtk_widget_class_get_activate_signal
gtk_widget_class_get_css_name
gtk_widget_class_get_layout_manager_type
gtk_widget_class_install_action
gtk_widget_class_install_property_action
gtk_widget_class_query_action
gtk_widget_class_set_accessible_role
gtk_widget_class_set_activate_signal
gtk_widget_class_set_activate_signal_from_name
gtk_widget_class_set_template_scope
The only other widget with class methods we can implement is CellArea
gtk_cell_area_class_find_cell_property
gtk_cell_area_class_install_cell_property
gtk_cell_area_class_list_cell_properties
This one is called on ObjectClass, not sure why it's there...
gtk_editable_install_properties
It's a fundamental type and needs manual bindings for itself and all its subclasses. See glib::ParamSpec
for another example like that.
see src/entry_buffer
See gdk::keys
module for how it could look like.
Also the gtk4::EventControllerKey
currently provides plain u32
for keyval/keycode in its events. That should probably be an enum too.
It would be nicer to have a set_draw_func()
that takes a plain closure and an unset_draw_func()
for setting it to None
again.
Same as gtk-rs/gtk3-rs#91 but for gtk4-rs
i clone https://github.com/gtk-rs/gtk4-rs
and then cargo build , it complie ok.
and then i create my crate gtk4test1,and copy/paste the code from gtk4-rs/examples/bin/basic.rs,
the cargo.toml like
[package]
name = "gtk4test1"
version = "0.1.0"
authors = ["xxx <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gtk= { git = "https://github.com/gtk-rs/gtk4-rs", package="gtk4"}
then run
cargo build
it fail.
many many errors.
the end like this :
--> /home/ra/.cargo/git/checkouts/gtk4-rs-e74ad56283dfeb5e/2d185cf/gdk4/src/auto/toplevel_layout.rs:120:18
|
120 | impl Default for ToplevelLayout {
| ^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `ToplevelLayout` in this scope
--> /home/ra/.cargo/git/checkouts/gtk4-rs-e74ad56283dfeb5e/2d185cf/gdk4/src/auto/toplevel_layout.rs:126:20
|
126 | impl PartialEq for ToplevelLayout {
| ^^^^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `ToplevelLayout` in this scope
--> /home/ra/.cargo/git/checkouts/gtk4-rs-e74ad56283dfeb5e/2d185cf/gdk4/src/auto/toplevel_layout.rs:133:13
|
133 | impl Eq for ToplevelLayout {}
| ^^^^^^^^^^^^^^ not found in this scope
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> /home/ra/.cargo/git/checkouts/gtk4-rs-e74ad56283dfeb5e/2d185cf/gdk4/src/auto/drop.rs:160:1
|
160 | impl fmt::Display for Drop {
| ^^^^^^^^^^^^^^^^^^^^^^----
| | |
| | `dyn std::ops::Drop` is not defined in the current crate
| impl doesn't use only types from inside the current crate
|
= note: define and implement a trait or new type instead
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
--> /home/ra/.cargo/git/checkouts/gtk4-rs-e74ad56283dfeb5e/2d185cf/gdk4/src/auto/drop.rs:30:1
|
30 | / impl Drop {
31 | | #[doc(alias = "gdk_drop_finish")]
32 | | pub fn finish(&self, action: DragAction) {
33 | | unsafe {
... |
157 | | }
158 | | }
| |_^ impl for type defined outside of crate.
|
= note: define and implement a trait or new type instead
error: aborting due to 463 previous errors
Some errors have detailed explanations: E0116, E0117, E0412, E0432, E0433.
For more information about an error, try `rustc --explain E0116`.
error: could not compile `gdk4`
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
[ra@ubuntu gtk4test1]$
Adding a layout constraint from VFL is not supported by gtk4-rs
Example based on pygobject API translated to Rust:
let layout = gtk::ConstraintLayout::new();
let vfl = vec![
"H:|-20-[position]-5-[progress(>=600@weak)]-5-[total]-20-|",
"V:|-0-[position]-0-|",
"V:|-0-[progress]-0-|",
"V:|-0-[total]-0-|"
];
let widgets = hashmap! {
position: &position_label,
progress: &progress_scale,
total: &total_label
};
layout.add_constraints_from_description(
&vfl, 0, 0, &widgets
);
Would be nice to have a list of PR/MR of each application that migrated from gtk3-rs to gtk4-rs somehow here
Hi,
I want to move a window on X11, so I need to get access to the respective X11 display and window.
Following the GDK4 documentation this API call should be used: https://developer.gnome.org/gdk4/stable/gdk4-X-Window-System-Interaction.html#gdk-x11-display-get-xdisplay
Gir.toml mentions it in line 55: https://github.com/gtk-rs/gtk4-rs/blob/master/gdk4-x11/Gir.toml#L55
But the source doesn't contain the API call: https://github.com/gtk-rs/gtk4-rs/blob/master/gdk4-x11/src/auto/x11_display.rs
I'm not sure if this is really a bug, or if I need to generate something. A hint how to fix it manually would also be welcome.
gtk4-rs, gdk4-x11
Currently there's the following gtk4 specific crates
As the other sys crates are moving to gtk-rs, we will probably need to move the 3 first sys crates to their individual repositories. Along with the creation of two new repositories to handle the missing bindings.
What I suggest:
Migrate all the gtk4 repositories into this one (if possible), the same way it was handled for gtk3. Both repositories could be merged later in the future once they are "ready" (as in gtk-rs & gtk4-rs?)
The benefits:
To allow users to bind the signals from their UI file;
Quoting slomo again
This will need some subclass defined here in gtk so that builder can automatically connect signals/etc. Best to create an issue for that.
slomo : i think the cleanest would be a attribute proc macro that you would put on callback functions, which then creates the actual callback based on the function signature and GValues and checking that the types match up. then the only remaining problem is to prevent people from defining arbitrary functions manually as that would allow (intentionally) causing memory corruptions from safe code, i.e. would be unsound
slomo: the GValue stuff can be done more or less automatically once i finished gtk-rs/gtk3-rs#48 . that would work very similar to how i want to handle GObject properties more conveniently Improve glib::Value usage by merging FromValue/FromValueOptional traits · Issue #48 · gtk-rs/gtk-rs
slomo: Currently we have pub trait FromValueOptional<'a>: StaticType + Sized { unsafe fn from_value_optional(_: &'a Value) -> Option; } pub trait FromValue<'a>: ...
slomo: and that change is needed so that you can autogenerate code from/to GValues without knowing anything about the Rust types involved other than their name
slomo: and GValues are relevant in your case too because that's how the signal machinery works. and the builder scope wants you to provide GClosures
slomo: having such an attribute proc macro could also make glib::Object::connect() more convenient btw, i think that would be useful
slomo: makes sense?
Needs something similar to
quoting slomo
Actually nevermind, it shouldn't have a new() function but basically work like https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/blob/master/gstreamer/src/param_spec.rs#L13 . That way it will work well with the subclass property API.
Trying to use a subclassed widget in another widget's ui template gives a runtime error:
Gtk-CRITICAL **: 18:40:50.481: Error building template class 'ParentCustomWidget' for an instance of type 'ParentCustomWidget': .:0:0 Invalid object type 'ChildCustomWidget'
This stackoverflow thread seems to have some info.
Should probably be enums. See also https://github.com/gtk-rs/gdk4/issues/20
Similarly for the mouse buttons in the other event controllers.
the param uses inout
direction which can't be automatically generated by gir for now, this needs to be manually implemented for now.
<method name="remove" c:identifier="gtk_tree_store_remove">
<doc xml:space="preserve">Removes @iter from @tree_store. After being removed, @iter is set to the
next valid row at that level, or invalidated if it previously pointed to the
last one.</doc>
<return-value transfer-ownership="none">
<doc xml:space="preserve">%TRUE if @iter is still valid, %FALSE if not.</doc>
<type name="gboolean" c:type="gboolean"/>
</return-value>
<parameters>
<instance-parameter name="tree_store" transfer-ownership="none">
<doc xml:space="preserve">A #GtkTreeStore</doc>
<type name="TreeStore" c:type="GtkTreeStore*"/>
</instance-parameter>
<parameter name="iter" direction="inout" caller-allocates="0" transfer-ownership="full">
<doc xml:space="preserve">A valid #GtkTreeIter</doc>
<type name="TreeIter" c:type="GtkTreeIter*"/>
</parameter>
</parameters>
</method>
I'm using for c in listbox.get_children()
from gtk3-rs. This will probably become legacy code, because the handling of children can probably be done via model bindings in gtk4. However, it might still be handy to just have an iterator for children. Opinions?
Requires adding the proper gir files to gir-files first
See summary :)
I am running on fedora 33 and installed rust and gtk4-devel using dnf. When trying to get rust to compile I had to add
[dependencies]
gtk4 = { git = "https://github.com/gtk-rs/gtk4.git" }
to the Cargo.toml (just using gtk = .. did not work)
Also I compile the basic.rs code in the example, but any reference to gtk, I had to change to gtk4.
Is this an issue?
From IRC
dcomp: Whats the difference between gtk4::Application::new and gtk4::ApplicationBuilder::new().build()?
I would assume that the Builder just calls methods on a Application instance. But that doesn't seem to be the case
as I get a panic on the activate signal saying that gtk::init hasn't been called
-> bilelmoussaoui : slomo: it needs it here as well https://github.com/gtk-rs/gtk4-rs/blob/master/gtk4/src/auto/application.rs#L65 i guess
Has to be manual
I have just start to play with gtk4, the first run wasn't a success sadly as I'm getting this when running any examples from gtk-rs/examples4.
thread 'main' panicked at 'GTK has not been initialized. Call `gtk::init` first.', /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/auto/functions.rs:333:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Here's the backtrace with RUST_BACKTRACE=full
hread 'main' panicked at 'GTK has not been initialized. Call `gtk::init` first.', /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/auto/functions.rs:333:5
stack backtrace:
0: 0x56540f4004b4 - backtrace::backtrace::libunwind::trace::h7b0eb74108f5983f
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
1: 0x56540f4004b4 - backtrace::backtrace::trace_unsynchronized::h1b47ddc501b76c75
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
2: 0x56540f4004b4 - std::sys_common::backtrace::_print_fmt::hdb3e11118348d382
at src/libstd/sys_common/backtrace.rs:77
3: 0x56540f4004b4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9a91dd8c51296d48
at src/libstd/sys_common/backtrace.rs:61
4: 0x56540f418d6c - core::fmt::write::h0abb1a448222f5be
at src/libcore/fmt/mod.rs:1028
5: 0x56540f3fed37 - std::io::Write::write_fmt::heafd3457e1ab0a67
at src/libstd/io/mod.rs:1412
6: 0x56540f40284e - std::sys_common::backtrace::_print::hce8ebf3707f77321
at src/libstd/sys_common/backtrace.rs:65
7: 0x56540f40284e - std::sys_common::backtrace::print::hab52fb573eb13c01
at src/libstd/sys_common/backtrace.rs:50
8: 0x56540f40284e - std::panicking::default_hook::{{closure}}::hb9a3113d679899b0
at src/libstd/panicking.rs:188
9: 0x56540f402541 - std::panicking::default_hook::haba400789ba2c5f0
at src/libstd/panicking.rs:205
10: 0x56540f402e9b - std::panicking::rust_panic_with_hook::hf1dd057170b2fcea
at src/libstd/panicking.rs:464
11: 0x56540f3fb1b3 - std::panicking::begin_panic::he6705b84de17ade4
at /rustc/91fd6283e658e2c7aab2d3f5206fc1891f486af2/src/libstd/panicking.rs:400
12: 0x56540f3e9992 - gtk4::auto::functions::is_initialized::he3968962883b7744
at /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/auto/functions.rs:333
13: 0x56540f3e8ed7 - gtk4::rt::init::h7aeefe6a0a29e070
at /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/rt.rs:97
14: 0x56540f3ea203 - gtk4::application::<impl gtk4::auto::application::Application>::new::h51ba65495792adae
at /home/bilelmoussaoui/.cargo/git/checkouts/gtk4-200dfd804dd04253/d29b0d8/src/application.rs:12
15: 0x56540f3e7a16 - basic::main::h475eff658a69716b
at src/bin/basic.rs:31
16: 0x56540f3e5d20 - std::rt::lang_start::{{closure}}::h27829dcc20b89d0f
at /rustc/91fd6283e658e2c7aab2d3f5206fc1891f486af2/src/libstd/rt.rs:61
17: 0x56540f402913 - std::rt::lang_start_internal::{{closure}}::hefa3bdc6af77c7a5
at src/libstd/rt.rs:48
18: 0x56540f402913 - std::panicking::try::do_call::h1fdd22ace65aadbc
at src/libstd/panicking.rs:287
19: 0x56540f40411a - __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:83
20: 0x56540f40337d - std::panicking::try::hfb89dbe42a15da49
at src/libstd/panicking.rs:265
21: 0x56540f40337d - std::panic::catch_unwind::hf2d0ee7f8aef5e8d
at src/libstd/panic.rs:396
22: 0x56540f40337d - std::rt::lang_start_internal::ha3597cbe02c510ac
at src/libstd/rt.rs:47
23: 0x56540f3e5cf9 - std::rt::lang_start::h82983fdaabb50d4e
at /rustc/91fd6283e658e2c7aab2d3f5206fc1891f486af2/src/libstd/rt.rs:61
24: 0x56540f3e7b2a - main
25: 0x7f897a5841a3 - __libc_start_main
26: 0x56540f3e51fe - _start
27: 0x0 - <unknown>
Expect some other issues and hopefully pull requests to fix them :)
It's a fundamental type and needs manual bindings for itself and all its subclasses. See glib::ParamSpec
for another example like that.
This should probably become a fn get_layout_type() -> glib::Type
on the trait that is queried exactly once in override_vfuncs()
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.