Move implementations from example to libcosmic
This commit is contained in:
parent
699e474427
commit
5ad54bd3b1
13 changed files with 162 additions and 122 deletions
18
src/widget/icon.rs
Normal file
18
src/widget/icon.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use iced::widget::svg;
|
||||
|
||||
pub fn icon(name: &str, size: u16) -> svg::Svg {
|
||||
let handle = match freedesktop_icons::lookup(name)
|
||||
.with_size(size)
|
||||
.with_theme("Pop")
|
||||
.with_cache()
|
||||
.force_svg()
|
||||
.find()
|
||||
{
|
||||
Some(path) => svg::Handle::from_path(path),
|
||||
None => {
|
||||
eprintln!("icon '{}' size {} not found", name, size);
|
||||
svg::Handle::from_memory(Vec::new())
|
||||
},
|
||||
};
|
||||
svg::Svg::new(handle)
|
||||
}
|
||||
23
src/widget/list_view.rs
Normal file
23
src/widget/list_view.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use iced::{
|
||||
Background,
|
||||
Color,
|
||||
Theme,
|
||||
widget::{
|
||||
container,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn list_view_style(theme: &Theme) -> container::Appearance {
|
||||
container::Appearance {
|
||||
text_color: None,
|
||||
background: Some(Background::Color(
|
||||
match theme {
|
||||
Theme::Dark => Color::from_rgb8(0x27, 0x27, 0x27),
|
||||
Theme::Light => Color::from_rgb8(0xf7, 0xf7, 0xf7),
|
||||
}
|
||||
)),
|
||||
border_radius: 8.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
}
|
||||
}
|
||||
22
src/widget/mod.rs
Normal file
22
src/widget/mod.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#[macro_export]
|
||||
macro_rules! button {
|
||||
($($x:expr),+ $(,)?) => (
|
||||
$crate::iced::widget::Button::new(
|
||||
$crate::iced::widget::Row::with_children(
|
||||
vec![$($crate::iced::Element::from($x)),+]
|
||||
)
|
||||
.spacing(8)
|
||||
)
|
||||
.padding([8, 16])
|
||||
);
|
||||
}
|
||||
pub use button;
|
||||
|
||||
mod icon;
|
||||
pub use self::icon::icon;
|
||||
|
||||
mod list_view;
|
||||
pub use list_view::list_view_style;
|
||||
|
||||
mod nav_bar;
|
||||
pub use nav_bar::nav_bar_style;
|
||||
23
src/widget/nav_bar.rs
Normal file
23
src/widget/nav_bar.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use iced::{
|
||||
Background,
|
||||
Color,
|
||||
Theme,
|
||||
widget::{
|
||||
container,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn nav_bar_style(theme: &Theme) -> container::Appearance {
|
||||
container::Appearance {
|
||||
text_color: None,
|
||||
background: Some(Background::Color(
|
||||
match theme {
|
||||
Theme::Dark => Color::from_rgb8(0x29, 0x29, 0x29),
|
||||
Theme::Light => Color::from_rgb8(0xfd, 0xfd, 0xfd),
|
||||
}
|
||||
)),
|
||||
border_radius: 8.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue