Skip to content

Commit

Permalink
Replace Raylib.text_format with native string interpolation and forma…
Browse files Browse the repository at this point in the history
…tting
  • Loading branch information
wilsonsilva committed Oct 26, 2023
1 parent 3fbfd73 commit b26f794
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/audio/audio_mixed_processor-broken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
Raylib.clear_background(Raylib::RAYWHITE)

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

Raylib.draw_rectangle(199, 199, 402, 34, Raylib::LIGHTGRAY)
400.times do |i|
Expand Down
6 changes: 3 additions & 3 deletions examples/core/core_custom_frame_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@

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

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)
Raylib.draw_text(Raylib.text_format("PosX: %03.0f", :double, position), position.to_i - 50, Raylib.get_screen_height / 2 + 40, 20, Raylib::BLACK)
Raylib.draw_text("%03.0f ms" % (time_counter * 1000.0), position.to_i - 40, Raylib.get_screen_height / 2 - 100, 20, Raylib::MAROON)
Raylib.draw_text("PosX: %03.0f" % position, position.to_i - 50, Raylib.get_screen_height / 2 + 40, 20, Raylib::BLACK)

Raylib.draw_text("Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate.", 10, 10, 20, Raylib::DARKGRAY)
Raylib.draw_text("PRESS SPACE to PAUSE MOVEMENT", 10, Raylib.get_screen_height - 60, 20, Raylib::GRAY)
Raylib.draw_text("PRESS UP | DOWN to CHANGE TARGET FPS", 10, Raylib.get_screen_height - 30, 20, Raylib::GRAY)
Raylib.draw_text(Raylib.text_format("TARGET FPS: %i", :int, target_fps), Raylib.get_screen_width - 220, 10, 20, Raylib::LIME)
Raylib.draw_text("TARGET FPS: #{target_fps}", Raylib.get_screen_width - 220, 10, 20, Raylib::LIME)
# TODO: This is causing Infinity (FloatDomainError) error
# 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)

Expand Down
8 changes: 4 additions & 4 deletions examples/core/core_input_gamepad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
Raylib.clear_background(Raylib::RAYWHITE)

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

# Implement drawing logic
gamepad_name = Raylib.get_gamepad_name(0)
Expand Down Expand Up @@ -170,18 +170,18 @@
end

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

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

detected_button = Raylib.get_gamepad_button_pressed

if detected_button != Raylib::GAMEPAD_BUTTON_UNKNOWN
Raylib.draw_text(Raylib.text_format("DETECTED BUTTON: %i", :int, detected_button), 10, 430, 10, Raylib::RED)
Raylib.draw_text("DETECTED BUTTON: #{detected_button}", 10, 430, 10, Raylib::RED)
else
Raylib.draw_text("DETECTED BUTTON: NONE", 10, 430, 10, Raylib::GRAY)
end
Expand Down
4 changes: 1 addition & 3 deletions examples/core/core_input_multitouch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
touch_positions.each do |touch_position|
if touch_position.x > 0 && touch_position.y > 0
Raylib.draw_circle_v(touch_position, 34, Raylib::ORANGE)
Raylib.draw_text(
Raylib.text_format("%d", :int, i), touch_position.x - 10, touch_position.y - 70, 40, Raylib::BLACK
)
Raylib.draw_text(i.to_s, touch_position.x - 10, touch_position.y - 70, 40, Raylib::BLACK)
end
end

Expand Down
2 changes: 1 addition & 1 deletion examples/core/core_random_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

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

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

Raylib.end_drawing
end
Expand Down
2 changes: 1 addition & 1 deletion examples/core/core_window_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def draw_window_flag_state(flag_name, flag_value, key, y_position)
Raylib.draw_fps(10, 10)

Raylib.draw_text(
Raylib.text_format("Screen Size: [%i, %i]", :int, Raylib.get_screen_width, :int, Raylib.get_screen_height),
"Screen Size: [#{Raylib.get_screen_width}, #{Raylib.get_screen_height}]",
10,
40,
10,
Expand Down
4 changes: 2 additions & 2 deletions examples/core/core_window_letterbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
end

Raylib.draw_text("If executed inside a window,\nyou can resize the window,\nand see the screen scaling!", 10, 25, 20, Raylib::WHITE)
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)
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)
Raylib.draw_text("Default Mouse: [#{mouse.x.to_i} , #{mouse.y.to_i}]", 350, 25, 20, Raylib::GREEN)
Raylib.draw_text("Virtual Mouse: [#{virtual_mouse.x.to_i} , #{virtual_mouse.y.to_i}]", 350, 55, 20, Raylib::YELLOW)
Raylib.end_texture_mode

Raylib.begin_drawing
Expand Down
2 changes: 1 addition & 1 deletion examples/core/core_world_screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
)

Raylib.draw_text(
Raylib.text_format("Cube position in screen space coordinates: [%i, %i]", :int, cube_screen_position.x, :int, cube_screen_position.y),
"Cube position in screen space coordinates: [#{cube_screen_position.x.to_i}, #{cube_screen_position.y.to_i}]",
10,
10,
20,
Expand Down
2 changes: 1 addition & 1 deletion examples/shapes/shapes_collision_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

# Draw collision area
Raylib.draw_text(
Raylib.text_format('Collision Area: %i', :int, box_collision.width * box_collision.height),
Raylib.text_format("Collision Area: #{(box_collision.width * box_collision.height).to}"),
(Raylib.get_screen_width / 2) - 100,
SCREEN_UPPER_LIMIT + 10, 20, Raylib::BLACK
)
Expand Down
4 changes: 2 additions & 2 deletions examples/text/text_font_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
Raylib.draw_text_ex(font, msg, font_position, font_size, 0, Raylib::BLACK)

Raylib.draw_rectangle(0, SCREEN_HEIGHT - 80, SCREEN_WIDTH, 80, Raylib::LIGHTGRAY)
Raylib.draw_text(Raylib.text_format('Font size: %02.02f', :float, font_size), 20, SCREEN_HEIGHT - 50, 10, Raylib::DARKGRAY)
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)
Raylib.draw_text('Font size: %02.02f' % font_size, 20, SCREEN_HEIGHT - 50, 10, Raylib::DARKGRAY)
Raylib.draw_text('Text size: [%02.02f, %02.02f]' % [text_size.x, text_size.y], 20, SCREEN_HEIGHT - 30, 10, Raylib::DARKGRAY)
Raylib.draw_text('CURRENT TEXTURE FILTER:', 250, 400, 20, Raylib::GRAY)

case current_font_filter
Expand Down
2 changes: 1 addition & 1 deletion examples/text/text_input_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def is_any_key_pressed

Raylib.draw_text(name, text_box.x.to_i + 5, text_box.y.to_i + 8, 40, Raylib::MAROON)

Raylib.draw_text(Raylib.text_format('INPUT CHARS: %i/%i', :int, letter_count, :int, MAX_INPUT_CHARS), 315, 250, 20, Raylib::DARKGRAY)
Raylib.draw_text("INPUT CHARS: #{letter_count}/#{MAX_INPUT_CHARS}", 315, 250, 20, Raylib::DARKGRAY)

if mouse_on_text
if letter_count < MAX_INPUT_CHARS
Expand Down
4 changes: 2 additions & 2 deletions examples/textures/textures_bunnymark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def self.create(position, speed, color)
end

Raylib.draw_rectangle(0, 0, SCREEN_WIDTH, 40, Raylib::BLACK)
Raylib.draw_text(Raylib.text_format('bunnies: %i', :int, bunnies_count), 120, 10, 20, Raylib::GREEN)
Raylib.draw_text(Raylib.text_format('batched draw calls: %i', :int, 1 + (bunnies_count / MAX_BATCH_ELEMENTS)), 320, 10, 20, Raylib::MAROON)
Raylib.draw_text("bunnies: #{bunnies_count}", 120, 10, 20, Raylib::GREEN)
Raylib.draw_text("batched draw calls: #{1 + (bunnies_count / MAX_BATCH_ELEMENTS)}", 320, 10, 20, Raylib::MAROON)

Raylib.draw_fps(10, 10)
Raylib.end_drawing
Expand Down
2 changes: 1 addition & 1 deletion examples/textures/textures_sprite_anim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
)

Raylib.draw_text('FRAME SPEED: ', 165, 210, 10, Raylib::DARKGRAY)
Raylib.draw_text(Raylib.text_format('%02i FPS', :int, frames_speed), 575, 210, 10, Raylib::DARKGRAY)
Raylib.draw_text('%02i FPS' % frames_speed, 575, 210, 10, Raylib::DARKGRAY)
Raylib.draw_text('PRESS RIGHT/LEFT KEYS to CHANGE SPEED!', 290, 240, 10, Raylib::DARKGRAY)

MAX_FRAME_SPEED.times do |i|
Expand Down

0 comments on commit b26f794

Please sign in to comment.