Skip to content
New issue

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

Add gtk::ColumnView "data grid" example #1111

Merged
merged 1 commit into from Sep 10, 2022
Merged

Add gtk::ColumnView "data grid" example #1111

merged 1 commit into from Sep 10, 2022

Conversation

cmdcolin
Copy link
Contributor

Hi there,
I wanted to create a data grid style app as a learning experience. struggled with it for awhile as I'm very new to both gtk and rust, so not sure if I got all the idiomatic usage correct, but I thought it could be useful for others to have an example for the gtk::ColumnView. It adapts from the listview applications launcher a bit, so some code similarities there

I used a tip from gtk-rs/gtk-rs-core#757 as a starter

Let me know if I can add any more details

@Hofer-Julian
Copy link
Collaborator

Haven’t checked the code yet, but I see that the screenshot shows that you don’t use the GTK default theme. That is something we require for our screenshots IIRC.

@cmdcolin
Copy link
Contributor Author

not sure if this is the true GTK default theme but I used gnome tweaks to make "Adwaita (default)" for the screenshot now

examples/column_view_datagrid/main.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/main.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/main.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/grid_cell/mod.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/grid_cell/grid_cell.ui Outdated Show resolved Hide resolved
examples/column_view_datagrid/grid_cell/grid_cell.ui Outdated Show resolved Hide resolved
@cmdcolin
Copy link
Contributor Author

cmdcolin commented Sep 1, 2022

thanks all, this is great feedback. I'll try to incorporate

@cmdcolin
Copy link
Contributor Author

cmdcolin commented Sep 2, 2022

might be ready for re-review

@cmdcolin
Copy link
Contributor Author

cmdcolin commented Sep 6, 2022

just as a random add on, I am sure more features could be added onto this example if there is interest in showing off more features of columnview but the basic example could be helpful to get people started.

if there are ideas about the extending the scope this example should have, let me know

examples/column_view_datagrid/grid_cell/imp.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/grid_cell/mod.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/main.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/main.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/main.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/grid_cell/imp.rs Outdated Show resolved Hide resolved
examples/column_view_datagrid/grid_cell/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@bilelmoussaoui bilelmoussaoui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise lgtm, thanks!

<interface>
<template class="GridCell" parent="GtkWidget">
<child>
<object class="GtkLabel" id="name">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be replaced with a GtkInscription btw.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting an error trying to use "gtk::Inscription" in the imp file (mentioned here #1111 (comment)), not sure if that is what it is called?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to modify https://github.com/gtk-rs/gtk4-rs/blob/master/examples/Cargo.toml#L15-L17 and add features = ["v4_8"] to opt-in for the new gtk 4.8 features. If it doesn't build locally, then it means you have an older gtk version installed which is fine as the example would work fine in the CI. You can add some comment saying, you can use a plain gtk::Label for gtk < 4.8 and point to the docs for Inscription type that explains why it is a good alternative to gtk::Label sometimes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thanks. I went ahead and pushed this

examples/column_view_datagrid/grid_cell/imp.rs Outdated Show resolved Hide resolved
@bilelmoussaoui
Copy link
Member

sorry for being very picky but one last change and we can land it. If you can squash all the commits into one, that would be awesome.

Add screenshot

Update examples/column_view_datagrid/grid_cell/mod.rs

Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com>

Update examples/column_view_datagrid/grid_cell/grid_cell.ui

Co-authored-by: Marco Melorio <marco.melorio@protonmail.com>

Just use a Gtk::Label in the gridcell

Subclass plain Gtk::Widget instead of Gtk::Box xref '#1111 (comment)'

Add dispose function

Append a bunch of items

Add note

Update examples/column_view_datagrid/grid_cell/imp.rs

Co-authored-by: Marco Melorio <marco.melorio@protonmail.com>

Update examples/column_view_datagrid/grid_cell/mod.rs

Co-authored-by: Marco Melorio <marco.melorio@protonmail.com>

Update examples/column_view_datagrid/grid_cell/imp.rs

Co-authored-by: Marco Melorio <marco.melorio@protonmail.com>

Rename to set_entry

Rename some variables and remove outer Gtk.Box

Fix lint

Update examples/column_view_datagrid/grid_cell/imp.rs

Co-authored-by: Bilal Elmoussaoui <belmouss@redhat.com>

Update to use gtk::Inscription instead of gtk::Label
@cmdcolin
Copy link
Contributor Author

cmdcolin commented Sep 10, 2022

no worries, I appreciate the good code review! I made that change now

possibly as a follow up PR, we could add more features to this example. I am experimenting with how a user interacts with the columnview currently e.g. with the connect_activate method, MultiSelection with the Bitset+BitsetIterator, maybe adding right click context menu, etc.

@bilelmoussaoui bilelmoussaoui merged commit 7cb33b0 into gtk-rs:master Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants