Skip to content

Commit

Permalink
Transparent example: makes frameless windows movable with simple impl…
Browse files Browse the repository at this point in the history
…ementation
  • Loading branch information
cjbrigato committed Jan 12, 2025
1 parent 0f4b762 commit 6260aad
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions examples/transparent/transparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,43 @@ import (
g "github.com/AllenDang/giu"
)

var (
wnd *g.MasterWindow
isMovingFrame = false
)

func FramelessMovableWidget(widget g.Widget) *g.CustomWidget {

Check failure on line 18 in examples/transparent/transparent.go

View workflow job for this annotation

GitHub Actions / Lint

exported: exported function FramelessMovableWidget should have comment or be unexported (revive)
return g.Custom(func() {
if isMovingFrame && !g.IsMouseDown(g.MouseButtonLeft) {
isMovingFrame = false
return
}
widget.Build()

Check failure on line 24 in examples/transparent/transparent.go

View workflow job for this annotation

GitHub Actions / Lint

expressions should not be cuddled with blocks (wsl)
if g.IsItemHovered() {

Check failure on line 25 in examples/transparent/transparent.go

View workflow job for this annotation

GitHub Actions / Lint

if statements should only be cuddled with assignments (wsl)
if g.IsMouseDown(g.MouseButtonLeft) {
isMovingFrame = true
}
}
if isMovingFrame {

Check failure on line 30 in examples/transparent/transparent.go

View workflow job for this annotation

GitHub Actions / Lint

if statements should only be cuddled with assignments (wsl)
delta := imgui.CurrentIO().MouseDelta()
dx := int(delta.X)
dy := int(delta.Y)
if dx != 0 || dy != 0 {

Check failure on line 34 in examples/transparent/transparent.go

View workflow job for this annotation

GitHub Actions / Lint

only one cuddle assignment allowed before if statement (wsl)
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 +80,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 6260aad

Please sign in to comment.