Added working text input box

This commit is contained in:
Stefan Stefanov 2024-04-19 21:30:09 +03:00
parent 15e5ad3454
commit 8da1321bdd
4 changed files with 56 additions and 20 deletions

View file

@ -3,5 +3,5 @@
"activityBar.background": "#322C2D",
"titleBar.activeBackground": "#463E3F",
"titleBar.activeForeground": "#FAFAFA"
}
}
}

View file

@ -17,42 +17,61 @@ import rl "vendor:raylib"
PixelWindowHeight :: 180
GameMemory :: struct {}
FILE_DIALOG_SIZE :: 1000
GameMemory :: struct {
file_dialog_text_buffer: [FILE_DIALOG_SIZE + 1]u8,
}
g_mem: ^GameMemory
w, h: f32
game_camera :: proc() -> rl.Camera2D {
w := f32(rl.GetScreenWidth())
h := f32(rl.GetScreenHeight())
w = f32(rl.GetScreenWidth())
h = f32(rl.GetScreenHeight())
return {zoom = h / PixelWindowHeight, target = {}, offset = {w / 2, h / 2}}
}
scaling: f32 = 2
ui_camera :: proc() -> rl.Camera2D {
return {zoom = f32(rl.GetScreenHeight()) / PixelWindowHeight}
// return {zoom = f32(rl.GetScreenHeight()) / PixelWindowHeight}
return {zoom = scaling}
}
input_box_loc: rl.Vector2 = {}
moving_input_box: bool
update :: proc() {
// Update the width/height
w = f32(rl.GetScreenWidth())
h = f32(rl.GetScreenHeight())
rl.SetMouseScale(1 / scaling, 1 / scaling)
if rl.IsMouseButtonDown(.RIGHT) {
input_box_loc = rl.GetMousePosition()
}
}
draw :: proc() {
rl.BeginDrawing()
defer rl.EndDrawing()
rl.ClearBackground(rl.BLACK)
rl.BeginMode2D(game_camera())
// rl.DrawRectangleV(g_mem.player_pos, {4, 8}, rl.WHITE)
rl.DrawRectangleV({20, 20}, {10, 20}, rl.RED)
rl.EndMode2D()
rl.BeginMode2D(ui_camera())
// rl.DrawText(
// fmt.ctprintf("some_number: %v\nplayer_pos: %v", g_mem.some_number, g_mem.player_pos),
// 5,
// 5,
// 8,
// rl.WHITE,
// )
rl.GuiTextInputBox(
rl.Rectangle {
x = input_box_loc.x,
y = input_box_loc.y,
width = (w / scaling) / 2,
height = (h / scaling) / 2,
},
"Files",
"File input box",
"Button",
cstring(rawptr(&g_mem.file_dialog_text_buffer)),
FILE_DIALOG_SIZE,
nil,
)
rl.EndMode2D()
rl.EndDrawing()
}
}

15
src/input_box.odin Normal file
View file

@ -0,0 +1,15 @@
package game
import rl "vendor:raylib"
// Check if any key is pressed
// NOTE: We limit keys check to keys between 32 (KEY_SPACE) and 126
IsAnyKeyPressed :: proc() -> (keyPressed: bool) {
key := rl.GetKeyPressed()
if (i32(key) >= 32) && (i32(key) <= 126) {
keyPressed = true
}
return
}

View file

@ -1,5 +1,7 @@
package game
import rl "vendor:raylib"
@(export)
game_update :: proc() -> bool {
update()