Add some styling to pane_grid
buttons
This commit is contained in:
parent
20b142e8e3
commit
b8a035d2da
@ -167,7 +167,7 @@ impl Content {
|
|||||||
close,
|
close,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let button = |state, label, message| {
|
let button = |state, label, message, style| {
|
||||||
Button::new(
|
Button::new(
|
||||||
state,
|
state,
|
||||||
Text::new(label)
|
Text::new(label)
|
||||||
@ -176,7 +176,9 @@ impl Content {
|
|||||||
.size(16),
|
.size(16),
|
||||||
)
|
)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
|
.padding(8)
|
||||||
.on_press(message)
|
.on_press(message)
|
||||||
|
.style(style)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut controls = Column::new()
|
let mut controls = Column::new()
|
||||||
@ -186,16 +188,22 @@ impl Content {
|
|||||||
split_horizontally,
|
split_horizontally,
|
||||||
"Split horizontally",
|
"Split horizontally",
|
||||||
Message::Split(pane_grid::Axis::Horizontal, pane),
|
Message::Split(pane_grid::Axis::Horizontal, pane),
|
||||||
|
style::Button::Primary,
|
||||||
))
|
))
|
||||||
.push(button(
|
.push(button(
|
||||||
split_vertically,
|
split_vertically,
|
||||||
"Split vertically",
|
"Split vertically",
|
||||||
Message::Split(pane_grid::Axis::Vertical, pane),
|
Message::Split(pane_grid::Axis::Vertical, pane),
|
||||||
|
style::Button::Primary,
|
||||||
));
|
));
|
||||||
|
|
||||||
if total_panes > 1 {
|
if total_panes > 1 {
|
||||||
controls =
|
controls = controls.push(button(
|
||||||
controls.push(button(close, "Close", Message::Close(pane)));
|
close,
|
||||||
|
"Close",
|
||||||
|
Message::Close(pane),
|
||||||
|
style::Button::Destructive,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = Scrollable::new(scroll)
|
let content = Scrollable::new(scroll)
|
||||||
@ -217,7 +225,7 @@ impl Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod style {
|
mod style {
|
||||||
use iced::{container, Background, Color};
|
use iced::{button, container, Background, Color, Vector};
|
||||||
|
|
||||||
pub struct Pane {
|
pub struct Pane {
|
||||||
pub is_focused: bool,
|
pub is_focused: bool,
|
||||||
@ -237,4 +245,39 @@ mod style {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum Button {
|
||||||
|
Primary,
|
||||||
|
Destructive,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl button::StyleSheet for Button {
|
||||||
|
fn active(&self) -> button::Style {
|
||||||
|
let color = match self {
|
||||||
|
Button::Primary => Color::from_rgb8(0x25, 0x7A, 0xFD),
|
||||||
|
Button::Destructive => Color::from_rgb(0.8, 0.2, 0.2),
|
||||||
|
};
|
||||||
|
|
||||||
|
button::Style {
|
||||||
|
background: None,
|
||||||
|
border_color: color,
|
||||||
|
border_radius: 5,
|
||||||
|
border_width: 1,
|
||||||
|
shadow_offset: Vector::new(0.0, 0.0),
|
||||||
|
text_color: color,
|
||||||
|
..button::Style::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hovered(&self) -> button::Style {
|
||||||
|
let active = self.active();
|
||||||
|
|
||||||
|
button::Style {
|
||||||
|
background: Some(Background::Color(active.border_color)),
|
||||||
|
text_color: Color::WHITE,
|
||||||
|
border_width: 0,
|
||||||
|
..active
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user