Skip to content

Commit

Permalink
add icons and style panegrid
Browse files Browse the repository at this point in the history
  • Loading branch information
x86y committed Jul 21, 2023
1 parent e5202bf commit 4ffb197
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 15 deletions.
230 changes: 226 additions & 4 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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"], rev = "fd077918db7643530c3a7318ed5777d2f3d8761b" }
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" }
Expand Down
3 changes: 3 additions & 0 deletions assets/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/horizontal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/vertical.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ impl Application for Beacon {
)
.into()
}))
.style(if is_focused {
style::pane_focused
} else {
style::pane_active
})
})
.width(Length::Fill)
.height(Length::Fill)
Expand Down Expand Up @@ -488,3 +493,38 @@ impl Application for Beacon {
})
}
}

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

pub fn pane_active(theme: &Theme) -> container::Appearance {
let palette = theme.extended_palette();
container::Appearance {
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,
..Default::default()
}
}

pub fn pane_focused(theme: &Theme) -> container::Appearance {
let palette = theme.extended_palette();
container::Appearance {
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,
..Default::default()
}
}
}
21 changes: 21 additions & 0 deletions src/styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use iced::Color;

pub struct BtnStyle;
pub struct TabStyle;
pub struct TransparentBtn;
pub struct CanvasStyle;
pub struct ToolbarStyle;
pub struct SrcCellStyle;
Expand Down Expand Up @@ -51,6 +52,26 @@ impl TabStyle {
}
}

impl iced::widget::button::StyleSheet for TransparentBtn {
type Style = iced::Theme;
fn active(&self, _: &Self::Style) -> button::Appearance {
button::Appearance {
background: Some(Background::Color(Color::from_rgb(
12.0 / 255.0,
12.0 / 255.0,
12.0 / 255.0,
))),
text_color: Color::WHITE,
..Default::default()
}
}
}
impl TransparentBtn {
pub fn theme() -> iced::theme::Button {
iced::theme::Button::Custom(Box::from(TransparentBtn))
}
}

impl iced::widget::container::StyleSheet for ToolbarStyle {
type Style = iced::Theme;
fn appearance(&self, _: &Self::Style) -> container::Appearance {
Expand Down
25 changes: 15 additions & 10 deletions src/views/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use crate::widgets::text_input;
use crate::{styles::*, INPUT_ID};
use crate::{Message, SCROLL_ID};
use iced::alignment::{self, Alignment};
use iced::widget::pane_grid;
use iced::widget::{pane_grid, svg};
use iced::{
color, theme,
widget::{button, column, container, row, scrollable, text, Column, Container},
Element, Length,
};
Expand Down Expand Up @@ -91,24 +92,28 @@ pub fn view_pane<'a>(
.collect::<Vec<Element<_>>>(),
)
.spacing(8);
let handle = |n| svg::Handle::from_path(format!(
"{}/assets/{n}.svg",
env!("CARGO_MANIFEST_DIR")
));

let button = |label, message| {
button(
text(label)
.horizontal_alignment(alignment::Horizontal::Center)
.size(16),
)
button( svg(handle(label)).width(Length::Fill).height(Length::Fill).style(theme::Svg::custom_fn(|_theme| svg::Appearance {
color: Some(color!(0xffffff)),
})))
.padding(2)
.style(TabStyle::theme())
.style(TransparentBtn::theme())
.on_press(message)
};


let mut controls = row![
button("-", Message::Split(pane_grid::Axis::Horizontal, pane),),
button("|", Message::Split(pane_grid::Axis::Vertical, pane),)
button("horizontal", 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("X", Message::Close(pane)));
controls = controls.push(button("cross", Message::Close(pane)));
}

let content = column![
Expand Down

0 comments on commit 4ffb197

Please sign in to comment.