Skip to content

Commit

Permalink
update to latest iced
Browse files Browse the repository at this point in the history
  • Loading branch information
x86y committed Jul 22, 2024
1 parent 61ad52e commit 1ad5ba4
Show file tree
Hide file tree
Showing 12 changed files with 3,916 additions and 2,703 deletions.
3,840 changes: 2,551 additions & 1,289 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ directories-next = "2.0"
cbqn = { version = "0.1.0", default-features=false, optional = true }
phf = "0.11.1"
unicode-segmentation = "1.10.1"
iced = { git = "https://github.com/iced-rs/iced", features = ["async-std", "debug", "lazy", "svg"], rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
iced_core = { git = "https://github.com/iced-rs/iced", rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
iced_style = { git = "https://github.com/iced-rs/iced", rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
iced = { git = "https://github.com/iced-rs/iced", features = ["async-std", "debug", "lazy", "svg", "advanced"], rev = "dcdf1307006883f50083c186ca7b8656bfa60873" }
iced_core = { git = "https://github.com/iced-rs/iced", rev = "dcdf1307006883f50083c186ca7b8656bfa60873" }
iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "dcdf1307006883f50083c186ca7b8656bfa60873" }
# itertools = "0.11.0"
# tracing = "0.1.37"
# tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
Expand Down
118 changes: 53 additions & 65 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
use iced::widget::pane_grid::{self, PaneGrid};
use iced::widget::responsive;
use iced::{
event::{self, Event},
keyboard::{self, Modifiers},
subscription,
widget::{column, container, scrollable, text},
window, Application, Command, Element, Length, Settings, Subscription, Theme,
Element, Length, Subscription, Task as Command, Theme,
};
use iced_runtime::font::load;
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::time::Instant;
use styles::CanvasStyle;
use styles::canvasstyle;
use views::tabs::tab_view;
// use tracing::{event as e, info, instrument, Level};

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

pub fn main() -> iced::Result {
// tracing_subscriber::fmt::init();
Beacon::run(Settings {
window: window::Settings {
size: (430, 800),
..window::Settings::default()
},
..Settings::default()
})
iced::application(Beacon::title, Beacon::update, Beacon::view)
.subscription(Beacon::subscription)
.font(include_bytes!("../assets/BQN386.ttf").as_slice())
.window_size((500.0, 800.0))
.run_with(Beacon::new)
}

enum Beacon {
Expand Down Expand Up @@ -117,13 +112,8 @@ pub enum Message {
CloseFocused,
}

impl Application for Beacon {
type Message = Message;
type Theme = Theme;
type Executor = iced::executor::Default;
type Flags = ();

fn new(_flags: ()) -> (Beacon, Command<Message>) {
impl Beacon {
fn new() -> (Beacon, Command<Message>) {
// let _ = REPL.call1(&libs.to_string().into());
#[cfg(feature = "k")]
ngnk::kinit();
Expand All @@ -135,7 +125,7 @@ impl Application for Beacon {
]),
)
}
fn theme(&self) -> Self::Theme {
fn theme(&self) -> Theme {
Theme::Dark
}

Expand Down Expand Up @@ -187,7 +177,7 @@ impl Application for Beacon {
Message::Split(axis, pane) => {
let result = state
.panes
.split(axis, &pane, Pane::new(state.panes_created));
.split(axis, pane, Pane::new(state.panes_created));

if let Some((pane, _)) = result {
state.focus = Some(pane);
Expand All @@ -201,7 +191,7 @@ impl Application for Beacon {
let result =
state
.panes
.split(axis, &pane, Pane::new(state.panes_created));
.split(axis, pane, Pane::new(state.panes_created));

if let Some((pane, _)) = result {
state.focus = Some(pane);
Expand All @@ -213,7 +203,7 @@ impl Application for Beacon {
}
Message::FocusAdjacent(direction) => {
if let Some(pane) = state.focus {
if let Some(adjacent) = state.panes.adjacent(&pane, direction) {
if let Some(adjacent) = state.panes.adjacent(pane, direction) {
state.focus = Some(adjacent);
}
}
Expand All @@ -224,22 +214,22 @@ impl Application for Beacon {
Command::none()
}
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
state.panes.resize(&split, ratio);
state.panes.resize(split, ratio);
Command::none()
}
Message::Dragged(pane_grid::DragEvent::Dropped { pane, target }) => {
state.panes.drop(&pane, target);
state.panes.drop(pane, target);
Command::none()
}
Message::Dragged(_) => Command::none(),
Message::TogglePin(pane) => {
if let Some(Pane { is_pinned, .. }) = state.panes.get_mut(&pane) {
if let Some(Pane { is_pinned, .. }) = state.panes.get_mut(pane) {
*is_pinned = !*is_pinned;
}
Command::none()
}
Message::Maximize(pane) => {
state.panes.maximize(&pane);
state.panes.maximize(pane);

Command::none()
}
Expand All @@ -248,16 +238,16 @@ impl Application for Beacon {
Command::none()
}
Message::Close(pane) => {
if let Some((_, sibling)) = state.panes.close(&pane) {
if let Some((_, sibling)) = state.panes.close(pane) {
state.focus = Some(sibling);
}
Command::none()
}
Message::CloseFocused => {
if let Some(pane) = state.focus {
if let Some(Pane { is_pinned, .. }) = state.panes.get(&pane) {
if let Some(Pane { is_pinned, .. }) = state.panes.get(pane) {
if !is_pinned {
if let Some((_, sibling)) = state.panes.close(&pane) {
if let Some((_, sibling)) = state.panes.close(pane) {
state.focus = Some(sibling);
}
}
Expand Down Expand Up @@ -446,11 +436,11 @@ impl Application for Beacon {
)
.into()
}))
.style(if is_focused {
style::pane_focused
} else {
style::pane_active
})
.style(if is_focused {
style::pane_focused
} else {
style::pane_active
})
})
.width(Length::Fill)
.height(Length::Fill)
Expand All @@ -462,68 +452,66 @@ impl Application for Beacon {
.width(Length::Fill)
.height(Length::Fill)
.padding(10)
.style(CanvasStyle::theme())
.style(canvasstyle)
.into()
}
}
}

fn subscription(&self) -> Subscription<Message> {
macro_rules! kp {
($kc:pat, $modif:pat) => {
(
Event::Keyboard(keyboard::Event::KeyPressed {
key_code: $kc,
modifiers: $modif,
}),
event::Status::Ignored,
)
};
}
subscription::events_with(|event, status| match (event, status) {
kp!(keyboard::KeyCode::T, Modifiers::CTRL) => Some(Message::TabCreate),
kp!(keyboard::KeyCode::Q, Modifiers::CTRL) => Some(Message::TabClose),
kp!(keyboard::KeyCode::N, Modifiers::CTRL) => Some(Message::TabNext),
kp!(keyboard::KeyCode::P, Modifiers::CTRL) => Some(Message::TabPrev),
kp!(keyboard::KeyCode::L, Modifiers::CTRL) => Some(Message::BufferClear),
(Event::Keyboard(keyboard::Event::CharacterReceived(_)), event::Status::Ignored) => {
Some(Message::InputFocus)
keyboard::on_key_press(|key, modifiers| {
if !modifiers.command() {
return None;
}

match (key.as_ref(), modifiers) {
(keyboard::Key::Character("T"), Modifiers::CTRL) => Some(Message::TabCreate),
(keyboard::Key::Character("Q"), Modifiers::CTRL) => Some(Message::TabClose),
(keyboard::Key::Character("N"), Modifiers::CTRL) => Some(Message::TabNext),
(keyboard::Key::Character("P"), Modifiers::CTRL) => Some(Message::TabPrev),
(keyboard::Key::Character("L"), Modifiers::CTRL) => Some(Message::BufferClear),
_ => None,
}
_ => None,
})
}
}

mod style {
use iced::widget::container;
use iced::Theme;
use iced::Background;
use iced::Color;
use iced::Theme;

pub fn pane_active(theme: &Theme) -> container::Appearance {
pub fn pane_active(theme: &Theme) -> container::Style {
let palette = theme.extended_palette();
container::Appearance {
container::Style {
background: Some(Background::Color(Color::from_rgb(
12.0 / 255.0,
12.0 / 255.0,
12.0 / 255.0,
))),
border_width: 2.0,
border_color: palette.background.strong.color,
border: iced::Border {
width: 0.0,
color: palette.background.strong.color,
radius: 0.0.into(),
},
..Default::default()
}
}

pub fn pane_focused(theme: &Theme) -> container::Appearance {
pub fn pane_focused(theme: &Theme) -> container::Style {
let palette = theme.extended_palette();
container::Appearance {
container::Style {
background: Some(Background::Color(Color::from_rgb(
12.0 / 255.0,
12.0 / 255.0,
12.0 / 255.0,
))),
border_width: 2.0,
border_color: palette.primary.strong.color,
border: iced::Border {
width: 0.0,
color: palette.primary.strong.color,
radius: 0.0.into(),
},
..Default::default()
}
}
Expand Down
Loading

0 comments on commit 1ad5ba4

Please sign in to comment.