Style PickList
in game_of_life
example
This commit is contained in:
parent
b64e0ea5e3
commit
94383d82a5
@ -842,12 +842,17 @@ impl Controls {
|
|||||||
.spacing(5)
|
.spacing(5)
|
||||||
.text_size(16),
|
.text_size(16),
|
||||||
)
|
)
|
||||||
.push(PickList::new(
|
.push(
|
||||||
&mut self.preset_list,
|
PickList::new(
|
||||||
preset::ALL,
|
&mut self.preset_list,
|
||||||
Some(preset),
|
preset::ALL,
|
||||||
Message::PresetPicked,
|
Some(preset),
|
||||||
))
|
Message::PresetPicked,
|
||||||
|
)
|
||||||
|
.padding(8)
|
||||||
|
.text_size(16)
|
||||||
|
.style(style::PickList),
|
||||||
|
)
|
||||||
.push(
|
.push(
|
||||||
Button::new(&mut self.clear_button, Text::new("Clear"))
|
Button::new(&mut self.clear_button, Text::new("Clear"))
|
||||||
.on_press(Message::Clear)
|
.on_press(Message::Clear)
|
||||||
|
@ -8,8 +8,8 @@ pub enum Preset {
|
|||||||
TenCellRow,
|
TenCellRow,
|
||||||
LightweightSpaceship,
|
LightweightSpaceship,
|
||||||
Tumbler,
|
Tumbler,
|
||||||
Acorn,
|
|
||||||
GliderGun,
|
GliderGun,
|
||||||
|
Acorn,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static ALL: &[Preset] = &[
|
pub static ALL: &[Preset] = &[
|
||||||
@ -21,8 +21,8 @@ pub static ALL: &[Preset] = &[
|
|||||||
Preset::TenCellRow,
|
Preset::TenCellRow,
|
||||||
Preset::LightweightSpaceship,
|
Preset::LightweightSpaceship,
|
||||||
Preset::Tumbler,
|
Preset::Tumbler,
|
||||||
Preset::Acorn,
|
|
||||||
Preset::GliderGun,
|
Preset::GliderGun,
|
||||||
|
Preset::Acorn,
|
||||||
];
|
];
|
||||||
|
|
||||||
impl Preset {
|
impl Preset {
|
||||||
@ -76,11 +76,6 @@ impl Preset {
|
|||||||
"x x x x",
|
"x x x x",
|
||||||
"xx xx",
|
"xx xx",
|
||||||
],
|
],
|
||||||
Preset::Acorn => vec![
|
|
||||||
" x ",
|
|
||||||
" x ",
|
|
||||||
"xx xxx",
|
|
||||||
],
|
|
||||||
Preset::GliderGun => vec![
|
Preset::GliderGun => vec![
|
||||||
" x ",
|
" x ",
|
||||||
" x x ",
|
" x x ",
|
||||||
@ -91,7 +86,12 @@ impl Preset {
|
|||||||
" x x x ",
|
" x x x ",
|
||||||
" x x ",
|
" x x ",
|
||||||
" xx ",
|
" xx ",
|
||||||
]
|
],
|
||||||
|
Preset::Acorn => vec![
|
||||||
|
" x ",
|
||||||
|
" x ",
|
||||||
|
"xx xxx",
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let start_row = -(cells.len() as isize / 2);
|
let start_row = -(cells.len() as isize / 2);
|
||||||
@ -134,8 +134,8 @@ impl std::fmt::Display for Preset {
|
|||||||
Preset::TenCellRow => "10 Cell Row",
|
Preset::TenCellRow => "10 Cell Row",
|
||||||
Preset::LightweightSpaceship => "Lightweight spaceship",
|
Preset::LightweightSpaceship => "Lightweight spaceship",
|
||||||
Preset::Tumbler => "Tumbler",
|
Preset::Tumbler => "Tumbler",
|
||||||
Preset::Acorn => "Acorn",
|
|
||||||
Preset::GliderGun => "Gosper Glider Gun",
|
Preset::GliderGun => "Gosper Glider Gun",
|
||||||
|
Preset::Acorn => "Acorn",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use iced::{button, container, slider, Background, Color};
|
use iced::{button, container, pick_list, slider, Background, Color};
|
||||||
|
|
||||||
const ACTIVE: Color = Color::from_rgb(
|
const ACTIVE: Color = Color::from_rgb(
|
||||||
0x72 as f32 / 255.0,
|
0x72 as f32 / 255.0,
|
||||||
@ -18,6 +18,12 @@ const HOVERED: Color = Color::from_rgb(
|
|||||||
0xC4 as f32 / 255.0,
|
0xC4 as f32 / 255.0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const BACKGROUND: Color = Color::from_rgb(
|
||||||
|
0x2F as f32 / 255.0,
|
||||||
|
0x31 as f32 / 255.0,
|
||||||
|
0x36 as f32 / 255.0,
|
||||||
|
);
|
||||||
|
|
||||||
pub struct Container;
|
pub struct Container;
|
||||||
|
|
||||||
impl container::StyleSheet for Container {
|
impl container::StyleSheet for Container {
|
||||||
@ -132,3 +138,51 @@ impl slider::StyleSheet for Slider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct PickList;
|
||||||
|
|
||||||
|
impl pick_list::StyleSheet for PickList {
|
||||||
|
fn menu(&self) -> pick_list::Menu {
|
||||||
|
pick_list::Menu {
|
||||||
|
text_color: Color::WHITE,
|
||||||
|
background: BACKGROUND.into(),
|
||||||
|
border_width: 1,
|
||||||
|
border_color: Color {
|
||||||
|
a: 0.7,
|
||||||
|
..Color::BLACK
|
||||||
|
},
|
||||||
|
selected_background: Color {
|
||||||
|
a: 0.5,
|
||||||
|
..Color::BLACK
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
selected_text_color: Color::WHITE,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn active(&self) -> pick_list::Style {
|
||||||
|
pick_list::Style {
|
||||||
|
text_color: Color::WHITE,
|
||||||
|
background: BACKGROUND.into(),
|
||||||
|
border_width: 1,
|
||||||
|
border_color: Color {
|
||||||
|
a: 0.6,
|
||||||
|
..Color::BLACK
|
||||||
|
},
|
||||||
|
border_radius: 2,
|
||||||
|
icon_size: 0.5,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hovered(&self) -> pick_list::Style {
|
||||||
|
let active = self.active();
|
||||||
|
|
||||||
|
pick_list::Style {
|
||||||
|
border_color: Color {
|
||||||
|
a: 0.9,
|
||||||
|
..Color::BLACK
|
||||||
|
},
|
||||||
|
..active
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user