Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Add RadioToolButton #584

Merged
merged 3 commits into from Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions Gir.toml
Expand Up @@ -1162,6 +1162,27 @@ status = "generate"
name = "group"
ignore = true

[[object]]
name = "Gtk.RadioToolButton"
status = "generate"
[[object.function]]
pattern = ".+_from_widget"
[[object.function.parameter]]
name = "group"
nullable = false
[[object.function]]
name = "new"
ignore = true
[[object.function]]
name = "new_from_stock"
ignore = true
[[object.function]]
name = "set_group"
ignore = true
[[object.property]]
name = "group"
ignore = true

[[object]]
name = "Gtk.Range"
status = "generate"
Expand Down
5 changes: 5 additions & 0 deletions src/auto/mod.rs
Expand Up @@ -522,6 +522,10 @@ mod radio_menu_item;
pub use self::radio_menu_item::RadioMenuItem;
pub use self::radio_menu_item::RadioMenuItemExt;

mod radio_tool_button;
pub use self::radio_tool_button::RadioToolButton;
pub use self::radio_tool_button::RadioToolButtonExt;

mod range;
pub use self::range::Range;
pub use self::range::RangeExt;
Expand Down Expand Up @@ -1059,6 +1063,7 @@ pub mod traits {
pub use super::ProgressBarExt;
pub use super::RadioButtonExt;
pub use super::RadioMenuItemExt;
pub use super::RadioToolButtonExt;
pub use super::RangeExt;
pub use super::RecentChooserExt;
pub use super::RecentFilterExt;
Expand Down
55 changes: 55 additions & 0 deletions src/auto/radio_tool_button.rs
@@ -0,0 +1,55 @@
// This file was generated by gir (0fe730d) from gir-files (db49619)
// DO NOT EDIT

use Actionable;
use Bin;
use Container;
use RadioButton;
use ToggleToolButton;
use ToolButton;
use ToolItem;
use Widget;
use ffi;
use glib::object::Downcast;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
pub struct RadioToolButton(Object<ffi::GtkRadioToolButton>): ToggleToolButton, ToolButton, ToolItem, Bin, Container, Widget, Actionable;

match fn {
get_type => || ffi::gtk_radio_tool_button_get_type(),
}
}

impl RadioToolButton {
pub fn new_from_widget(group: &RadioToolButton) -> RadioToolButton {
skip_assert_initialized!();
unsafe {
ToolItem::from_glib_none(ffi::gtk_radio_tool_button_new_from_widget(group.to_glib_none().0)).downcast_unchecked()
}
}

pub fn new_with_stock_from_widget(group: &RadioToolButton, stock_id: &str) -> RadioToolButton {
skip_assert_initialized!();
unsafe {
ToolItem::from_glib_none(ffi::gtk_radio_tool_button_new_with_stock_from_widget(group.to_glib_none().0, stock_id.to_glib_none().0)).downcast_unchecked()
}
}
}

pub trait RadioToolButtonExt {
fn get_group(&self) -> Vec<RadioButton>;
}

impl<O: IsA<RadioToolButton>> RadioToolButtonExt for O {
fn get_group(&self) -> Vec<RadioButton> {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::gtk_radio_tool_button_get_group(self.to_glib_none().0))
}
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -215,6 +215,7 @@ mod message_dialog;
mod notebook;
mod radio_button;
mod radio_menu_item;
mod radio_tool_button;
mod recent_chooser_dialog;
mod recent_data;
mod requisition;
Expand Down
23 changes: 23 additions & 0 deletions src/radio_tool_button.rs
@@ -0,0 +1,23 @@
use std::ptr;

use RadioToolButton;
use ToolItem;
use ffi;
use glib::object::Downcast;
use glib::translate::*;

impl RadioToolButton {
pub fn new() -> RadioToolButton {
assert_initialized_main_thread!();
unsafe {
ToolItem::from_glib_none(ffi::gtk_radio_tool_button_new(ptr::null_mut())).downcast_unchecked()
Copy link
Member

Choose a reason for hiding this comment

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

Why ToolItem and not RadioToolButton? And generally, you can just use from_glib_none and let the compiler figure out the right implementation

Copy link
Member

Choose a reason for hiding this comment

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

Oh good catch, didn't see it at all...

Copy link
Member

Choose a reason for hiding this comment

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

It because says Gtk-3.0.gir:

        <return-value transfer-ownership="none">
          <doc xml:space="preserve">The new #GtkRadioToolButton</doc>
          <type name="ToolItem" c:type="GtkToolItem*"/>
        </return-value>

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 thought it would be best to be consistent with what gets auto-generated for similar functions, even if it does not really make a difference how one calls from_glib_none.

}
}

pub fn new_from_stock(stock_id: &str) -> RadioToolButton {
assert_initialized_main_thread!();
unsafe {
ToolItem::from_glib_none(ffi::gtk_radio_tool_button_new_from_stock(ptr::null_mut(), stock_id.to_glib_none().0)).downcast_unchecked()
Copy link
Member

Choose a reason for hiding this comment

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

This one is deprecated since 3.10, maybe let's not add it? Docs say that gtk_radio_tool_button_new() should be used instead.

Also it probably makes sense to expose something for the weird groups API it provides? IIRC we already have the same problem with other group API elsewhere in GTK ( @GuillaumeGomez you remember? ) so let's take inspiration from there.

Copy link
Member

Choose a reason for hiding this comment

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

I don't recall which at all. :-/

Copy link
Member

Choose a reason for hiding this comment

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

@EPashkin Maybe? Some other RadioWhatever API (the plain RadioButton? RadioMenuItems?) where you have groups of things. I don't have time for looking closer now and GTK UI stuff is not really my main area of expertise so I would have to look up, sorry :)

Copy link
Member

Choose a reason for hiding this comment

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

You meant #488?
Problem with this class that it don't have join_group function but it has group property that maybe works same and better deignored.
I will check this PR more later.

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 actually missed that the from_stock functions are deprecated. I can remove them if you want. I am fine either way.

For the group API, I will try to implement what @EPashkin proposed below. At the moment one has to use one of the new_from_widget functions.

}
}
}