Kaynağa Gözat

JS window set position and better win32 default position

Karl Zylinski 2 ay önce
ebeveyn
işleme
8856d8919d
3 değiştirilmiş dosya ile 6 ekleme ve 3 silme
  1. 0 1
      examples/snake/snake.odin
  2. 4 1
      window_js.odin
  3. 2 1
      window_win32.odin

+ 0 - 1
examples/snake/snake.odin

@@ -99,7 +99,6 @@ main :: proc() {
 
 init :: proc() {
 	k2.init(WINDOW_SIZE, WINDOW_SIZE, "Snake")
-	k2.set_window_position(300, 300)
 
 	prev_time = time.now()
 

+ 4 - 1
window_js.odin

@@ -28,6 +28,7 @@ WINDOW_INTERFACE_JS :: Window_Interface {
 import "core:sys/wasm/js"
 import "base:runtime"
 import "core:log"
+import "core:fmt"
 
 js_state_size :: proc() -> int {
 	return size_of(JS_State)
@@ -229,7 +230,9 @@ js_clear_events :: proc() {
 }
 
 js_set_position :: proc(x: int, y: int) {
-	log.error("set_position not implemented in JS")
+	buf: [256]u8
+	js.set_element_style(s.canvas_id, "margin-top", fmt.bprintf(buf[:], "%vpx", x))
+	js.set_element_style(s.canvas_id, "margin-left", fmt.bprintf(buf[:], "%vpx", y))
 }
 
 js_set_size :: proc(w, h: int) {

+ 2 - 1
window_win32.odin

@@ -70,7 +70,8 @@ win32_init :: proc(window_state: rawptr, window_width: int, window_height: int,
 	hwnd := win32.CreateWindowW(CLASS_NAME,
 		win32.utf8_to_wstring(window_title),
 		style,
-		100, 10, r.right - r.left, r.bottom - r.top,
+		win32.CW_USEDEFAULT, win32.CW_USEDEFAULT,
+		r.right - r.left, r.bottom - r.top,
 		nil, nil, instance, nil,
 	)