github.com/as/shiny@v0.8.2/driver/win32/size.go (about)

     1  
     2  // +build windows
     3  
     4  package win32
     5  
     6  import (
     7  	"syscall"
     8  	"unsafe"
     9  
    10  	"github.com/as/shiny/event/size"
    11  	"github.com/as/shiny/geom"
    12  	"github.com/as/shiny/screen"
    13  )
    14  
    15  type Size = size.Event
    16  
    17  var (
    18  	SizeEvent func(hwnd syscall.Handle, e size.Event)
    19  )
    20  
    21  func sendSizeEvent(hwnd syscall.Handle, uMsg uint32, wParam, lParam uintptr) (lResult uintptr) {
    22  	wp := (*WindowPos)(unsafe.Pointer(lParam))
    23  	if wp.Flags&SwpNosize != 0 {
    24  		return 0
    25  	}
    26  	sendSize(hwnd)
    27  	return 0
    28  }
    29  
    30  func sendSize(hwnd syscall.Handle) {
    31  	r := &Rectangle{}
    32  	if err := GetClientRect(hwnd, r); err != nil {
    33  		panic(err) // TODO(andlabs)
    34  	}
    35  
    36  	dx, dy := int(r.Dx()), int(r.Dy())
    37  	screen.SendSize(size.Event{
    38  		WidthPx:     dx,
    39  		HeightPx:    dy,
    40  		WidthPt:     geom.Pt(dx),
    41  		HeightPt:    geom.Pt(dy),
    42  		PixelsPerPt: 1,
    43  	})
    44  }