mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add shell.background-color.rgba to prefs (#30488)
* Add shell.transparent-background.enabled to prefs * Rename config to background_color * Rename to background-color and.rgba add PrefValue::Array variant
This commit is contained in:
parent
ffac882f8f
commit
38a325cc1c
8 changed files with 108 additions and 37 deletions
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
use std::sync::RwLock;
|
||||
|
@ -16,6 +17,7 @@ pub enum PrefValue {
|
|||
Int(i64),
|
||||
Str(String),
|
||||
Bool(bool),
|
||||
Array(Vec<PrefValue>),
|
||||
Missing,
|
||||
}
|
||||
|
||||
|
@ -149,6 +151,36 @@ impl_from_pref! {
|
|||
PrefValue::Bool => bool,
|
||||
}
|
||||
|
||||
impl From<[f64; 4]> for PrefValue {
|
||||
fn from(other: [f64; 4]) -> PrefValue {
|
||||
PrefValue::Array(IntoIterator::into_iter(other).map(|v| v.into()).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PrefValue> for [f64; 4] {
|
||||
fn from(other: PrefValue) -> [f64; 4] {
|
||||
match other {
|
||||
PrefValue::Array(values) if values.len() == 4 => {
|
||||
let mut f = values.into_iter().map(|v| v.try_into());
|
||||
if f.all(|v| v.is_ok()) {
|
||||
let f = f.flatten().collect::<Vec<f64>>();
|
||||
return [f[0], f[1], f[2], f[3]];
|
||||
} else {
|
||||
panic!(
|
||||
"Cannot convert PrefValue to {:?}",
|
||||
std::any::type_name::<[f64; 4]>()
|
||||
)
|
||||
}
|
||||
},
|
||||
_ => panic!(
|
||||
"Cannot convert {:?} to {:?}",
|
||||
other,
|
||||
std::any::type_name::<[f64; 4]>()
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PrefError {
|
||||
NoSuchPref(String),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue