3
3
use iced:: widget:: pane_grid:: { self , PaneGrid } ;
4
4
use iced:: widget:: responsive;
5
5
use iced:: {
6
- event:: { self , Event } ,
7
6
keyboard:: { self , Modifiers } ,
8
- subscription,
9
7
widget:: { column, container, scrollable, text} ,
10
- window , Application , Command , Element , Length , Settings , Subscription , Theme ,
8
+ Element , Length , Subscription , Task as Command , Theme ,
11
9
} ;
12
10
use iced_runtime:: font:: load;
13
11
use once_cell:: sync:: Lazy ;
14
12
use std:: collections:: HashMap ;
15
13
use std:: time:: Instant ;
16
- use styles:: CanvasStyle ;
14
+ use styles:: canvasstyle ;
17
15
use views:: tabs:: tab_view;
18
- // use tracing::{event as e, info, instrument, Level};
19
16
20
17
mod docs;
21
18
mod save;
@@ -37,13 +34,11 @@ static SCROLL_ID: Lazy<scrollable::Id> = Lazy::new(scrollable::Id::unique);
37
34
38
35
pub fn main ( ) -> iced:: Result {
39
36
// tracing_subscriber::fmt::init();
40
- Beacon :: run ( Settings {
41
- window : window:: Settings {
42
- size : ( 430 , 800 ) ,
43
- ..window:: Settings :: default ( )
44
- } ,
45
- ..Settings :: default ( )
46
- } )
37
+ iced:: application ( Beacon :: title, Beacon :: update, Beacon :: view)
38
+ . subscription ( Beacon :: subscription)
39
+ . font ( include_bytes ! ( "../assets/BQN386.ttf" ) . as_slice ( ) )
40
+ . window_size ( ( 500.0 , 800.0 ) )
41
+ . run_with ( Beacon :: new)
47
42
}
48
43
49
44
enum Beacon {
@@ -117,13 +112,8 @@ pub enum Message {
117
112
CloseFocused ,
118
113
}
119
114
120
- impl Application for Beacon {
121
- type Message = Message ;
122
- type Theme = Theme ;
123
- type Executor = iced:: executor:: Default ;
124
- type Flags = ( ) ;
125
-
126
- fn new ( _flags : ( ) ) -> ( Beacon , Command < Message > ) {
115
+ impl Beacon {
116
+ fn new ( ) -> ( Beacon , Command < Message > ) {
127
117
// let _ = REPL.call1(&libs.to_string().into());
128
118
#[ cfg( feature = "k" ) ]
129
119
ngnk:: kinit ( ) ;
@@ -135,7 +125,7 @@ impl Application for Beacon {
135
125
] ) ,
136
126
)
137
127
}
138
- fn theme ( & self ) -> Self :: Theme {
128
+ fn theme ( & self ) -> Theme {
139
129
Theme :: Dark
140
130
}
141
131
@@ -187,7 +177,7 @@ impl Application for Beacon {
187
177
Message :: Split ( axis, pane) => {
188
178
let result = state
189
179
. panes
190
- . split ( axis, & pane, Pane :: new ( state. panes_created ) ) ;
180
+ . split ( axis, pane, Pane :: new ( state. panes_created ) ) ;
191
181
192
182
if let Some ( ( pane, _) ) = result {
193
183
state. focus = Some ( pane) ;
@@ -201,7 +191,7 @@ impl Application for Beacon {
201
191
let result =
202
192
state
203
193
. panes
204
- . split ( axis, & pane, Pane :: new ( state. panes_created ) ) ;
194
+ . split ( axis, pane, Pane :: new ( state. panes_created ) ) ;
205
195
206
196
if let Some ( ( pane, _) ) = result {
207
197
state. focus = Some ( pane) ;
@@ -213,7 +203,7 @@ impl Application for Beacon {
213
203
}
214
204
Message :: FocusAdjacent ( direction) => {
215
205
if let Some ( pane) = state. focus {
216
- if let Some ( adjacent) = state. panes . adjacent ( & pane, direction) {
206
+ if let Some ( adjacent) = state. panes . adjacent ( pane, direction) {
217
207
state. focus = Some ( adjacent) ;
218
208
}
219
209
}
@@ -224,22 +214,22 @@ impl Application for Beacon {
224
214
Command :: none ( )
225
215
}
226
216
Message :: Resized ( pane_grid:: ResizeEvent { split, ratio } ) => {
227
- state. panes . resize ( & split, ratio) ;
217
+ state. panes . resize ( split, ratio) ;
228
218
Command :: none ( )
229
219
}
230
220
Message :: Dragged ( pane_grid:: DragEvent :: Dropped { pane, target } ) => {
231
- state. panes . drop ( & pane, target) ;
221
+ state. panes . drop ( pane, target) ;
232
222
Command :: none ( )
233
223
}
234
224
Message :: Dragged ( _) => Command :: none ( ) ,
235
225
Message :: TogglePin ( pane) => {
236
- if let Some ( Pane { is_pinned, .. } ) = state. panes . get_mut ( & pane) {
226
+ if let Some ( Pane { is_pinned, .. } ) = state. panes . get_mut ( pane) {
237
227
* is_pinned = !* is_pinned;
238
228
}
239
229
Command :: none ( )
240
230
}
241
231
Message :: Maximize ( pane) => {
242
- state. panes . maximize ( & pane) ;
232
+ state. panes . maximize ( pane) ;
243
233
244
234
Command :: none ( )
245
235
}
@@ -248,16 +238,16 @@ impl Application for Beacon {
248
238
Command :: none ( )
249
239
}
250
240
Message :: Close ( pane) => {
251
- if let Some ( ( _, sibling) ) = state. panes . close ( & pane) {
241
+ if let Some ( ( _, sibling) ) = state. panes . close ( pane) {
252
242
state. focus = Some ( sibling) ;
253
243
}
254
244
Command :: none ( )
255
245
}
256
246
Message :: CloseFocused => {
257
247
if let Some ( pane) = state. focus {
258
- if let Some ( Pane { is_pinned, .. } ) = state. panes . get ( & pane) {
248
+ if let Some ( Pane { is_pinned, .. } ) = state. panes . get ( pane) {
259
249
if !is_pinned {
260
- if let Some ( ( _, sibling) ) = state. panes . close ( & pane) {
250
+ if let Some ( ( _, sibling) ) = state. panes . close ( pane) {
261
251
state. focus = Some ( sibling) ;
262
252
}
263
253
}
@@ -446,11 +436,11 @@ impl Application for Beacon {
446
436
)
447
437
. into ( )
448
438
} ) )
449
- . style ( if is_focused {
450
- style:: pane_focused
451
- } else {
452
- style:: pane_active
453
- } )
439
+ . style ( if is_focused {
440
+ style:: pane_focused
441
+ } else {
442
+ style:: pane_active
443
+ } )
454
444
} )
455
445
. width ( Length :: Fill )
456
446
. height ( Length :: Fill )
@@ -462,68 +452,66 @@ impl Application for Beacon {
462
452
. width ( Length :: Fill )
463
453
. height ( Length :: Fill )
464
454
. padding ( 10 )
465
- . style ( CanvasStyle :: theme ( ) )
455
+ . style ( canvasstyle )
466
456
. into ( )
467
457
}
468
458
}
469
459
}
470
460
471
461
fn subscription ( & self ) -> Subscription < Message > {
472
- macro_rules! kp {
473
- ( $kc: pat, $modif: pat) => {
474
- (
475
- Event :: Keyboard ( keyboard:: Event :: KeyPressed {
476
- key_code: $kc,
477
- modifiers: $modif,
478
- } ) ,
479
- event:: Status :: Ignored ,
480
- )
481
- } ;
482
- }
483
- subscription:: events_with ( |event, status| match ( event, status) {
484
- kp ! ( keyboard:: KeyCode :: T , Modifiers :: CTRL ) => Some ( Message :: TabCreate ) ,
485
- kp ! ( keyboard:: KeyCode :: Q , Modifiers :: CTRL ) => Some ( Message :: TabClose ) ,
486
- kp ! ( keyboard:: KeyCode :: N , Modifiers :: CTRL ) => Some ( Message :: TabNext ) ,
487
- kp ! ( keyboard:: KeyCode :: P , Modifiers :: CTRL ) => Some ( Message :: TabPrev ) ,
488
- kp ! ( keyboard:: KeyCode :: L , Modifiers :: CTRL ) => Some ( Message :: BufferClear ) ,
489
- ( Event :: Keyboard ( keyboard:: Event :: CharacterReceived ( _) ) , event:: Status :: Ignored ) => {
490
- Some ( Message :: InputFocus )
462
+ keyboard:: on_key_press ( |key, modifiers| {
463
+ if !modifiers. command ( ) {
464
+ return None ;
465
+ }
466
+
467
+ match ( key. as_ref ( ) , modifiers) {
468
+ ( keyboard:: Key :: Character ( "T" ) , Modifiers :: CTRL ) => Some ( Message :: TabCreate ) ,
469
+ ( keyboard:: Key :: Character ( "Q" ) , Modifiers :: CTRL ) => Some ( Message :: TabClose ) ,
470
+ ( keyboard:: Key :: Character ( "N" ) , Modifiers :: CTRL ) => Some ( Message :: TabNext ) ,
471
+ ( keyboard:: Key :: Character ( "P" ) , Modifiers :: CTRL ) => Some ( Message :: TabPrev ) ,
472
+ ( keyboard:: Key :: Character ( "L" ) , Modifiers :: CTRL ) => Some ( Message :: BufferClear ) ,
473
+ _ => None ,
491
474
}
492
- _ => None ,
493
475
} )
494
476
}
495
477
}
496
478
497
479
mod style {
498
480
use iced:: widget:: container;
499
- use iced:: Theme ;
500
481
use iced:: Background ;
501
482
use iced:: Color ;
483
+ use iced:: Theme ;
502
484
503
- pub fn pane_active ( theme : & Theme ) -> container:: Appearance {
485
+ pub fn pane_active ( theme : & Theme ) -> container:: Style {
504
486
let palette = theme. extended_palette ( ) ;
505
- container:: Appearance {
487
+ container:: Style {
506
488
background : Some ( Background :: Color ( Color :: from_rgb (
507
489
12.0 / 255.0 ,
508
490
12.0 / 255.0 ,
509
491
12.0 / 255.0 ,
510
492
) ) ) ,
511
- border_width : 2.0 ,
512
- border_color : palette. background . strong . color ,
493
+ border : iced:: Border {
494
+ width : 0.0 ,
495
+ color : palette. background . strong . color ,
496
+ radius : 0.0 . into ( ) ,
497
+ } ,
513
498
..Default :: default ( )
514
499
}
515
500
}
516
501
517
- pub fn pane_focused ( theme : & Theme ) -> container:: Appearance {
502
+ pub fn pane_focused ( theme : & Theme ) -> container:: Style {
518
503
let palette = theme. extended_palette ( ) ;
519
- container:: Appearance {
504
+ container:: Style {
520
505
background : Some ( Background :: Color ( Color :: from_rgb (
521
506
12.0 / 255.0 ,
522
507
12.0 / 255.0 ,
523
508
12.0 / 255.0 ,
524
509
) ) ) ,
525
- border_width : 2.0 ,
526
- border_color : palette. primary . strong . color ,
510
+ border : iced:: Border {
511
+ width : 0.0 ,
512
+ color : palette. primary . strong . color ,
513
+ radius : 0.0 . into ( ) ,
514
+ } ,
527
515
..Default :: default ( )
528
516
}
529
517
}
0 commit comments