Skip to content

Commit

Permalink
Merge pull request #935 from cjbrigato/frameless_movable_example
Browse files Browse the repository at this point in the history
Transparent example: makes frameless windows movable
  • Loading branch information
gucio321 authored Jan 12, 2025
2 parents 8fffff2 + 24fbb28 commit ac3f0dc
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions examples/transparent/transparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,47 @@ import (
g "github.com/AllenDang/giu"
)

var (
wnd *g.MasterWindow
isMovingFrame = false
)

func framelessMovableWidget(widget g.Widget) *g.CustomWidget {
return g.Custom(func() {
if isMovingFrame && !g.IsMouseDown(g.MouseButtonLeft) {
isMovingFrame = false
return
}

widget.Build()

if g.IsItemHovered() {
if g.IsMouseDown(g.MouseButtonLeft) {
isMovingFrame = true
}
}

if isMovingFrame {
delta := imgui.CurrentIO().MouseDelta()
dx := int(delta.X)
dy := int(delta.Y)

if dx != 0 || dy != 0 {
ox, oy := wnd.GetPos()
wnd.SetPos(ox+dx, oy+dy)
}
}
})
}

func loop() {
imgui.PushStyleVarFloat(imgui.StyleVarWindowBorderSize, 0)
g.PushColorWindowBg(color.RGBA{50, 50, 50, 0})
g.PushColorFrameBg(color.RGBA{10, 10, 10, 0})
g.PushColorWindowBg(color.RGBA{50, 50, 70, 130})
g.PushColorFrameBg(color.RGBA{30, 30, 60, 110})
g.SingleWindow().Layout(
framelessMovableWidget(
g.Label("Maintain Left-click on me to move the frameless window !"),
),
g.Custom(func() {
canvas := g.GetCanvas()
pos := g.GetCursorScreenPos()
Expand Down Expand Up @@ -48,7 +84,8 @@ func loop() {
}

func main() {
wnd := g.NewMasterWindow("transparent", 300, 200, g.MasterWindowFlagsNotResizable|g.MasterWindowFlagsFloating|g.MasterWindowFlagsFrameless|g.MasterWindowFlagsTransparent)
wnd = g.NewMasterWindow("transparent", 300, 200, g.MasterWindowFlagsNotResizable|g.MasterWindowFlagsFloating|g.MasterWindowFlagsFrameless|g.MasterWindowFlagsTransparent)
wnd.SetBgColor(color.RGBA{0, 0, 0, 0})
wnd.SetPos(50, 50)
wnd.Run(loop)
}

0 comments on commit ac3f0dc

Please sign in to comment.