Skip to content

Commit b26f794

Browse files
committed
Replace Raylib.text_format with native string interpolation and formatting
1 parent 3fbfd73 commit b26f794

13 files changed

+21
-23
lines changed

examples/audio/audio_mixed_processor-broken.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
Raylib.clear_background(Raylib::RAYWHITE)
9191

9292
Raylib.draw_text("MUSIC SHOULD BE PLAYING!", 255, 150, 20, Raylib::LIGHTGRAY)
93-
Raylib.draw_text(Raylib.text_format("EXPONENT = %.2f", :float, $exponent), 215, 180, 20, Raylib::LIGHTGRAY)
93+
Raylib.draw_text("EXPONENT = %.2f" % $exponent, 215, 180, 20, Raylib::LIGHTGRAY)
9494

9595
Raylib.draw_rectangle(199, 199, 402, 34, Raylib::LIGHTGRAY)
9696
400.times do |i|

examples/core/core_custom_frame_control.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@
8282

8383
Raylib.draw_circle(position.to_i, Raylib.get_screen_height / 2 - 25, 50, Raylib::RED)
8484

85-
Raylib.draw_text(Raylib.text_format("%03.0f ms", :double, time_counter * 1000.0), position.to_i - 40, Raylib.get_screen_height / 2 - 100, 20, Raylib::MAROON)
86-
Raylib.draw_text(Raylib.text_format("PosX: %03.0f", :double, position), position.to_i - 50, Raylib.get_screen_height / 2 + 40, 20, Raylib::BLACK)
85+
Raylib.draw_text("%03.0f ms" % (time_counter * 1000.0), position.to_i - 40, Raylib.get_screen_height / 2 - 100, 20, Raylib::MAROON)
86+
Raylib.draw_text("PosX: %03.0f" % position, position.to_i - 50, Raylib.get_screen_height / 2 + 40, 20, Raylib::BLACK)
8787

8888
Raylib.draw_text("Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate.", 10, 10, 20, Raylib::DARKGRAY)
8989
Raylib.draw_text("PRESS SPACE to PAUSE MOVEMENT", 10, Raylib.get_screen_height - 60, 20, Raylib::GRAY)
9090
Raylib.draw_text("PRESS UP | DOWN to CHANGE TARGET FPS", 10, Raylib.get_screen_height - 30, 20, Raylib::GRAY)
91-
Raylib.draw_text(Raylib.text_format("TARGET FPS: %i", :int, target_fps), Raylib.get_screen_width - 220, 10, 20, Raylib::LIME)
91+
Raylib.draw_text("TARGET FPS: #{target_fps}", Raylib.get_screen_width - 220, 10, 20, Raylib::LIME)
9292
# TODO: This is causing Infinity (FloatDomainError) error
9393
# Raylib.draw_text(Raylib.text_format("CURRENT FPS: %i", :int, (1.0 / delta_time).to_i), Raylib.get_screen_width - 220, 40, 20, Raylib::GREEN)
9494

examples/core/core_input_gamepad.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
Raylib.clear_background(Raylib::RAYWHITE)
5252

5353
if Raylib.is_gamepad_available(0)
54-
Raylib.draw_text(Raylib.text_format("GP1: %s", :string, Raylib.get_gamepad_name(0)), 10, 10, 10, Raylib::BLACK)
54+
Raylib.draw_text("GP1: #{Raylib.get_gamepad_name(0)}", 10, 10, 10, Raylib::BLACK)
5555

5656
# Implement drawing logic
5757
gamepad_name = Raylib.get_gamepad_name(0)
@@ -170,18 +170,18 @@
170170
end
171171

172172
axis_count = Raylib.get_gamepad_axis_count(0)
173-
Raylib.draw_text(Raylib.text_format("DETECTED AXIS [%i]:", :int, axis_count), 10, 50, 10, Raylib::MAROON)
173+
Raylib.draw_text("DETECTED AXIS [#{axis_count}]:", 10, 50, 10, Raylib::MAROON)
174174

175175
axis_count.times do |i|
176176
Raylib.draw_text(
177-
Raylib.text_format("AXIS %i: %.02f", :int, i, :float, Raylib.get_gamepad_axis_movement(0, i)), 20, 70 + 20 * i, 10, Raylib::DARKGRAY
177+
"AXIS %i: %.02f" % [i, Raylib.get_gamepad_axis_movement(0, i)], 20, 70 + 20 * i, 10, Raylib::DARKGRAY
178178
)
179179
end
180180

181181
detected_button = Raylib.get_gamepad_button_pressed
182182

183183
if detected_button != Raylib::GAMEPAD_BUTTON_UNKNOWN
184-
Raylib.draw_text(Raylib.text_format("DETECTED BUTTON: %i", :int, detected_button), 10, 430, 10, Raylib::RED)
184+
Raylib.draw_text("DETECTED BUTTON: #{detected_button}", 10, 430, 10, Raylib::RED)
185185
else
186186
Raylib.draw_text("DETECTED BUTTON: NONE", 10, 430, 10, Raylib::GRAY)
187187
end

examples/core/core_input_multitouch.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@
5151
touch_positions.each do |touch_position|
5252
if touch_position.x > 0 && touch_position.y > 0
5353
Raylib.draw_circle_v(touch_position, 34, Raylib::ORANGE)
54-
Raylib.draw_text(
55-
Raylib.text_format("%d", :int, i), touch_position.x - 10, touch_position.y - 70, 40, Raylib::BLACK
56-
)
54+
Raylib.draw_text(i.to_s, touch_position.x - 10, touch_position.y - 70, 40, Raylib::BLACK)
5755
end
5856
end
5957

examples/core/core_random_values.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
Raylib.draw_text("Every 2 seconds a new random value is generated:", 130, 100, 20, Raylib::MAROON)
5050

51-
Raylib.draw_text(Raylib.text_format("%i", :int, rand_value), 360, 180, 80, Raylib::LIGHTGRAY)
51+
Raylib.draw_text(rand_value.to_s, 360, 180, 80, Raylib::LIGHTGRAY)
5252

5353
Raylib.end_drawing
5454
end

examples/core/core_window_flags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def draw_window_flag_state(flag_name, flag_value, key, y_position)
163163
Raylib.draw_fps(10, 10)
164164

165165
Raylib.draw_text(
166-
Raylib.text_format("Screen Size: [%i, %i]", :int, Raylib.get_screen_width, :int, Raylib.get_screen_height),
166+
"Screen Size: [#{Raylib.get_screen_width}, #{Raylib.get_screen_height}]",
167167
10,
168168
40,
169169
10,

examples/core/core_window_letterbox.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
end
7777

7878
Raylib.draw_text("If executed inside a window,\nyou can resize the window,\nand see the screen scaling!", 10, 25, 20, Raylib::WHITE)
79-
Raylib.draw_text(Raylib.text_format("Default Mouse: [%i , %i]", :int, mouse.x.to_i, :int, mouse.y.to_i), 350, 25, 20, Raylib::GREEN)
80-
Raylib.draw_text(Raylib.text_format("Virtual Mouse: [%i , %i]", :int, virtual_mouse.x.to_i, :int, virtual_mouse.y.to_i), 350, 55, 20, Raylib::YELLOW)
79+
Raylib.draw_text("Default Mouse: [#{mouse.x.to_i} , #{mouse.y.to_i}]", 350, 25, 20, Raylib::GREEN)
80+
Raylib.draw_text("Virtual Mouse: [#{virtual_mouse.x.to_i} , #{virtual_mouse.y.to_i}]", 350, 55, 20, Raylib::YELLOW)
8181
Raylib.end_texture_mode
8282

8383
Raylib.begin_drawing

examples/core/core_world_screen.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
)
7777

7878
Raylib.draw_text(
79-
Raylib.text_format("Cube position in screen space coordinates: [%i, %i]", :int, cube_screen_position.x, :int, cube_screen_position.y),
79+
"Cube position in screen space coordinates: [#{cube_screen_position.x.to_i}, #{cube_screen_position.y.to_i}]",
8080
10,
8181
10,
8282
20,

examples/shapes/shapes_collision_area.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101

102102
# Draw collision area
103103
Raylib.draw_text(
104-
Raylib.text_format('Collision Area: %i', :int, box_collision.width * box_collision.height),
104+
Raylib.text_format("Collision Area: #{(box_collision.width * box_collision.height).to}"),
105105
(Raylib.get_screen_width / 2) - 100,
106106
SCREEN_UPPER_LIMIT + 10, 20, Raylib::BLACK
107107
)

examples/text/text_font_filters.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
Raylib.draw_text_ex(font, msg, font_position, font_size, 0, Raylib::BLACK)
9999

100100
Raylib.draw_rectangle(0, SCREEN_HEIGHT - 80, SCREEN_WIDTH, 80, Raylib::LIGHTGRAY)
101-
Raylib.draw_text(Raylib.text_format('Font size: %02.02f', :float, font_size), 20, SCREEN_HEIGHT - 50, 10, Raylib::DARKGRAY)
102-
Raylib.draw_text(Raylib.text_format('Text size: [%02.02f, %02.02f]', :float, text_size.x, :float, text_size.y), 20, SCREEN_HEIGHT - 30, 10, Raylib::DARKGRAY)
101+
Raylib.draw_text('Font size: %02.02f' % font_size, 20, SCREEN_HEIGHT - 50, 10, Raylib::DARKGRAY)
102+
Raylib.draw_text('Text size: [%02.02f, %02.02f]' % [text_size.x, text_size.y], 20, SCREEN_HEIGHT - 30, 10, Raylib::DARKGRAY)
103103
Raylib.draw_text('CURRENT TEXTURE FILTER:', 250, 400, 20, Raylib::GRAY)
104104

105105
case current_font_filter

0 commit comments

Comments
 (0)