Skip to content

Commit 4ffb197

Browse files
committed
add icons and style panegrid
1 parent e5202bf commit 4ffb197

File tree

8 files changed

+312
-15
lines changed

8 files changed

+312
-15
lines changed

Cargo.lock

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

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ 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"], rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
16+
iced = { git = "https://github.com/iced-rs/iced", features = ["async-std", "debug", "lazy", "svg"], rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
1717
iced_core = { git = "https://github.com/iced-rs/iced", rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
1818
iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
1919
iced_style = { git = "https://github.com/iced-rs/iced", rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }

assets/cross.svg

+3
Loading

assets/horizontal.svg

+3
Loading

assets/vertical.svg

+3
Loading

src/main.rs

+40
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ impl Application for Beacon {
446446
)
447447
.into()
448448
}))
449+
.style(if is_focused {
450+
style::pane_focused
451+
} else {
452+
style::pane_active
453+
})
449454
})
450455
.width(Length::Fill)
451456
.height(Length::Fill)
@@ -488,3 +493,38 @@ impl Application for Beacon {
488493
})
489494
}
490495
}
496+
497+
mod style {
498+
use iced::widget::container;
499+
use iced::Theme;
500+
use iced::Background;
501+
use iced::Color;
502+
503+
pub fn pane_active(theme: &Theme) -> container::Appearance {
504+
let palette = theme.extended_palette();
505+
container::Appearance {
506+
background: Some(Background::Color(Color::from_rgb(
507+
12.0 / 255.0,
508+
12.0 / 255.0,
509+
12.0 / 255.0,
510+
))),
511+
border_width: 2.0,
512+
border_color: palette.background.strong.color,
513+
..Default::default()
514+
}
515+
}
516+
517+
pub fn pane_focused(theme: &Theme) -> container::Appearance {
518+
let palette = theme.extended_palette();
519+
container::Appearance {
520+
background: Some(Background::Color(Color::from_rgb(
521+
12.0 / 255.0,
522+
12.0 / 255.0,
523+
12.0 / 255.0,
524+
))),
525+
border_width: 2.0,
526+
border_color: palette.primary.strong.color,
527+
..Default::default()
528+
}
529+
}
530+
}

src/styles.rs

+21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use iced::Color;
55

66
pub struct BtnStyle;
77
pub struct TabStyle;
8+
pub struct TransparentBtn;
89
pub struct CanvasStyle;
910
pub struct ToolbarStyle;
1011
pub struct SrcCellStyle;
@@ -51,6 +52,26 @@ impl TabStyle {
5152
}
5253
}
5354

55+
impl iced::widget::button::StyleSheet for TransparentBtn {
56+
type Style = iced::Theme;
57+
fn active(&self, _: &Self::Style) -> button::Appearance {
58+
button::Appearance {
59+
background: Some(Background::Color(Color::from_rgb(
60+
12.0 / 255.0,
61+
12.0 / 255.0,
62+
12.0 / 255.0,
63+
))),
64+
text_color: Color::WHITE,
65+
..Default::default()
66+
}
67+
}
68+
}
69+
impl TransparentBtn {
70+
pub fn theme() -> iced::theme::Button {
71+
iced::theme::Button::Custom(Box::from(TransparentBtn))
72+
}
73+
}
74+
5475
impl iced::widget::container::StyleSheet for ToolbarStyle {
5576
type Style = iced::Theme;
5677
fn appearance(&self, _: &Self::Style) -> container::Appearance {

src/views/pane.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use crate::widgets::text_input;
66
use crate::{styles::*, INPUT_ID};
77
use crate::{Message, SCROLL_ID};
88
use iced::alignment::{self, Alignment};
9-
use iced::widget::pane_grid;
9+
use iced::widget::{pane_grid, svg};
1010
use iced::{
11+
color, theme,
1112
widget::{button, column, container, row, scrollable, text, Column, Container},
1213
Element, Length,
1314
};
@@ -91,24 +92,28 @@ pub fn view_pane<'a>(
9192
.collect::<Vec<Element<_>>>(),
9293
)
9394
.spacing(8);
95+
let handle = |n| svg::Handle::from_path(format!(
96+
"{}/assets/{n}.svg",
97+
env!("CARGO_MANIFEST_DIR")
98+
));
99+
94100
let button = |label, message| {
95-
button(
96-
text(label)
97-
.horizontal_alignment(alignment::Horizontal::Center)
98-
.size(16),
99-
)
101+
button( svg(handle(label)).width(Length::Fill).height(Length::Fill).style(theme::Svg::custom_fn(|_theme| svg::Appearance {
102+
color: Some(color!(0xffffff)),
103+
})))
100104
.padding(2)
101-
.style(TabStyle::theme())
105+
.style(TransparentBtn::theme())
102106
.on_press(message)
103107
};
104108

109+
105110
let mut controls = row![
106-
button("-", Message::Split(pane_grid::Axis::Horizontal, pane),),
107-
button("|", Message::Split(pane_grid::Axis::Vertical, pane),)
111+
button("horizontal", Message::Split(pane_grid::Axis::Horizontal, pane),),
112+
button("vertical", Message::Split(pane_grid::Axis::Vertical, pane),)
108113
]
109114
.spacing(5);
110115
if total_panes > 1 && !is_pinned {
111-
controls = controls.push(button("X", Message::Close(pane)));
116+
controls = controls.push(button("cross", Message::Close(pane)));
112117
}
113118

114119
let content = column![

0 commit comments

Comments
 (0)