@@ -5,6 +5,7 @@ use std::collections::HashMap;
5
5
mod physical_layout;
6
6
pub ( super ) use physical_layout:: PhysicalLayout ;
7
7
8
+ use crate :: color:: Rgb ;
8
9
use crate :: keymap:: KeyMap ;
9
10
use super :: key:: Key ;
10
11
use super :: rect:: Rect ;
@@ -90,8 +91,8 @@ impl<'a> Layout<'a> {
90
91
let mut y = 0.0 ;
91
92
let mut w = 1.0 ;
92
93
let mut h = 1.0 ;
93
- let mut background_color = "#cccccc" . to_string ( ) ;
94
- let mut foreground_color = "#000000" . to_string ( ) ;
94
+ let mut background_color = Rgb :: new ( 0xcc , 0xcc , 0xcc ) ;
95
+ let mut foreground_color = Rgb :: new ( 0x00 , 0x00 , 0x00 ) ;
95
96
96
97
for entry in & self . physical . 0 {
97
98
if let PhysicalLayoutEntry :: Row ( row) = entry {
@@ -103,12 +104,16 @@ impl<'a> Layout<'a> {
103
104
y -= meta. y ;
104
105
w = meta. w . unwrap_or ( w) ;
105
106
h = meta. h . unwrap_or ( h) ;
106
- background_color = meta. c . clone ( ) . unwrap_or ( background_color) ;
107
+ background_color = meta. c . as_ref ( ) . map ( |c| {
108
+ let err = format ! ( "Failed to parse color {}" , c) ;
109
+ Rgb :: parse ( & c[ 1 ..] ) . expect ( & err)
110
+ } ) . unwrap_or ( background_color) ;
107
111
if let Some ( t) = & meta. t {
108
112
//TODO: support using different color per line?
109
113
//Is this even possible in GTK?
110
114
if let Some ( t_l) = t. lines ( ) . next ( ) {
111
- foreground_color = t_l. to_string ( ) ;
115
+ let err = format ! ( "Failed to parse color {}" , t_l) ;
116
+ foreground_color = Rgb :: parse ( & t_l[ 1 ..] ) . expect ( & err) ;
112
117
}
113
118
}
114
119
}
@@ -140,8 +145,8 @@ impl<'a> Layout<'a> {
140
145
electrical : electrical. clone ( ) ,
141
146
electrical_name : format ! ( "{}, {}" , electrical. 0 , electrical. 1 ) ,
142
147
scancodes : RefCell :: new ( Vec :: new ( ) ) ,
143
- background_color : background_color . clone ( ) ,
144
- foreground_color : foreground_color . clone ( ) ,
148
+ background_color,
149
+ foreground_color,
145
150
} ) ;
146
151
147
152
x += w;
0 commit comments