GithubHelp home page GithubHelp logo

gtk-rs / gtk4-rs Goto Github PK

View Code? Open in Web Editor NEW
1.8K 16.0 168.0 129.94 MB

Rust bindings of GTK 4

Home Page: https://gtk-rs.org/gtk4-rs/

License: MIT License

Rust 97.46% C 2.53% Dockerfile 0.01% CSS 0.01%
gtk4 gtk4-rs gsk4 gdk4 gdk4-wayland gdk4-x11 gtk4-macros gtk-rs

gtk4-rs's Introduction

gtk3-rs CI

This project is UNMAINTAINED. Please take a look at gtk4-rs instead!

The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries. You can find more about it on https://gtk-rs.org.

This repository contains all the "core" crates of the gtk-rs organization. For more information about each crate, please refer to their README.md file in their directory.

Minimum supported Rust version

Currently, the minimum supported Rust version is 1.70.0.

Documentation

Ecosystem

The gtk3-rs repository contains Rust crates for GTK 3. However there is a large ecosystem of GObject libraries and many of these libraries have Rust bindings based on the tooling included in gtk-rs. Of particular note:

  • gtk-rs-core - bindings for some of the core libraries such as glib, gio, pango, graphene
  • gstreamer-rs - bindings for the GStreamer media framework

Additionally, Rust bindings for various libraries are hosted on GNOME's GitLab instance and can be found at https://gitlab.gnome.org/World/Rust.

When using crates that are not part of the gtk-rs repository, you will need to be careful and ensure that they do not pull in incompatible versions of core crates like glib-rs.

Regenerating

To regenerate crates using gir, please use the generator.py file as follows:

$ python3 generator.py

If you didn't do so yet, please check out all the submodules before via

$ git submodule update --checkout

Development

This repository is mostly split into two branches: master and crate. master contains the not yet released code and is where new developments are happening. crate contains the last release source code and isn't supposed to be updated.

This repository is structured as follows:

- crate/
   |
   |-- README.md
   |-- Gir.toml
   |-- Cargo.toml
   |-- src/
   |-- sys/

The crate is a "top" directory (so "atk" or "gdk" in here for example). Each crate contains:

  • README.md: explanations about the crate itself and eventually some details.
  • Cargo.toml: descriptor of the crate, used by cargo and Rust.
  • Gir.toml: configuration used by gir to generate most of the crates' code.
  • src: the source code of the crate.
  • sys: the 1:1 bindings of the C API.

The gir and gir-files top folders are not crates, but are git submodules which respectively contain the gir tool and the gir files used by the generator.

When running generator.py the tool will automatically update these git submodules and run the gir tool on the gir files to regenerate the code.

During development, it is useful to execute the generator with a different version of the gir tool or of the gir files, for instance to test if the code generation is successful before submitting a pull request to update one of the submodules. This can be done by specifying arguments to the generator script, for instance, to run the generator on a local copy of the gir files:

$ python3 generator.py --gir-files-directory ../gir-files/

See python3 generator.py --help for more details.

gtk4-rs's People

Contributors

a6gibkm avatar aaronerhardt avatar alatiera avatar bilelmoussaoui avatar brainblasted avatar cogitri avatar dependabot[bot] avatar dns2utf8 avatar elmarco avatar epashkin avatar erwinschrodinger1 avatar fengalin avatar guillaumegomez avatar hofer-julian avatar jf2048 avatar lucab avatar marijns95 avatar pbor avatar ranfdev avatar realkc avatar sdroege avatar seadve avatar sfanxiang avatar sophie-h avatar vamsikrishna-brahmajosyula avatar wroyca avatar yalter avatar yuraiz avatar zecakeh avatar zekefast avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gtk4-rs's Issues

Keep gtk::DialogExt::run() as async variant

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?

Merge gtk4 crates

Currently there's the following gtk4 specific crates

  • gtk4/gtk4-sys
  • gdk4/gdk4-sys
  • gsk4/gsk4-sys
  • gdk4x11/gdk4x11-sys (to be generated)
  • gdk4wayland/gdk4wayland-sys (to be generated)
  • examples4

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:

  • Regenerating the bindings for a new gtk4 release would be much easier than having to check the status in 6 (once all created) repositories
  • Simplify maintaince

cc @sdroege @GuillaumeGomez

Code generation for composite templates

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:

  • Compile time checking of UI files, if a field is missing or has the wrong type your code would not compile
  • Less code to be written and maintained.

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

WidgetExt::iter() for children?

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?

GTK fails to init

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 :)

Panic when parent's Widget::compute_expand() virtual method is not implemented in subclass

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>

Some of events like `connect_button_press_event` not exist GTK4 all widgets receive all events

In 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: &gtk::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<_>>());
}

Disambiguate set_name (again)

    |                 ^^^^^^^^ 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`

Add missing WidgetClass methods

  • 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 C only, for language bindings, we should use #24
  • 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

Misleading license info

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".

Subclassing support: virtual methods

Here's a list of Classes/Interfaces along with their associate virtual methods

  • GtkAccessibleTextInterface
  • Actionable - get_action_name
  • Actionable - get_action_target_value
  • Actionable - set_action_name
  • Actionable - set_action_target_value
  • Adjustment - changed
  • Adjustment - value_changed
  • Buildable - add_child
  • Buildable - construct_child
  • Buildable - custom_finished
  • Buildable - custom_tag_end
  • Buildable - custom_tag_start
  • Buildable - get_id
  • Buildable - get_internal_child
  • Buildable - parser_finished
  • Buildable - set_buildable_property
  • Buildable - set_id
  • BuilderScope - create_closure
  • BuilderScope - get_type_from_function
  • BuilderScope - get_type_from_name
  • Button - activate
  • Button - clicked
  • CellArea - activate
  • CellArea - add
  • CellArea - apply_attributes
  • CellArea - copy_context
  • CellArea - create_context
  • CellArea - event
  • CellArea - focus
  • CellArea - foreach_alloc
  • CellArea - foreach
  • CellArea - get_cell_property
  • CellArea - get_preferred_height_for_width
  • CellArea - get_preferred_height
  • CellArea - get_preferred_width_for_height
  • CellArea - get_preferred_width
  • CellArea - get_request_mode
  • CellArea - is_activatable
  • CellArea - remove
  • CellArea - set_cell_property
  • CellArea - snapshot
  • CellAreaContext - allocate
  • CellAreaContext - get_preferred_height_for_width
  • CellAreaContext - get_preferred_width_for_height
  • CellAreaContext - reset
  • CellEditable - editing_done
  • CellEditable - remove_widget
  • CellEditable - start_editing
  • CellLayout - add_attribute
  • CellLayout - clear_attributes
  • CellLayout - clear
  • CellLayout - get_area
  • CellLayout - get_cells
  • CellLayout - pack_end
  • CellLayout - pack_start
  • CellLayout - reorder
  • CellLayout - set_cell_data_func
  • CellRenderer - activate
  • CellRenderer - editing_canceled
  • CellRenderer - editing_started
  • CellRenderer - get_aligned_area
  • CellRenderer - get_preferred_height_for_width
  • CellRenderer - get_preferred_height
  • CellRenderer - get_preferred_width_for_height
  • CellRenderer - get_preferred_width
  • CellRenderer - get_request_mode
  • CellRenderer - get_size
  • CellRenderer - snapshot
  • CellRenderer - start_editing
  • CellRendererText - edited
  • CheckButton - toggled
  • ColorChooser - add_palette
  • ColorChooser - color_activated
  • ColorChooser - get_rgba
  • ColorChooser - set_rgba
  • ComboBox - changed
  • ComboBox - format_entry_text
  • DrawingArea - resize
  • Editable - changed
  • Editable - delete_text
  • Editable - do_delete_text
  • Editable - do_insert_text
  • Editable - get_selection_bounds
  • Editable - get_text
  • Editable - insert_text
  • Editable - set_selection_bounds
  • Entry - activate
  • EntryBuffer - delete_text
  • EntryBuffer - deleted_text
  • EntryBuffer - get_length
  • EntryBuffer - get_text
  • EntryBuffer - insert_text
  • EntryBuffer - inserted_text
  • Filter - get_strictness
  • Filter - match
  • FlowBoxChild - activate
  • FontChooser - font_activated
  • FontChooser - get_font_face
  • FontChooser - get_font_family
  • FontChooser - get_font_map
  • FontChooser - get_font_size
  • FontChooser - set_filter_func
  • FontChooser - set_font_map
  • Frame - compute_child_allocation
  • GLArea - create_context
  • GLArea - render
  • GLArea - resize
  • IMContext - commit
  • IMContext - delete_surrounding
  • IMContext - filter_keypress
  • IMContext - focus_in
  • IMContext - focus_out
  • IMContext - get_preedit_string
  • IMContext - get_surrounding
  • IMContext - preedit_changed
  • IMContext - preedit_end
  • IMContext - preedit_start
  • IMContext - reset
  • IMContext - retrieve_surrounding
  • IMContext - set_client_widget
  • IMContext - set_cursor_location
  • IMContext - set_surrounding
  • IMContext - set_use_preedit
  • LayoutManager - allocate
  • LayoutManager - create_layout_child
  • LayoutManager - get_request_mode
  • LayoutManager - measure
  • LayoutManager - root
  • LayoutManager - unroot
  • ListBoxRow - activate
  • MediaFile - close
  • MediaFile - open
  • MediaStream - pause
  • MediaStream - play
  • MediaStream - realize
  • MediaStream - seek
  • MediaStream - unrealize
  • MediaStream - update_audio
  • NativeDialog - hide
  • NativeDialog - response
  • NativeDialog - show
  • Popover - activate_default
  • Popover - closed
  • PrintOperation - begin_print
  • PrintOperation - create_custom_widget
  • PrintOperation - custom_widget_apply
  • PrintOperation - done
  • PrintOperation - draw_page
  • PrintOperation - end_print
  • PrintOperation - paginate
  • PrintOperation - preview
  • PrintOperation - request_page_setup
  • PrintOperation - status_changed
  • PrintOperation - update_custom_widget
  • PrintOperationPreview - end_preview
  • PrintOperationPreview - got_page_size
  • PrintOperationPreview - is_selected
  • PrintOperationPreview - ready
  • PrintOperationPreview - render_page
  • Range - adjust_bounds
  • Range - change_value
  • Range - get_range_border
  • Range - move_slider
  • Range - value_changed
  • RecentManager - changed
  • Scale - get_layout_offsets
  • ScaleButton - value_changed
  • Scrollable - get_border
  • SelectionModel - get_selection_in_range
  • SelectionModel - is_selected
  • SelectionModel - select_all
  • SelectionModel - select_item
  • SelectionModel - select_range
  • SelectionModel - set_selection
  • SelectionModel - unselect_all
  • SelectionModel - unselect_item
  • SelectionModel - unselect_range
  • ShortcutManager - add_controller
  • ShortcutManager - remove_controller
  • Sorter - compare
  • Sorter - get_order
  • StyleContext - changed
  • TextBuffer - apply_tag
  • TextBuffer - begin_user_action
  • TextBuffer - changed
  • TextBuffer - delete_range
  • TextBuffer - end_user_action
  • TextBuffer - insert_child_anchor
  • TextBuffer - insert_paintable
  • TextBuffer - insert_text
  • TextBuffer - mark_deleted
  • TextBuffer - mark_set
  • TextBuffer - modified_changed
  • TextBuffer - paste_done
  • TextBuffer - redo
  • TextBuffer - remove_tag
  • TextBuffer - undo
  • TextView - backspace
  • TextView - copy_clipboard
  • TextView - create_buffer
  • TextView - cut_clipboard
  • TextView - delete_from_cursor
  • TextView - extend_selection
  • TextView - insert_at_cursor
  • TextView - insert_emoji
  • TextView - move_cursor
  • TextView - paste_clipboard
  • TextView - set_anchor
  • TextView - snapshot_layer
  • TextView - toggle_overwrite
  • ToggleButton - toggled
  • TreeDragDest - drag_data_received
  • TreeDragDest - row_drop_possible
  • TreeDragSource - drag_data_delete
  • TreeDragSource - drag_data_get
  • TreeDragSource - row_draggable
  • TreeModel - get_column_type
  • TreeModel - get_flags
  • TreeModel - get_iter
  • TreeModel - get_n_columns
  • TreeModel - get_path
  • TreeModel - get_value
  • TreeModel - iter_children
  • TreeModel - iter_has_child
  • TreeModel - iter_n_children
  • TreeModel - iter_next
  • TreeModel - iter_nth_child
  • TreeModel - iter_parent
  • TreeModel - iter_previous
  • TreeModel - ref_node
  • TreeModel - row_changed
  • TreeModel - row_deleted
  • TreeModel - row_has_child_toggled
  • TreeModel - row_inserted
  • TreeModel - rows_reordered
  • TreeModel - unref_node
  • TreeModelFilter - modify
  • TreeModelFilter - visible
  • TreeSortable - get_sort_column_id
  • TreeSortable - has_default_sort_func
  • TreeSortable - set_default_sort_func
  • TreeSortable - set_sort_column_id
  • TreeSortable - set_sort_func
  • TreeSortable - sort_column_changed
  • TreeView - columns_changed
  • TreeView - cursor_changed
  • TreeView - expand_collapse_cursor_row
  • TreeView - move_cursor
  • TreeView - row_activated
  • TreeView - row_collapsed
  • TreeView - row_expanded
  • TreeView - select_all
  • TreeView - select_cursor_parent
  • TreeView - select_cursor_row
  • TreeView - start_interactive_search
  • TreeView - test_collapse_row
  • TreeView - test_expand_row
  • TreeView - toggle_cursor_row
  • TreeView - unselect_all
  • Widget - contains
  • Widget - css_changed
  • Widget - focus
  • Widget - get_request_mode
  • Widget - grab_focus
  • Widget - hide
  • Widget - keynav_failed
  • Widget - map
  • Widget - measure
  • Widget - mnemonic_activate
  • Widget - move_focus
  • Widget - query_tooltip
  • Widget - realize
  • Widget - root
  • Widget - set_focus_child
  • Widget - show
  • Widget - size_allocate
  • Widget - snapshot
  • Widget - state_flags_changed
  • Widget - system_setting_changed
  • Widget - unmap
  • Widget - unrealize
  • Widget - unroot
  • Application - window_added
  • Application - window_removed
  • Dialog - close
  • Dialog - response
  • Widget - compute_expand
  • Widget - direction_changed
  • Window - activate_default
  • Window - activate_focus
  • Window - close_request
  • Window - enable_debugging
  • Window - keys_changed

gdk:

  • ContentProvider - attach_clipboard
  • ContentProvider - content_changed
  • ContentProvider - detach_clipboard
  • ContentProvider - get_value
  • ContentProvider - ref_formats
  • ContentProvider - ref_storable_formats
  • ContentProvider - write_mime_type_async
  • ContentProvider - write_mime_type_finish
  • Paintable - get_current_image
  • Paintable - get_flags
  • Paintable - get_intrinsic_aspect_ratio
  • Paintable - get_intrinsic_height
  • Paintable - get_intrinsic_width
  • Paintable - snapshot

FileChooserNativeBuilder drops the filters

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);

setup on fedora required code changes

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?

Application subclass does not initialize GTK

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

Remnants For Composite Template Support

After #51 is merged, there's still some work left to do:

  • Find a way to use the CompositeTemplate trait's bind_template_children fn
    as klass.bind_template_children()
  • Find a way to handle instance_init() so that init_template() can be called
    from it.
  • Add support for signals/callbacks in templates

Cleanup & provide a README for all the crates

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

Figure out how to use Gtk.BuilderScope

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?

ConstraintLayout::add_constraints_from_description() is missing

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
            );

Using custom widgets in ui templates

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.

get_xdisplay() is missing from gdk4-x11::X11Display

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

the basic.rs example in my crate does not compile,but in gtk4-rs crate compile

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]$

Forgetting to add #[template_child] to TemplateChild members leads to runtime crashes when accessing the member

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

Port C examples

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.

TreeStore: manually implement remove

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>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.