Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
[refactor] Remove duplicate definition of styling prop kind mapping
Browse files Browse the repository at this point in the history
With rust-lang/rust#66507 merged, `Prop::kind_flags` can be `const fn`
and the `prop!` macro can use this method to get the kind flags for a
given prop.
  • Loading branch information
yvt committed Jan 1, 2020
1 parent 780db56 commit 9c8b067
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
2 changes: 2 additions & 0 deletions tcw3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#![feature(weak_counts)]
#![feature(doc_cfg)] // `cfg(rustdoc)`
#![feature(unsized_locals)] // Call `dyn FnOnce`
#![feature(const_if_match)] // `if` and `match` in `const fn`
#![feature(const_fn)] // conditional expressions in `const fn`
#![allow(clippy::float_cmp)]
// this lint is ridiculous
// The size on memory hardly relates to how they are passed via a parameter
Expand Down
5 changes: 1 addition & 4 deletions tcw3/src/ui/theming/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,7 @@ bitflags! {
}

impl Prop {
pub fn kind_flags(&self) -> PropKindFlags {
// Make sure to synchronize these with the `prop!` macro - This is a
// temporary restriction until `match` inside `const fn` is implemented:
// <https://github.com/rust-lang/rust/issues/49146>
pub const fn kind_flags(&self) -> PropKindFlags {
match *self {
Prop::NumLayers => PropKindFlags::LAYER_ALL,
Prop::LayerImg(_) => PropKindFlags::LAYER_IMG,
Expand Down
21 changes: 9 additions & 12 deletions tcw3/src/ui/theming/stylesheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,12 @@ macro_rules! sel {

/// This macro is used for two purposes:
/// - To create `PropKindFlags`.
/// (`Prop` and `Prop::kind_flags` would be better for normalization, but
/// `match` does not work inside a `const fn` yet...
/// <https://github.com/rust-lang/rfcs/pull/2342>)
/// - To create `(Prop, PropValue)`.
#[doc(hidden)]
#[macro_export]
macro_rules! prop {
(@kind num_layers) => {
$crate::ui::theming::PropKindFlags::LAYER_ALL
$crate::ui::theming::Prop::NumLayers.kind_flags()
};
(num_layers: $val:expr) => {
(
Expand All @@ -257,7 +254,7 @@ macro_rules! prop {
};

(@kind layer_img[$i:expr]) => {
$crate::ui::theming::PropKindFlags::LAYER_IMG
$crate::ui::theming::Prop::LayerImg($i).kind_flags()
};
(layer_img[$i:expr]: $val:expr) => {
(
Expand All @@ -267,7 +264,7 @@ macro_rules! prop {
};

(@kind layer_center[$i:expr]) => {
$crate::ui::theming::PropKindFlags::LAYER_CENTER
$crate::ui::theming::Prop::LayerCenter($i).kind_flags()
};
(layer_center[$i:expr]: $val:expr) => {
(
Expand All @@ -277,7 +274,7 @@ macro_rules! prop {
};

(@kind layer_opacity[$i:expr]) => {
$crate::ui::theming::PropKindFlags::LAYER_OPACITY
$crate::ui::theming::Prop::LayerOpacity($i).kind_flags()
};
(layer_opacity[$i:expr]: $val:expr) => {
(
Expand All @@ -287,7 +284,7 @@ macro_rules! prop {
};

(@kind layer_bg_color[$i:expr]) => {
$crate::ui::theming::PropKindFlags::LAYER_BG_COLOR
$crate::ui::theming::Prop::LayerBgColor($i).kind_flags()
};
(layer_bg_color[$i:expr]: $val:expr) => {
(
Expand All @@ -297,7 +294,7 @@ macro_rules! prop {
};

(@kind layer_metrics[$i:expr]) => {
$crate::ui::theming::PropKindFlags::LAYER_BOUNDS
$crate::ui::theming::Prop::LayerMetrics($i).kind_flags()
};
(layer_metrics[$i:expr]: $val:expr) => {
(
Expand All @@ -307,7 +304,7 @@ macro_rules! prop {
};

(@kind subview_metrics[$i:expr]) => {
$crate::ui::theming::PropKindFlags::LAYOUT
$crate::ui::theming::Prop::SubviewMetrics($i).kind_flags()
};
(subview_metrics[$i:expr]: $val:expr) => {
(
Expand All @@ -317,7 +314,7 @@ macro_rules! prop {
};

(@kind min_size) => {
$crate::ui::theming::PropKindFlags::LAYOUT
$crate::ui::theming::Prop::MinSize.kind_flags()
};
(min_size: $val:expr) => {
(
Expand All @@ -327,7 +324,7 @@ macro_rules! prop {
};

(@kind fg_color) => {
$crate::ui::theming::PropKindFlags::FG_COLOR
$crate::ui::theming::Prop::FgColor.kind_flags()
};
(fg_color: $val:expr) => {
(
Expand Down

0 comments on commit 9c8b067

Please sign in to comment.