@@ -547,7 +547,7 @@ pub fn get_widget_for_value(
547547 . sensitive ( readwrite)
548548 . visible ( true )
549549 . halign ( gtk:: Align :: Start )
550- . valign ( gtk:: Align :: Start )
550+ . valign ( gtk:: Align :: Center )
551551 . use_alpha ( true )
552552 . show_editor ( true )
553553 . build ( ) ;
@@ -828,3 +828,78 @@ pub fn new_property_window(
828828 w. set_child ( Some ( & scrolled_window) ) ;
829829 w
830830}
831+
832+ #[ derive( Default , Debug ) ]
833+ pub struct PropertyChoiceInner {
834+ pub btn : OnceCell < gtk:: RadioButton > ,
835+ pub widget : OnceCell < gtk:: Widget > ,
836+ }
837+
838+ #[ glib:: object_subclass]
839+ impl ObjectSubclass for PropertyChoiceInner {
840+ const NAME : & ' static str = "PropertyChoice" ;
841+ type Type = PropertyChoice ;
842+ type ParentType = gtk:: Box ;
843+ }
844+
845+ impl ObjectImpl for PropertyChoiceInner {
846+ fn constructed ( & self , obj : & Self :: Type ) {
847+ self . parent_constructed ( obj) ;
848+ obj. upcast_ref :: < gtk:: Box > ( )
849+ . set_orientation ( gtk:: Orientation :: Horizontal ) ;
850+ obj. set_spacing ( 1 ) ;
851+ obj. set_expand ( false ) ;
852+ obj. set_visible ( true ) ;
853+ obj. set_can_focus ( true ) ;
854+ }
855+ }
856+
857+ impl WidgetImpl for PropertyChoiceInner { }
858+ impl ContainerImpl for PropertyChoiceInner { }
859+ impl BoxImpl for PropertyChoiceInner { }
860+
861+ glib:: wrapper! {
862+ pub struct PropertyChoice ( ObjectSubclass <PropertyChoiceInner >)
863+ @extends gtk:: Widget , gtk:: Container , gtk:: Box ;
864+ }
865+
866+ impl PropertyChoice {
867+ pub fn new ( label : & str , btn : gtk:: RadioButton , widget : gtk:: Widget ) -> Self {
868+ let ret: PropertyChoice = glib:: Object :: new ( & [ ] ) . unwrap ( ) ;
869+ let label = gtk:: Label :: builder ( )
870+ . label ( label)
871+ . visible ( true )
872+ . selectable ( false )
873+ . max_width_chars ( 30 )
874+ . halign ( gtk:: Align :: Start )
875+ . wrap ( true )
876+ . expand ( false )
877+ . build ( ) ;
878+ let event_box = gtk:: EventBox :: builder ( )
879+ . events ( gtk:: gdk:: EventMask :: BUTTON_PRESS_MASK )
880+ . above_child ( true )
881+ . child ( & label)
882+ . visible ( true )
883+ . build ( ) ;
884+ ret. pack_start ( & event_box, false , false , 5 ) ;
885+ ret. pack_start ( & btn, false , false , 5 ) ;
886+ ret. pack_start ( & widget, false , false , 5 ) ;
887+ btn. bind_property ( "active" , & widget, "sensitive" )
888+ . flags ( glib:: BindingFlags :: SYNC_CREATE )
889+ . build ( ) ;
890+ event_box. connect_button_press_event ( clone ! ( @weak btn => @default -return Inhibit ( false ) , move |_, event| {
891+ if event. button( ) == gtk:: gdk:: BUTTON_PRIMARY && event. event_type( ) == gtk:: gdk:: EventType :: ButtonPress {
892+ btn. set_active( true ) ;
893+ }
894+ Inhibit ( false )
895+ } ) ) ;
896+ ret. btn . set ( btn) . unwrap ( ) ;
897+ ret
898+ }
899+
900+ pub fn button ( & self ) -> & gtk:: RadioButton {
901+ self . btn . get ( ) . unwrap ( )
902+ }
903+ }
904+
905+ impl_deref ! ( PropertyChoice , PropertyChoiceInner ) ;
0 commit comments