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

Commit 9c8b067

Browse files
committed
[refactor] Remove duplicate definition of styling prop kind mapping
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.
1 parent 780db56 commit 9c8b067

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

tcw3/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#![feature(weak_counts)]
99
#![feature(doc_cfg)] // `cfg(rustdoc)`
1010
#![feature(unsized_locals)] // Call `dyn FnOnce`
11+
#![feature(const_if_match)] // `if` and `match` in `const fn`
12+
#![feature(const_fn)] // conditional expressions in `const fn`
1113
#![allow(clippy::float_cmp)]
1214
// this lint is ridiculous
1315
// The size on memory hardly relates to how they are passed via a parameter

tcw3/src/ui/theming/manager.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,7 @@ bitflags! {
406406
}
407407

408408
impl Prop {
409-
pub fn kind_flags(&self) -> PropKindFlags {
410-
// Make sure to synchronize these with the `prop!` macro - This is a
411-
// temporary restriction until `match` inside `const fn` is implemented:
412-
// <https://github.com/rust-lang/rust/issues/49146>
409+
pub const fn kind_flags(&self) -> PropKindFlags {
413410
match *self {
414411
Prop::NumLayers => PropKindFlags::LAYER_ALL,
415412
Prop::LayerImg(_) => PropKindFlags::LAYER_IMG,

tcw3/src/ui/theming/stylesheet.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,12 @@ macro_rules! sel {
239239

240240
/// This macro is used for two purposes:
241241
/// - To create `PropKindFlags`.
242-
/// (`Prop` and `Prop::kind_flags` would be better for normalization, but
243-
/// `match` does not work inside a `const fn` yet...
244-
/// <https://github.com/rust-lang/rfcs/pull/2342>)
245242
/// - To create `(Prop, PropValue)`.
246243
#[doc(hidden)]
247244
#[macro_export]
248245
macro_rules! prop {
249246
(@kind num_layers) => {
250-
$crate::ui::theming::PropKindFlags::LAYER_ALL
247+
$crate::ui::theming::Prop::NumLayers.kind_flags()
251248
};
252249
(num_layers: $val:expr) => {
253250
(
@@ -257,7 +254,7 @@ macro_rules! prop {
257254
};
258255

259256
(@kind layer_img[$i:expr]) => {
260-
$crate::ui::theming::PropKindFlags::LAYER_IMG
257+
$crate::ui::theming::Prop::LayerImg($i).kind_flags()
261258
};
262259
(layer_img[$i:expr]: $val:expr) => {
263260
(
@@ -267,7 +264,7 @@ macro_rules! prop {
267264
};
268265

269266
(@kind layer_center[$i:expr]) => {
270-
$crate::ui::theming::PropKindFlags::LAYER_CENTER
267+
$crate::ui::theming::Prop::LayerCenter($i).kind_flags()
271268
};
272269
(layer_center[$i:expr]: $val:expr) => {
273270
(
@@ -277,7 +274,7 @@ macro_rules! prop {
277274
};
278275

279276
(@kind layer_opacity[$i:expr]) => {
280-
$crate::ui::theming::PropKindFlags::LAYER_OPACITY
277+
$crate::ui::theming::Prop::LayerOpacity($i).kind_flags()
281278
};
282279
(layer_opacity[$i:expr]: $val:expr) => {
283280
(
@@ -287,7 +284,7 @@ macro_rules! prop {
287284
};
288285

289286
(@kind layer_bg_color[$i:expr]) => {
290-
$crate::ui::theming::PropKindFlags::LAYER_BG_COLOR
287+
$crate::ui::theming::Prop::LayerBgColor($i).kind_flags()
291288
};
292289
(layer_bg_color[$i:expr]: $val:expr) => {
293290
(
@@ -297,7 +294,7 @@ macro_rules! prop {
297294
};
298295

299296
(@kind layer_metrics[$i:expr]) => {
300-
$crate::ui::theming::PropKindFlags::LAYER_BOUNDS
297+
$crate::ui::theming::Prop::LayerMetrics($i).kind_flags()
301298
};
302299
(layer_metrics[$i:expr]: $val:expr) => {
303300
(
@@ -307,7 +304,7 @@ macro_rules! prop {
307304
};
308305

309306
(@kind subview_metrics[$i:expr]) => {
310-
$crate::ui::theming::PropKindFlags::LAYOUT
307+
$crate::ui::theming::Prop::SubviewMetrics($i).kind_flags()
311308
};
312309
(subview_metrics[$i:expr]: $val:expr) => {
313310
(
@@ -317,7 +314,7 @@ macro_rules! prop {
317314
};
318315

319316
(@kind min_size) => {
320-
$crate::ui::theming::PropKindFlags::LAYOUT
317+
$crate::ui::theming::Prop::MinSize.kind_flags()
321318
};
322319
(min_size: $val:expr) => {
323320
(
@@ -327,7 +324,7 @@ macro_rules! prop {
327324
};
328325

329326
(@kind fg_color) => {
330-
$crate::ui::theming::PropKindFlags::FG_COLOR
327+
$crate::ui::theming::Prop::FgColor.kind_flags()
331328
};
332329
(fg_color: $val:expr) => {
333330
(

0 commit comments

Comments
 (0)