@@ -18,10 +18,12 @@ const SCALE: f64 = 64.0;
18
18
const MARGIN : f64 = 2. ;
19
19
const RADIUS : f64 = 4. ;
20
20
21
+ #[ derive( Default ) ]
21
22
pub struct KeyboardLayerInner {
22
23
page : Cell < Page > ,
23
24
keys : OnceCell < Rc < [ Key ] > > ,
24
25
selected : Cell < Option < usize > > ,
26
+ selectable : Cell < bool > ,
25
27
}
26
28
27
29
impl ObjectSubclass for KeyboardLayerInner {
@@ -38,9 +40,8 @@ impl ObjectSubclass for KeyboardLayerInner {
38
40
39
41
fn new ( ) -> Self {
40
42
Self {
41
- page : Cell :: new ( Page :: Layer1 ) ,
42
- keys : OnceCell :: new ( ) ,
43
- selected : Cell :: new ( None ) ,
43
+ selectable : Cell :: new ( true ) ,
44
+ ..Self :: default ( )
44
45
}
45
46
}
46
47
}
@@ -143,6 +144,10 @@ impl WidgetImpl for KeyboardLayerInner {
143
144
fn button_press_event ( & self , widget : & KeyboardLayer , evt : & gdk:: EventButton ) -> Inhibit {
144
145
self . parent_button_press_event ( widget, evt) ;
145
146
147
+ if !self . selectable . get ( ) {
148
+ return Inhibit ( false ) ;
149
+ }
150
+
146
151
let pos = evt. get_position ( ) ;
147
152
for ( i, k) in widget. keys ( ) . iter ( ) . enumerate ( ) {
148
153
let x = ( k. physical . x * SCALE ) + MARGIN ;
@@ -208,4 +213,11 @@ impl KeyboardLayer {
208
213
self . queue_draw ( ) ;
209
214
self . notify ( "selected" ) ;
210
215
}
216
+
217
+ pub fn set_selectable ( & self , selectable : bool ) {
218
+ self . inner ( ) . selectable . set ( selectable) ;
219
+ if !selectable {
220
+ self . set_selected ( None ) ;
221
+ }
222
+ }
211
223
}
0 commit comments