@@ -17,6 +17,8 @@ use std::marker::PhantomData;
1717use std:: pin:: Pin ;
1818use std:: rc:: Rc ;
1919use url:: Url ;
20+ use gtk:: CompositeTemplate ;
21+ use gtk:: TemplateChild ;
2022
2123use crate :: common;
2224use crate :: common:: { glibctx, HistoryItem , LossyTextRead , PageElement , RequestCtx } ;
@@ -32,16 +34,22 @@ pub struct HistoryStatus {
3234pub mod imp {
3335
3436 pub use super :: * ;
35- #[ derive( Debug , Default , Properties ) ]
37+ #[ derive( Debug , Default , Properties , CompositeTemplate ) ]
38+ #[ template( resource = "/com/ranfdev/Geopard/ui/tab.ui" ) ]
3639 #[ properties( wrapper_type = super :: Tab ) ]
3740 pub struct Tab {
3841 pub ( crate ) gemini_client : RefCell < gemini:: Client > ,
3942 pub ( crate ) draw_ctx : RefCell < Option < DrawCtx > > ,
4043 pub ( crate ) history : RefCell < Vec < HistoryItem > > ,
4144 pub ( crate ) current_hi : RefCell < Option < usize > > ,
42- pub ( crate ) scroll_win : gtk:: ScrolledWindow ,
43- pub ( crate ) stack : gtk:: Stack ,
44- pub ( crate ) clamp : adw:: Clamp ,
45+ #[ template_child]
46+ pub ( crate ) scroll_win : TemplateChild < gtk:: ScrolledWindow > ,
47+ #[ template_child]
48+ pub ( crate ) text_view : TemplateChild < gtk:: TextView > ,
49+ #[ template_child]
50+ pub ( crate ) stack : TemplateChild < gtk:: Stack > ,
51+ #[ template_child]
52+ pub ( crate ) clamp : TemplateChild < adw:: Clamp > ,
4553 pub ( crate ) left_click_ctrl : RefCell < Option < gtk:: GestureClick > > ,
4654 pub ( crate ) right_click_ctrl : RefCell < Option < gtk:: GestureClick > > ,
4755 pub ( crate ) motion_ctrl : RefCell < Option < gtk:: EventControllerMotion > > ,
@@ -58,28 +66,22 @@ pub mod imp {
5866
5967 #[ glib:: object_subclass]
6068 impl ObjectSubclass for Tab {
61- const NAME : & ' static str = "GeopardTab " ;
69+ const NAME : & ' static str = "Tab " ;
6270 type Type = super :: Tab ;
63- type ParentType = gtk :: Widget ;
71+ type ParentType = adw :: Bin ;
6472
6573 fn class_init ( klass : & mut Self :: Class ) {
66- // The layout manager determines how child widgets are laid out.
67- klass. set_layout_manager_type :: < gtk:: BinLayout > ( ) ;
74+ Self :: bind_template ( klass) ;
75+ }
76+ fn instance_init ( obj : & glib:: subclass:: InitializingObject < Self > ) {
77+ obj. init_template ( ) ;
6878 }
6979 }
7080
7181 impl ObjectImpl for Tab {
7282 fn constructed ( & self , obj : & Self :: Type ) {
7383 self . parent_constructed ( obj) ;
7484
75- self . scroll_win . set_vexpand ( true ) ;
76- obj. set_vexpand ( true ) ;
77-
78- self . clamp . set_parent ( obj) ;
79- self . clamp . set_maximum_size ( 768 ) ;
80- self . clamp . set_tightening_threshold ( 720 ) ;
81- self . clamp . set_child ( Some ( & self . scroll_win ) ) ;
82-
8385 self . left_click_ctrl
8486 . replace ( Some ( gtk:: GestureClick :: builder ( ) . button ( 1 ) . build ( ) ) ) ;
8587 self . right_click_ctrl
@@ -90,10 +92,6 @@ pub mod imp {
9092 . replace ( gemini:: ClientBuilder :: new ( ) . redirect ( true ) . build ( ) ) ;
9193 }
9294
93- fn dispose ( & self , _obj : & Self :: Type ) {
94- self . clamp . unparent ( ) ;
95- }
96-
9795 fn signals ( ) -> & ' static [ glib:: subclass:: Signal ] {
9896 static SIGNALS : Lazy < Vec < glib:: subclass:: Signal > > = Lazy :: new ( || {
9997 vec ! [ glib:: subclass:: Signal :: builder(
@@ -133,6 +131,7 @@ pub mod imp {
133131 }
134132 }
135133 impl WidgetImpl for Tab { }
134+ impl adw:: subclass:: bin:: BinImpl for Tab { }
136135}
137136glib:: wrapper! {
138137 pub struct Tab ( ObjectSubclass <imp:: Tab >)
@@ -143,33 +142,15 @@ impl Tab {
143142 pub fn new ( config : crate :: config:: Config ) -> Self {
144143 let this: Self = glib:: Object :: new ( & [ ] ) . unwrap ( ) ;
145144 let imp = this. imp ( ) ;
146- use common:: MARGIN ;
147- let text_view = gtk:: builders:: TextViewBuilder :: new ( )
148- . top_margin ( MARGIN * 2 )
149- . left_margin ( MARGIN )
150- . right_margin ( MARGIN )
151- . bottom_margin ( MARGIN * 4 )
152- . indent ( 2 )
153- . editable ( false )
154- . cursor_visible ( false )
155- . wrap_mode ( gtk:: WrapMode :: WordChar )
156- . build ( ) ;
157- text_view. add_controller ( imp. left_click_ctrl . borrow ( ) . as_ref ( ) . unwrap ( ) ) ;
158- text_view. add_controller ( imp. right_click_ctrl . borrow ( ) . as_ref ( ) . unwrap ( ) ) ;
159- text_view. add_controller ( imp. motion_ctrl . borrow ( ) . as_ref ( ) . unwrap ( ) ) ;
160-
161- imp. stack . add_child ( & text_view) ;
162- imp. scroll_win . set_child ( Some ( & imp. stack ) ) ;
163-
164- imp. draw_ctx . replace ( Some ( DrawCtx :: new ( text_view, config) ) ) ;
145+ imp. text_view . add_controller ( imp. left_click_ctrl . borrow ( ) . as_ref ( ) . unwrap ( ) ) ;
146+ imp. text_view . add_controller ( imp. right_click_ctrl . borrow ( ) . as_ref ( ) . unwrap ( ) ) ;
147+ imp. text_view . add_controller ( imp. motion_ctrl . borrow ( ) . as_ref ( ) . unwrap ( ) ) ;
148+
149+ imp. draw_ctx . replace ( Some ( DrawCtx :: new ( imp. text_view . clone ( ) , config) ) ) ;
165150
166151 this. bind_signals ( ) ;
167152 this
168153 }
169- pub fn child ( & self ) -> & gtk:: ScrolledWindow {
170- let imp = self . imp ( ) ;
171- & imp. scroll_win
172- }
173154 fn build_request_ctx ( & self , url : Url ) -> RequestCtx {
174155 let imp = self . imp ( ) ;
175156 RequestCtx {
0 commit comments