Skip to content

Commit 1361002

Browse files
authored
gg: change the Color APIs, that int to use i32 instead (#25349)
1 parent 5fd2278 commit 1361002

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

‎vlib/builtin/js/string.js.v‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ pub fn (s string) i16() i16 {
287287
return i16(JS.parseInt(s.str))
288288
}
289289

290+
// i32 returns the value of the string as i32 `'1'.i32() == i32(1)`.
291+
pub fn (s string) i32() i32 {
292+
return i32(JS.parseInt(s.str))
293+
}
294+
290295
// f32 returns the value of the string as f32 `'1.0'.f32() == f32(1)`.
291296
pub fn (s string) f32() f32 {
292297
// return C.atof(&char(s.str))

‎vlib/gg/color.v‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub mut:
122122
}
123123

124124
// hex takes in a 32 bit integer and splits it into 4 byte values
125-
pub fn hex(color int) Color {
125+
pub fn hex(color i32) Color {
126126
return Color{
127127
r: u8((color >> 16) & 0xFF)
128128
g: u8((color >> 8) & 0xFF)
@@ -151,10 +151,10 @@ pub fn rgba(r u8, g u8, b u8, a u8) Color {
151151

152152
// + adds `b` to `a`, with a maximum value of 255 for each channel
153153
pub fn (a Color) + (b Color) Color {
154-
mut na := int(a.a) + b.a
155-
mut nr := int(a.r) + b.r
156-
mut ng := int(a.g) + b.g
157-
mut nb := int(a.b) + b.b
154+
mut na := i32(a.a) + b.a
155+
mut nr := i32(a.r) + b.r
156+
mut ng := i32(a.g) + b.g
157+
mut nb := i32(a.b) + b.b
158158
if na > 255 {
159159
na = 255
160160
}
@@ -178,9 +178,9 @@ pub fn (a Color) + (b Color) Color {
178178
// - subtracts `b` from `a`, with a minimum value of 0 for each channel
179179
pub fn (a Color) - (b Color) Color {
180180
mut na := if a.a > b.a { a.a } else { b.a }
181-
mut nr := int(a.r) - b.r
182-
mut ng := int(a.g) - b.g
183-
mut nb := int(a.b) - b.b
181+
mut nr := i32(a.r) - b.r
182+
mut ng := i32(a.g) - b.g
183+
mut nb := i32(a.b) - b.b
184184
if na < 0 {
185185
na = 0
186186
}
@@ -249,25 +249,25 @@ pub fn (c Color) str() string {
249249
return 'Color{${c.r}, ${c.g}, ${c.b}, ${c.a}}'
250250
}
251251

252-
// rgba8 converts a color value to an int in the RGBA8 order.
252+
// rgba8 converts a color value to an 32bit int in the RGBA8 order.
253253
// see https://developer.apple.com/documentation/coreimage/ciformat
254254
@[inline]
255-
pub fn (c Color) rgba8() int {
256-
return int(u32(c.r) << 24 | u32(c.g) << 16 | u32(c.b) << 8 | u32(c.a))
255+
pub fn (c Color) rgba8() i32 {
256+
return i32(u32(c.r) << 24 | u32(c.g) << 16 | u32(c.b) << 8 | u32(c.a))
257257
}
258258

259-
// bgra8 converts a color value to an int in the BGRA8 order.
259+
// bgra8 converts a color value to an 32bit int in the BGRA8 order.
260260
// see https://developer.apple.com/documentation/coreimage/ciformat
261261
@[inline]
262-
pub fn (c Color) bgra8() int {
263-
return int(u32(c.b) << 24 | u32(c.g) << 16 | u32(c.r) << 8 | u32(c.a))
262+
pub fn (c Color) bgra8() i32 {
263+
return i32(u32(c.b) << 24 | u32(c.g) << 16 | u32(c.r) << 8 | u32(c.a))
264264
}
265265

266-
// abgr8 converts a color value to an int in the ABGR8 order.
266+
// abgr8 converts a color value to an 32bit int in the ABGR8 order.
267267
// see https://developer.apple.com/documentation/coreimage/ciformat
268268
@[inline]
269-
pub fn (c Color) abgr8() int {
270-
return int(u32(c.a) << 24 | u32(c.b) << 16 | u32(c.g) << 8 | u32(c.r))
269+
pub fn (c Color) abgr8() i32 {
270+
return i32(u32(c.a) << 24 | u32(c.b) << 16 | u32(c.g) << 8 | u32(c.r))
271271
}
272272

273273
const string_colors = {
@@ -298,7 +298,7 @@ const string_colors = {
298298
pub fn color_from_string(s string) Color {
299299
if s.starts_with('#') {
300300
mut hex_str := '0x' + s[1..]
301-
return hex(hex_str.int())
301+
return hex(hex_str.i32())
302302
} else {
303303
return string_colors[s]
304304
}

0 commit comments

Comments
 (0)