diff --git a/Cargo.lock b/Cargo.lock index e33a02b..606fbc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2332,7 +2332,7 @@ dependencies = [ [[package]] name = "iced" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "iced_core", "iced_futures", @@ -2346,7 +2346,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "bitflags 2.6.0", "bytes", @@ -2365,7 +2365,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "async-std", "futures", @@ -2379,7 +2379,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "bitflags 2.6.0", "bytemuck", @@ -2398,7 +2398,7 @@ dependencies = [ [[package]] name = "iced_highlighter" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "iced_core", "once_cell", @@ -2408,7 +2408,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2420,7 +2420,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "bytes", "iced_core", @@ -2432,7 +2432,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "bytemuck", "cosmic-text", @@ -2448,7 +2448,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "bitflags 2.6.0", "bytemuck", @@ -2468,7 +2468,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "iced_highlighter", "iced_renderer", @@ -2486,7 +2486,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.13.0-dev" -source = "git+https://github.com/iced-rs/iced?branch=master#dcdf1307006883f50083c186ca7b8656bfa60873" +source = "git+https://github.com/iced-rs/iced?rev=dcdf1307006883f50083c186ca7b8656bfa60873#dcdf1307006883f50083c186ca7b8656bfa60873" dependencies = [ "iced_futures", "iced_graphics", @@ -5430,7 +5430,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.14", + "winnow 0.6.15", ] [[package]] @@ -6907,9 +6907,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374ec40a2d767a3c1b4972d9475ecd557356637be906f2cb3f7fe17a6eb5e22f" +checksum = "557404e450152cd6795bb558bca69e43c585055f4606e3bcae5894fc6dac9ba0" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 0fb91bf..199f286 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,8 +21,8 @@ iced = { git = "https://github.com/iced-rs/iced", features = [ "advanced", "markdown", "highlighter", -], branch = "master" } -iced_runtime = { git = "https://github.com/iced-rs/iced", branch = "master" } +], rev = "dcdf1307006883f50083c186ca7b8656bfa60873" } +iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "dcdf1307006883f50083c186ca7b8656bfa60873" } ngnk = { version = "0.2.3", optional = true } diff --git a/src/main.rs b/src/main.rs index c235119..d6c2c98 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ use crate::widgets::text_input; use utils::keval; use utils::{truncate, HistoryMap, REPL}; use views::pane::{view_pane, Pane}; -use views::toolbar::toolbar_view; +use views::toolbar::Toolbar; pub static INPUT_ID: Lazy = Lazy::new(text_input::Id::unique); static SCROLL_ID: Lazy = Lazy::new(scrollable::Id::unique); @@ -55,6 +55,7 @@ struct State { panes: pane_grid::State, panes_created: usize, focus: Option, + glyphbar: Toolbar, } impl Default for State { @@ -69,6 +70,7 @@ impl Default for State { panes, panes_created: 1, focus: None, + glyphbar: Toolbar::new(), } } } @@ -411,15 +413,15 @@ impl Beacon { tab_at: at, focus, panes, + glyphbar, .. }, ) => { - let glyphbar = toolbar_view(); let tabs = tab_view(outs, *at); let focus = focus; let total_panes = panes.len(); - let pane_grid = PaneGrid::new(&panes, |id, pane, is_maximized| { + let pane_grid = PaneGrid::new(panes, |id, pane, is_maximized| { let is_focused = *focus == Some(id); let pane_outs = outs .0 @@ -430,11 +432,10 @@ impl Beacon { id, total_panes, pane.is_pinned, - &input_value, + input_value, pane_outs, *at, ) - .into() })) .style(if is_focused { style::pane_focused @@ -448,7 +449,7 @@ impl Beacon { .on_click(Message::Clicked) .on_drag(Message::Dragged) .on_resize(10, Message::Resized); - container(column![glyphbar, tabs, pane_grid]) + container(column![glyphbar.view(), tabs, pane_grid]) .width(Length::Fill) .height(Length::Fill) .padding(10) diff --git a/src/utils.rs b/src/utils.rs index 85eec85..fdbfe8f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -12,10 +12,10 @@ pub fn truncate(s: &str, max_chars: usize) -> &str { pub mod macros { macro_rules! bqn386 { ($q:expr) => { - text($q) + iced::widget::text($q) .font(Font::with_name("BQN386 Unicode")) .size(14) - .line_height(LineHeight::Absolute(12.into())) + .line_height(iced::widget::text::LineHeight::Absolute(12.into())) }; } pub(crate) use bqn386; diff --git a/src/views/pane.rs b/src/views/pane.rs index 6f50e2e..bd4c249 100644 --- a/src/views/pane.rs +++ b/src/views/pane.rs @@ -9,9 +9,7 @@ use iced::alignment::Alignment; use iced::widget::{pane_grid, svg}; use iced::{ color, - widget::{ - button, column, container, row, scrollable, text, text::LineHeight, Column, Container, - }, + widget::{button, column, container, row, scrollable, Column, Container}, Element, Font, Length, }; @@ -42,7 +40,7 @@ pub fn view_pane<'a>( ) -> Element<'a, Message> { let inp = text_input::TextInput::new( "", - &input_value + input_value .get(&unsafe { std::mem::transmute::<_, usize>(pane) }) .unwrap_or(&String::new()), ) @@ -133,8 +131,7 @@ pub fn view_pane<'a>( Message::Split(pane_grid::Axis::Horizontal, pane), ), button("vertical", Message::Split(pane_grid::Axis::Vertical, pane),) - ] - .spacing(5); + ]; if total_panes > 1 && !is_pinned { controls = controls.push(button("cross", Message::Close(pane))); } @@ -146,13 +143,8 @@ pub fn view_pane<'a>( .id(SCROLL_ID.clone()), inp ] - .width(Length::Fill) .spacing(10) .align_x(Alignment::Center); - container(content) - .width(Length::Fill) - .height(Length::Fill) - .padding(5) - .into() + container(content).height(Length::Fill).padding(5).into() } diff --git a/src/views/tabs.rs b/src/views/tabs.rs index 194bf16..2dac39b 100644 --- a/src/views/tabs.rs +++ b/src/views/tabs.rs @@ -1,5 +1,5 @@ use iced::{ - widget::{button, row, text, text::LineHeight, Container}, + widget::{button, row, Container}, Element, Font, }; @@ -16,7 +16,7 @@ pub fn tab_view<'a>(outs: &HistoryMap, at: usize) -> Element<'a, Message> { .map(|i| { Container::new( button(if *i == at { - bqn386!(format!("{i}")) + bqn386!(format!("[{i}]")) } else { bqn386!(format!("{i}")) }) @@ -30,6 +30,15 @@ pub fn tab_view<'a>(outs: &HistoryMap, at: usize) -> Element<'a, Message> { text_color: iced::Color::WHITE, ..Default::default() }, + button::Status::Pressed => button::Style { + background: Some(iced::Background::Color(iced::Color::from_rgb( + 12.0 / 255.0, + 12.0 / 255.0, + 12.0 / 255.0, + ))), + text_color: iced::Color::WHITE, + ..Default::default() + }, _ => button::Style { background: Some(iced::Background::Color(iced::Color::from_rgb( 12.0 / 255.0, diff --git a/src/views/toolbar.rs b/src/views/toolbar.rs index 1dd6e71..9a728dd 100644 --- a/src/views/toolbar.rs +++ b/src/views/toolbar.rs @@ -1,15 +1,16 @@ use iced::{ - widget::{button, container, markdown, text, text::LineHeight, tooltip}, - Element, Font, + widget::{ + button, markdown, + tooltip, + }, + Element, Font, Padding, }; use once_cell::sync::Lazy; +use std::collections::HashMap; use crate::{ - docs::content::glyph_to_documentation, - styles::{btnstyle, toolbarstyle}, - utils::macros::bqn386, - widgets::wrap::Wrap, - Message, + docs::content::glyph_to_documentation, styles::btnstyle, utils::macros::bqn386, + widgets::wrap::Wrap, Message, }; static GLYPHS: Lazy<[char; 64]> = Lazy::new(|| { @@ -21,30 +22,54 @@ static GLYPHS: Lazy<[char; 64]> = Lazy::new(|| { ] }); -pub fn toolbar_view<'a>() -> Element<'a, Message> { - container( - GLYPHS +pub struct Toolbar { + items: HashMap>, +} + +impl Toolbar { + pub fn new() -> Self { + let items: HashMap> = GLYPHS .iter() - .fold(Wrap::new(), |wrap, glyph| { - wrap.push( + .map(|&glyph| (glyph, parse_glyph_documentation(glyph))) + .collect(); + + Self { items } + } + + pub fn view(&self) -> Element<'_, Message> { + Wrap::with_elements( + GLYPHS + .iter() + .map(|&glyph| { tooltip( button(bqn386!(glyph)) .style(btnstyle) .on_press(Message::ToolbarClick(glyph.to_string())), - markdown( - markdown::parse( - glyph_to_documentation(*glyph), - iced::theme::Palette::DRACULA, - ), + iced::widget::container(markdown( + &self.items[&glyph], markdown::Settings::default(), - (), - ), + |url| Message::TabNext, + )) + .style(|t| iced::widget::container::Style { + text_color: Some(iced::Color::BLACK), + background: Some(iced::Background::Color(iced::Color::WHITE)), + border: iced::border::rounded(4), + shadow: Default::default(), + }) + .padding(Padding::new(4.0)) + .width(400.0) + .max_height(1000.0), tooltip::Position::FollowCursor, ) - .style(toolbarstyle), - ) - }) - .spacing(1.0), - ) - .into() + .into() + }) + .collect(), + ) + .into() + } } + +fn parse_glyph_documentation(glyph: char) -> Vec { + markdown::parse(glyph_to_documentation(glyph), iced::theme::Palette::DRACULA).collect() +} +