fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
24.48k stars 1.36k forks source link

Transparent window background #181

Open hientt53 opened 5 years ago

hientt53 commented 5 years ago

Thank contributor for awesome repo and sorry for my English.

I want to make an app with a transparent background. I found the theme color: color.RGBA{} but param is unit32, A must type float ( example 0.2) to make a transparent background.

Can you give me some suggestion?

Thank again.

andydotxyz commented 5 years ago

For RGBA colours in Go it’s 0-255 instead of 0.0 to 1.0 - this means 0 is fully transparent and 255 is fully opaque...

However if you want to make the window transparent it may be more complicated as Fyne currently uses a fully opaque window.

hientt53 commented 5 years ago

thanks for quick reply, can you explain way make a window transparent. I need transparent for my screenshot tool, transparent window helps me select area want to capture.

prateekrastogi commented 5 years ago

Hoping for fluent design support in future :)

andydotxyz commented 5 years ago

I’m sorry to report but transparent windows are not supported yet. We would like to add it in the future, but the feature is not yet released in the library we use to show windows.

Blocked on #183

BabySid commented 2 years ago

Hi, I want to know whether transparent window is supported at present? I didn't find the corresponding API interface. I also want the splash window to be transparent in my application~

thanks.

andydotxyz commented 2 years ago

It is not added yet. The upstream blocker is now landed so it is technically possible. However there are complications around how background colour is used for many places and the default theme background colour is opaque so transparent windows will not be transparent without further work. This will probably require extra API to define what window background is separate from other type of background, I'm not sure. Or perhaps transparent window has no background, or a background override?

Thoughts or more information about the use-case or intended outcomes might help us design this right.

andydotxyz commented 2 years ago

For whoever picks this up, the GLFW component should be simple, just:

    glfw.WindowHint(glfw.TransparentFramebuffer, glfw.True)

It's the rest that will be hard ;)

BabySid commented 2 years ago

This will probably require extra API to define what window background is separate from other type of background, I'm not sure. Or perhaps transparent window has no background, or a background override?

Thoughts or more information about the use-case or intended outcomes might help us design this right.

thanks for reply.

In my application, I hope that as shown in the figure below, the white area in the middle is transparent, and the upper lines can move along the four sides of the white area. In this scene, I hope i can directly see the background of the desktop. At present, it is the background color of the theme. I wonder if I have described it clearly. sorry.

微信图片_20220301103702

andydotxyz commented 2 years ago

It would be useful to know more about how you will present the content. Are you using a custom theme to set certain colours or are you just using the canvas package and avoiding any themed elements like Widgets?

BabySid commented 2 years ago

It would be useful to know more about how you will present the content. Are you using a custom theme to set certain colours or are you just using the canvas package and avoiding any themed elements like Widgets?

Now, my code is as below

// I just use the default theme(light or dark)
// and hope there is a param which set the background of the win is transparent
w := drv.CreateSplashWindow() 

line := canvas.NewLine(color.NRGBA{R: 0, G: 0, B: 180, A: 128})
line.StrokeWidth = 5
line.Position1 = fyne.NewPos(0, 0)
line.Position2 = fyne.NewPos(50, 0)

w.SetContent(container.NewWithoutLayout(line))
w.Resize(fyne.NewSize(800, 600))
w.Show()

// create some animations to control the line's action along the window
// for example, from left to right, then from top to bottom……
...
a2 := canvas.NewPositionAnimation(fyne.NewPos(0, 0), fyne.NewPos(800, 0), time.Second*3, func(p fyne.Position) {
    line.Move(p)
    line.Refresh()
})
a2.RepeatCount = fyne.AnimationRepeatForever
a2.AutoReverse = true
a2.Curve = fyne.AnimationLinear
a2.Start()
....
JasperSurmont commented 6 months ago

Hey, this issue is quite old now and I was wondering if there is a way to do this by now?

I'm not afraid of getting my hands dirty so doing low level stuff would be okay for me. Specifically, my use case would be to draw figures (rectangles or circles) inside a transparent SplashWindow such that I can 'draw' these simple figures on top of another window.

andydotxyz commented 6 months ago

This issue has not progressed - if it had there would be info linked here. I think it is in part held back because this will impact both theme as well as window to get right.

On another note using a transparent window to draw over another may not be possible as there is no API for positioning windows, other than centrally or full screened.

JasperSurmont commented 6 months ago

Thanks for the answer. Would it theoretically be possible to create a GLFW window manually using the glfw library, such that transparency & position can be set, and then have Fyne perform actions on this window such as setting the content? I don't know a a lot about the internals, so I might be talking pure nonsense here 😄

andydotxyz commented 6 months ago

Fyne cannot paint into specific windows you create in other ways. You'd need to make the changes as a fork of the library, or discuss more the feature request - see how it relates to #1155

J7mbo commented 3 months ago

On another note using a transparent window to draw over another may not be possible as there is no API for positioning windows, other than centrally or full screened.

From my understanding, the only reason there is no API for positioning windows is because it's not wanted and "up to the window manager", even though we clearly want to be able to do this programmatically.

andydotxyz commented 3 months ago

I think your comments are better placed on #1155 where there is a long discussion about that topic.