Skip to content

Commit

Permalink
Getting window bounds on NewUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Ray committed Jun 15, 2020
1 parent 1fd935a commit fa6b0cb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type UI struct {
}

// NewUI Creates the UI and setups up its internal structures
func NewUI(context *imgui.Context) *UI {
func NewUI(context *imgui.Context, win *pixelgl.Window) *UI {
ui := &UI{
context: context,
}
Expand All @@ -34,7 +34,7 @@ func NewUI(context *imgui.Context) *UI {
ui.batch = pixel.NewBatch(ui.tris, nil)

ui.io = imgui.CurrentIO()
ui.io.SetDisplaySize(imgui.Vec2{X: 1920, Y: 1080})
ui.io.SetDisplaySize(pixelVecToimguiVec(win.Bounds().Size()))

ui.fonts = ui.io.Fonts()
ui.fonts.AddFontDefault()
Expand Down Expand Up @@ -100,6 +100,7 @@ func (ui *UI) Draw(win *pixelgl.Window) {
shouldRender := true
for j := 0; j < 3; j++ {
idx := unsafe.Pointer(uintptr(idxStart) + indexBufferOffset)
indexBufferOffset += uintptr(indexSize)
index := *(*C.ushort)(idx)
ptr := unsafe.Pointer(uintptr(start) + (uintptr(int(index) * vertexSize)))
pos := (*imgui.Vec2)(unsafe.Pointer(uintptr(ptr) + uintptr(posOffset)))
Expand All @@ -116,8 +117,6 @@ func (ui *UI) Draw(win *pixelgl.Window) {
// (*tmp)[j].Picture = uuvv
(*tmp)[j].Color = color
(*tmp)[j].Intensity = 0.0

indexBufferOffset += uintptr(indexSize)
}
if shouldRender {
for j := 0; j < 3; j++ {
Expand Down Expand Up @@ -161,6 +160,10 @@ func imguiRectToPixelRect(r imgui.Vec4) pixel.Rect {
return pixel.R(float64(r.X), float64(r.Y), float64(r.X+r.Z), float64(r.Y+r.W))
}

func pixelVecToimguiVec(v pixel.Vec) imgui.Vec2 {
return imgui.Vec2{X: float32(v.X), Y: float32(v.Y)}
}

func (ui *UI) setKeyMapping() {
keys := map[int]pixelgl.Button{
imgui.KeyTab: pixelgl.KeyTab,
Expand Down

0 comments on commit fa6b0cb

Please sign in to comment.