Skip to content

Commit 1ad5ba4

Browse files
committed
update to latest iced
1 parent 61ad52e commit 1ad5ba4

File tree

12 files changed

+3916
-2703
lines changed

12 files changed

+3916
-2703
lines changed

Cargo.lock

+2,551-1,289
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ directories-next = "2.0"
1313
cbqn = { version = "0.1.0", default-features=false, optional = true }
1414
phf = "0.11.1"
1515
unicode-segmentation = "1.10.1"
16-
iced = { git = "https://github.com/iced-rs/iced", features = ["async-std", "debug", "lazy", "svg"], rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
17-
iced_core = { git = "https://github.com/iced-rs/iced", rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
18-
iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
19-
iced_style = { git = "https://github.com/iced-rs/iced", rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
16+
iced = { git = "https://github.com/iced-rs/iced", features = ["async-std", "debug", "lazy", "svg", "advanced"], rev = "dcdf1307006883f50083c186ca7b8656bfa60873" }
17+
iced_core = { git = "https://github.com/iced-rs/iced", rev = "dcdf1307006883f50083c186ca7b8656bfa60873" }
18+
iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "dcdf1307006883f50083c186ca7b8656bfa60873" }
2019
# itertools = "0.11.0"
2120
# tracing = "0.1.37"
2221
# tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }

src/main.rs

+53-65
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
use iced::widget::pane_grid::{self, PaneGrid};
44
use iced::widget::responsive;
55
use iced::{
6-
event::{self, Event},
76
keyboard::{self, Modifiers},
8-
subscription,
97
widget::{column, container, scrollable, text},
10-
window, Application, Command, Element, Length, Settings, Subscription, Theme,
8+
Element, Length, Subscription, Task as Command, Theme,
119
};
1210
use iced_runtime::font::load;
1311
use once_cell::sync::Lazy;
1412
use std::collections::HashMap;
1513
use std::time::Instant;
16-
use styles::CanvasStyle;
14+
use styles::canvasstyle;
1715
use views::tabs::tab_view;
18-
// use tracing::{event as e, info, instrument, Level};
1916

2017
mod docs;
2118
mod save;
@@ -37,13 +34,11 @@ static SCROLL_ID: Lazy<scrollable::Id> = Lazy::new(scrollable::Id::unique);
3734

3835
pub fn main() -> iced::Result {
3936
// 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)
4742
}
4843

4944
enum Beacon {
@@ -117,13 +112,8 @@ pub enum Message {
117112
CloseFocused,
118113
}
119114

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>) {
127117
// let _ = REPL.call1(&libs.to_string().into());
128118
#[cfg(feature = "k")]
129119
ngnk::kinit();
@@ -135,7 +125,7 @@ impl Application for Beacon {
135125
]),
136126
)
137127
}
138-
fn theme(&self) -> Self::Theme {
128+
fn theme(&self) -> Theme {
139129
Theme::Dark
140130
}
141131

@@ -187,7 +177,7 @@ impl Application for Beacon {
187177
Message::Split(axis, pane) => {
188178
let result = state
189179
.panes
190-
.split(axis, &pane, Pane::new(state.panes_created));
180+
.split(axis, pane, Pane::new(state.panes_created));
191181

192182
if let Some((pane, _)) = result {
193183
state.focus = Some(pane);
@@ -201,7 +191,7 @@ impl Application for Beacon {
201191
let result =
202192
state
203193
.panes
204-
.split(axis, &pane, Pane::new(state.panes_created));
194+
.split(axis, pane, Pane::new(state.panes_created));
205195

206196
if let Some((pane, _)) = result {
207197
state.focus = Some(pane);
@@ -213,7 +203,7 @@ impl Application for Beacon {
213203
}
214204
Message::FocusAdjacent(direction) => {
215205
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) {
217207
state.focus = Some(adjacent);
218208
}
219209
}
@@ -224,22 +214,22 @@ impl Application for Beacon {
224214
Command::none()
225215
}
226216
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
227-
state.panes.resize(&split, ratio);
217+
state.panes.resize(split, ratio);
228218
Command::none()
229219
}
230220
Message::Dragged(pane_grid::DragEvent::Dropped { pane, target }) => {
231-
state.panes.drop(&pane, target);
221+
state.panes.drop(pane, target);
232222
Command::none()
233223
}
234224
Message::Dragged(_) => Command::none(),
235225
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) {
237227
*is_pinned = !*is_pinned;
238228
}
239229
Command::none()
240230
}
241231
Message::Maximize(pane) => {
242-
state.panes.maximize(&pane);
232+
state.panes.maximize(pane);
243233

244234
Command::none()
245235
}
@@ -248,16 +238,16 @@ impl Application for Beacon {
248238
Command::none()
249239
}
250240
Message::Close(pane) => {
251-
if let Some((_, sibling)) = state.panes.close(&pane) {
241+
if let Some((_, sibling)) = state.panes.close(pane) {
252242
state.focus = Some(sibling);
253243
}
254244
Command::none()
255245
}
256246
Message::CloseFocused => {
257247
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) {
259249
if !is_pinned {
260-
if let Some((_, sibling)) = state.panes.close(&pane) {
250+
if let Some((_, sibling)) = state.panes.close(pane) {
261251
state.focus = Some(sibling);
262252
}
263253
}
@@ -446,11 +436,11 @@ impl Application for Beacon {
446436
)
447437
.into()
448438
}))
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+
})
454444
})
455445
.width(Length::Fill)
456446
.height(Length::Fill)
@@ -462,68 +452,66 @@ impl Application for Beacon {
462452
.width(Length::Fill)
463453
.height(Length::Fill)
464454
.padding(10)
465-
.style(CanvasStyle::theme())
455+
.style(canvasstyle)
466456
.into()
467457
}
468458
}
469459
}
470460

471461
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,
491474
}
492-
_ => None,
493475
})
494476
}
495477
}
496478

497479
mod style {
498480
use iced::widget::container;
499-
use iced::Theme;
500481
use iced::Background;
501482
use iced::Color;
483+
use iced::Theme;
502484

503-
pub fn pane_active(theme: &Theme) -> container::Appearance {
485+
pub fn pane_active(theme: &Theme) -> container::Style {
504486
let palette = theme.extended_palette();
505-
container::Appearance {
487+
container::Style {
506488
background: Some(Background::Color(Color::from_rgb(
507489
12.0 / 255.0,
508490
12.0 / 255.0,
509491
12.0 / 255.0,
510492
))),
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+
},
513498
..Default::default()
514499
}
515500
}
516501

517-
pub fn pane_focused(theme: &Theme) -> container::Appearance {
502+
pub fn pane_focused(theme: &Theme) -> container::Style {
518503
let palette = theme.extended_palette();
519-
container::Appearance {
504+
container::Style {
520505
background: Some(Background::Color(Color::from_rgb(
521506
12.0 / 255.0,
522507
12.0 / 255.0,
523508
12.0 / 255.0,
524509
))),
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+
},
527515
..Default::default()
528516
}
529517
}

0 commit comments

Comments
 (0)