Skip to content

Commit 655802b

Browse files
committed
add markdown tooltips
1 parent 8bc9167 commit 655802b

File tree

7 files changed

+90
-63
lines changed

7 files changed

+90
-63
lines changed

Cargo.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ iced = { git = "https://github.com/iced-rs/iced", features = [
2121
"advanced",
2222
"markdown",
2323
"highlighter",
24-
], branch = "master" }
25-
iced_runtime = { git = "https://github.com/iced-rs/iced", branch = "master" }
24+
], rev = "dcdf1307006883f50083c186ca7b8656bfa60873" }
25+
iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "dcdf1307006883f50083c186ca7b8656bfa60873" }
2626
ngnk = { version = "0.2.3", optional = true }
2727

2828

src/main.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::widgets::text_input;
2727
use utils::keval;
2828
use utils::{truncate, HistoryMap, REPL};
2929
use views::pane::{view_pane, Pane};
30-
use views::toolbar::toolbar_view;
30+
use views::toolbar::Toolbar;
3131

3232
pub static INPUT_ID: Lazy<text_input::Id> = Lazy::new(text_input::Id::unique);
3333
static SCROLL_ID: Lazy<scrollable::Id> = Lazy::new(scrollable::Id::unique);
@@ -55,6 +55,7 @@ struct State {
5555
panes: pane_grid::State<Pane>,
5656
panes_created: usize,
5757
focus: Option<pane_grid::Pane>,
58+
glyphbar: Toolbar,
5859
}
5960

6061
impl Default for State {
@@ -69,6 +70,7 @@ impl Default for State {
6970
panes,
7071
panes_created: 1,
7172
focus: None,
73+
glyphbar: Toolbar::new(),
7274
}
7375
}
7476
}
@@ -411,15 +413,15 @@ impl Beacon {
411413
tab_at: at,
412414
focus,
413415
panes,
416+
glyphbar,
414417
..
415418
},
416419
) => {
417-
let glyphbar = toolbar_view();
418420
let tabs = tab_view(outs, *at);
419421

420422
let focus = focus;
421423
let total_panes = panes.len();
422-
let pane_grid = PaneGrid::new(&panes, |id, pane, is_maximized| {
424+
let pane_grid = PaneGrid::new(panes, |id, pane, is_maximized| {
423425
let is_focused = *focus == Some(id);
424426
let pane_outs = outs
425427
.0
@@ -430,11 +432,10 @@ impl Beacon {
430432
id,
431433
total_panes,
432434
pane.is_pinned,
433-
&input_value,
435+
input_value,
434436
pane_outs,
435437
*at,
436438
)
437-
.into()
438439
}))
439440
.style(if is_focused {
440441
style::pane_focused
@@ -448,7 +449,7 @@ impl Beacon {
448449
.on_click(Message::Clicked)
449450
.on_drag(Message::Dragged)
450451
.on_resize(10, Message::Resized);
451-
container(column![glyphbar, tabs, pane_grid])
452+
container(column![glyphbar.view(), tabs, pane_grid])
452453
.width(Length::Fill)
453454
.height(Length::Fill)
454455
.padding(10)

src/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ pub fn truncate(s: &str, max_chars: usize) -> &str {
1212
pub mod macros {
1313
macro_rules! bqn386 {
1414
($q:expr) => {
15-
text($q)
15+
iced::widget::text($q)
1616
.font(Font::with_name("BQN386 Unicode"))
1717
.size(14)
18-
.line_height(LineHeight::Absolute(12.into()))
18+
.line_height(iced::widget::text::LineHeight::Absolute(12.into()))
1919
};
2020
}
2121
pub(crate) use bqn386;

src/views/pane.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use iced::alignment::Alignment;
99
use iced::widget::{pane_grid, svg};
1010
use iced::{
1111
color,
12-
widget::{
13-
button, column, container, row, scrollable, text, text::LineHeight, Column, Container,
14-
},
12+
widget::{button, column, container, row, scrollable, Column, Container},
1513
Element, Font, Length,
1614
};
1715

@@ -42,7 +40,7 @@ pub fn view_pane<'a>(
4240
) -> Element<'a, Message> {
4341
let inp = text_input::TextInput::new(
4442
"",
45-
&input_value
43+
input_value
4644
.get(&unsafe { std::mem::transmute::<_, usize>(pane) })
4745
.unwrap_or(&String::new()),
4846
)
@@ -133,8 +131,7 @@ pub fn view_pane<'a>(
133131
Message::Split(pane_grid::Axis::Horizontal, pane),
134132
),
135133
button("vertical", Message::Split(pane_grid::Axis::Vertical, pane),)
136-
]
137-
.spacing(5);
134+
];
138135
if total_panes > 1 && !is_pinned {
139136
controls = controls.push(button("cross", Message::Close(pane)));
140137
}
@@ -146,13 +143,8 @@ pub fn view_pane<'a>(
146143
.id(SCROLL_ID.clone()),
147144
inp
148145
]
149-
.width(Length::Fill)
150146
.spacing(10)
151147
.align_x(Alignment::Center);
152148

153-
container(content)
154-
.width(Length::Fill)
155-
.height(Length::Fill)
156-
.padding(5)
157-
.into()
149+
container(content).height(Length::Fill).padding(5).into()
158150
}

src/views/tabs.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use iced::{
2-
widget::{button, row, text, text::LineHeight, Container},
2+
widget::{button, row, Container},
33
Element, Font,
44
};
55

@@ -16,7 +16,7 @@ pub fn tab_view<'a>(outs: &HistoryMap, at: usize) -> Element<'a, Message> {
1616
.map(|i| {
1717
Container::new(
1818
button(if *i == at {
19-
bqn386!(format!("{i}"))
19+
bqn386!(format!("[{i}]"))
2020
} else {
2121
bqn386!(format!("{i}"))
2222
})
@@ -30,6 +30,15 @@ pub fn tab_view<'a>(outs: &HistoryMap, at: usize) -> Element<'a, Message> {
3030
text_color: iced::Color::WHITE,
3131
..Default::default()
3232
},
33+
button::Status::Pressed => button::Style {
34+
background: Some(iced::Background::Color(iced::Color::from_rgb(
35+
12.0 / 255.0,
36+
12.0 / 255.0,
37+
12.0 / 255.0,
38+
))),
39+
text_color: iced::Color::WHITE,
40+
..Default::default()
41+
},
3342
_ => button::Style {
3443
background: Some(iced::Background::Color(iced::Color::from_rgb(
3544
12.0 / 255.0,

src/views/toolbar.rs

+50-25
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use iced::{
2-
widget::{button, container, markdown, text, text::LineHeight, tooltip},
3-
Element, Font,
2+
widget::{
3+
button, markdown,
4+
tooltip,
5+
},
6+
Element, Font, Padding,
47
};
58
use once_cell::sync::Lazy;
9+
use std::collections::HashMap;
610

711
use crate::{
8-
docs::content::glyph_to_documentation,
9-
styles::{btnstyle, toolbarstyle},
10-
utils::macros::bqn386,
11-
widgets::wrap::Wrap,
12-
Message,
12+
docs::content::glyph_to_documentation, styles::btnstyle, utils::macros::bqn386,
13+
widgets::wrap::Wrap, Message,
1314
};
1415

1516
static GLYPHS: Lazy<[char; 64]> = Lazy::new(|| {
@@ -21,30 +22,54 @@ static GLYPHS: Lazy<[char; 64]> = Lazy::new(|| {
2122
]
2223
});
2324

24-
pub fn toolbar_view<'a>() -> Element<'a, Message> {
25-
container(
26-
GLYPHS
25+
pub struct Toolbar {
26+
items: HashMap<char, Vec<markdown::Item>>,
27+
}
28+
29+
impl Toolbar {
30+
pub fn new() -> Self {
31+
let items: HashMap<char, Vec<markdown::Item>> = GLYPHS
2732
.iter()
28-
.fold(Wrap::new(), |wrap, glyph| {
29-
wrap.push(
33+
.map(|&glyph| (glyph, parse_glyph_documentation(glyph)))
34+
.collect();
35+
36+
Self { items }
37+
}
38+
39+
pub fn view(&self) -> Element<'_, Message> {
40+
Wrap::with_elements(
41+
GLYPHS
42+
.iter()
43+
.map(|&glyph| {
3044
tooltip(
3145
button(bqn386!(glyph))
3246
.style(btnstyle)
3347
.on_press(Message::ToolbarClick(glyph.to_string())),
34-
markdown(
35-
markdown::parse(
36-
glyph_to_documentation(*glyph),
37-
iced::theme::Palette::DRACULA,
38-
),
48+
iced::widget::container(markdown(
49+
&self.items[&glyph],
3950
markdown::Settings::default(),
40-
(),
41-
),
51+
|url| Message::TabNext,
52+
))
53+
.style(|t| iced::widget::container::Style {
54+
text_color: Some(iced::Color::BLACK),
55+
background: Some(iced::Background::Color(iced::Color::WHITE)),
56+
border: iced::border::rounded(4),
57+
shadow: Default::default(),
58+
})
59+
.padding(Padding::new(4.0))
60+
.width(400.0)
61+
.max_height(1000.0),
4262
tooltip::Position::FollowCursor,
4363
)
44-
.style(toolbarstyle),
45-
)
46-
})
47-
.spacing(1.0),
48-
)
49-
.into()
64+
.into()
65+
})
66+
.collect(),
67+
)
68+
.into()
69+
}
5070
}
71+
72+
fn parse_glyph_documentation(glyph: char) -> Vec<markdown::Item> {
73+
markdown::parse(glyph_to_documentation(glyph), iced::theme::Palette::DRACULA).collect()
74+
}
75+

0 commit comments

Comments
 (0)