Skip to content

Commit

Permalink
bump iced to 0.13.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Redhawk18 committed Jul 18, 2024
1 parent bf5f7a1 commit 8bbffa0
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 835 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kuiper_gui.workspace = true
tokio.workspace = true
pretty_env_logger.workspace = true

[dev.dependencies]
[dev-dependencies]
console-subscriber = "0.3.0"

[workspace]
Expand All @@ -31,9 +31,8 @@ kuiper_lsp = { path = "lsp" }

async-lsp = { version = "0.2", features = ["tokio"] }
dark-light = "1.0"
iced = { version = "0.12", features = ["advanced", "tokio"] }
iced_aw = { version = "0.8", features = ["icons", "menu","tab_bar"], default-features = false }
iced_runtime = "0.12"
iced = { version = "0.13.0-dev", features = ["advanced", "tokio"] }
iced_aw = { version = "0.9", features = ["icons", "tab_bar"], default-features = false }
jsonrpc = "0.17.0"
log = "0.4"
pattern_code = "0.1"
Expand All @@ -46,4 +45,5 @@ tokio-util = { version = "0.7", features = ["compat"] }
tower = "0.4"

[patch.crates-io]
iced_aw = { git = 'https:/iced-rs/iced_aw.git', rev = '99c12f1' }
iced = { git = 'https:/iced-rs/iced.git' }
iced_aw = { git = 'https:/iced-rs/iced_aw.git' }
3 changes: 1 addition & 2 deletions gui/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::widgets::Content;

use iced::widget::text_editor::Content;
use std::path::PathBuf;

#[derive(Debug)]
Expand Down
143 changes: 70 additions & 73 deletions gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ mod widgets;

use buffer::{Buffer, FileBuffer};
pub use messages::{Button, LanguageServer, Message, PaneGrid, Tab, TextEditor, Widgets};
use widgets::{menu_bar, pane_grid, Content};
use widgets::{menu_bar, pane_grid};

use kuiper_lsp::{
client::LSPClient,
commands::{initialize, synchronize},
};

use iced::{
executor, font,
application, font,
widget::{
column,
pane_grid::{DragEvent, Pane, ResizeEvent, State},
text_editor::Content,
},
Application, Command, Element, Settings, Theme,
Element, Task, Theme,
};
use slotmap::{DefaultKey, SlotMap};
use std::path::PathBuf;

pub fn start_gui() -> iced::Result {
Kuiper::run(Settings::default())
application(Kuiper::title, Kuiper::update, Kuiper::view)
.theme(Kuiper::theme)
.run_with(Kuiper::new)
}

pub struct Kuiper {
Expand All @@ -50,68 +53,15 @@ pub struct PaneState {
}

impl Kuiper {
pub(crate) fn get_panestate(&self) -> &PaneState {
self.panes.data.get(self.panes.active).unwrap()
}

pub(crate) fn get_mut_panestate(&mut self) -> &mut PaneState {
self.panes.data.get_mut(self.panes.active).unwrap()
}

pub(crate) fn get_buffer(&self) -> Option<&Buffer> {
let panestate = self.get_panestate();
match panestate.data.get(panestate.active_tab_index) {
Some(key) => Some(self.data.get(*key).unwrap()),
None => None,
}
}

pub(crate) fn get_mut_buffer(&mut self) -> Option<&mut Buffer> {
let panestate = self.get_panestate();
match panestate.get_active_key() {
Some(key) => Some(self.data.get_mut(*key).unwrap()),
None => None,
}
}

pub(crate) fn insert_buffer(&mut self, buffer: Buffer) {
let key = self.data.insert(buffer);
self.get_mut_panestate().data.push(key);
}
}

impl PaneState {
pub fn get_active_key(&self) -> Option<&DefaultKey> {
self.data.get(self.active_tab_index)
}

pub fn get_data<'a>(&'a self, map: &'a SlotMap<DefaultKey, Buffer>) -> Vec<&Buffer> {
self.data.iter().map(|key| map.get(*key).unwrap()).collect()
}

pub fn with_key(key: &DefaultKey) -> Self {
PaneState {
data: vec![*key],
..Default::default()
}
}
}

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

fn new(_flags: Self::Flags) -> (Self, Command<Self::Message>) {
fn new() -> (Self, Task<Message>) {
(
Kuiper {
data: SlotMap::default(),
lsp_client: None,
panes: Panes::default(),
workspace_folder: None,
},
Command::batch(vec![
Task::batch(vec![
font::load(iced_aw::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded),
font::load(iced_aw::NERD_FONT_BYTES).map(Message::FontLoaded),
]),
Expand All @@ -122,14 +72,14 @@ impl Application for Kuiper {
String::from("Kuiper")
}

fn update(&mut self, message: Message) -> Command<Message> {
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::FontLoaded(_) => {}
Message::LanguageServer(lsp) => match lsp {
LanguageServer::Initalize(result) => {
let Ok(server) = result else {
log::error!("Error initializing language server");
return Command::none();
return Task::none();
};

self.lsp_client = Some(LSPClient::new(server));
Expand All @@ -141,45 +91,45 @@ impl Application for Kuiper {
Widgets::Button(button) => match button {
Button::NewFile => self.insert_buffer(Buffer::File(FileBuffer::default())),
Button::OpenFile => {
return Command::perform(file_dialog::open_file(), |x| {
return Task::perform(file_dialog::open_file(), |x| {
Message::Widgets(Widgets::Button(Button::OpenedFile(x)))
});
}
Button::OpenedFile(result) => {
let Ok(file) = result else {
return Command::none();
return Task::none();
};

self.insert_buffer(Buffer::File(FileBuffer {
path: Some(file.0),
content: Content::with_text(&file.1),
}));

return Command::perform(initialize(), |x| {
return Task::perform(initialize(), |x| {
Message::LanguageServer(LanguageServer::Initalize(x))
});
}
Button::OpenFolder => {
return Command::perform(file_dialog::open_folder(), |x| {
return Task::perform(file_dialog::open_folder(), |x| {
Message::Widgets(Widgets::Button(Button::OpenedFolder(x)))
})
}
Button::OpenedFolder(result) => {
let Ok(folder) = result else {
return Command::none();
return Task::none();
};

self.workspace_folder = Some(folder);
}
Button::Save => {
let Some(buffer) = self.get_buffer() else {
log::warn!("No file open to save");
return Command::none();
return Task::none();
};

match buffer {
Buffer::File(file_buffer) => {
return Command::perform(
return Task::perform(
file_dialog::save_file(
file_buffer.path.clone(),
file_buffer.content.text(),
Expand All @@ -193,12 +143,12 @@ impl Application for Kuiper {
Button::SaveAs => {
let Some(buffer) = self.get_buffer() else {
log::warn!("No file open to save");
return Command::none();
return Task::none();
};

match buffer {
Buffer::File(file_buffer) => {
return Command::perform(
return Task::perform(
file_dialog::save_file_with_dialog(
file_buffer.path.clone(),
file_buffer.content.text(),
Expand All @@ -209,7 +159,8 @@ impl Application for Kuiper {
}
}
Button::SavedAs(_) => {}
Button::Quit => return iced::window::close(iced::window::Id::MAIN),
// Button::Quit => return iced::window::close(0),
Button::Quit => todo!(),
},
Widgets::PaneGrid(pane_grid) => match pane_grid {
PaneGrid::PaneClicked(pane) => self.panes.active = pane,
Expand Down Expand Up @@ -262,7 +213,7 @@ impl Application for Kuiper {
Buffer::File(buffer) => {
buffer.content.perform(action);
let path = buffer.path.clone().unwrap();
return Command::perform(
return Task::perform(
synchronize(path, self.lsp_client.clone().unwrap().socket),
|x| Message::LanguageServer(LanguageServer::Syncronize(x)),
);
Expand All @@ -273,7 +224,7 @@ impl Application for Kuiper {
},
}

Command::none()
Task::none()
}

fn view(&self) -> Element<Message> {
Expand All @@ -285,6 +236,52 @@ impl Application for Kuiper {
fn theme(&self) -> Theme {
Theme::GruvboxDark
}

pub(crate) fn get_buffer(&self) -> Option<&Buffer> {
let panestate = self.get_panestate();
match panestate.data.get(panestate.active_tab_index) {
Some(key) => Some(self.data.get(*key).unwrap()),
None => None,
}
}

pub(crate) fn get_mut_buffer(&mut self) -> Option<&mut Buffer> {
let panestate = self.get_panestate();
match panestate.get_active_key() {
Some(key) => Some(self.data.get_mut(*key).unwrap()),
None => None,
}
}

pub(crate) fn get_panestate(&self) -> &PaneState {
self.panes.data.get(self.panes.active).unwrap()
}

pub(crate) fn get_mut_panestate(&mut self) -> &mut PaneState {
self.panes.data.get_mut(self.panes.active).unwrap()
}

pub(crate) fn insert_buffer(&mut self, buffer: Buffer) {
let key = self.data.insert(buffer);
self.get_mut_panestate().data.push(key);
}
}

impl PaneState {
pub fn get_active_key(&self) -> Option<&DefaultKey> {
self.data.get(self.active_tab_index)
}

pub fn get_data<'a>(&self, map: &'a SlotMap<DefaultKey, Buffer>) -> Vec<&'a Buffer> {
self.data.iter().map(|key| map.get(*key).unwrap()).collect()
}

pub fn with_key(key: &DefaultKey) -> Self {
PaneState {
data: vec![*key],
..Default::default()
}
}
}

impl Default for Panes {
Expand Down
16 changes: 8 additions & 8 deletions gui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use iced::{Border, Theme};
const WIDTH: f32 = 2.0;
const RADIUS: f32 = 4.0;

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(palette.background.base.color.into()),
border: Border {
color: palette.background.strong.color,
Expand All @@ -18,10 +18,10 @@ pub fn pane_active(theme: &Theme) -> container::Appearance {
}
}

pub fn pane_inactive(theme: &Theme) -> container::Appearance {
pub fn pane_inactive(theme: &Theme) -> container::Style {
let palette = theme.extended_palette();

container::Appearance {
container::Style {
background: Some(palette.background.base.color.into()),
border: Border {
color: palette.background.strong.color,
Expand All @@ -32,20 +32,20 @@ pub fn pane_inactive(theme: &Theme) -> container::Appearance {
}
}

pub fn title_bar_active(theme: &Theme) -> container::Appearance {
pub fn title_bar_active(theme: &Theme) -> container::Style {
let palette = theme.extended_palette();

container::Appearance {
container::Style {
text_color: Some(palette.background.strong.text),
background: Some(palette.background.strong.color.into()),
..Default::default()
}
}

pub fn title_bar_inactive(theme: &Theme) -> container::Appearance {
pub fn title_bar_inactive(theme: &Theme) -> container::Style {
let palette = theme.extended_palette();

container::Appearance {
container::Style {
text_color: Some(palette.primary.strong.text),
background: Some(palette.primary.strong.color.into()),
..Default::default()
Expand Down
2 changes: 0 additions & 2 deletions gui/src/widgets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod menu_bar;
mod pane_grid;
mod tab_bar;
mod text_editor;

pub(crate) use menu_bar::menu_bar;
pub(crate) use pane_grid::pane_grid;
pub(crate) use tab_bar::tab_bar;
pub(crate) use text_editor::{Content, TextEditor};
Loading

0 comments on commit 8bbffa0

Please sign in to comment.