Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

futher "Canvas" or "CanvasObjekt" to easy draw #2924

Closed
MatejMagat305 opened this issue Apr 15, 2022 · 8 comments
Closed

futher "Canvas" or "CanvasObjekt" to easy draw #2924

MatejMagat305 opened this issue Apr 15, 2022 · 8 comments

Comments

@MatejMagat305
Copy link
Contributor

MatejMagat305 commented Apr 15, 2022

Well this is similar to #856 and #2228, but I really hope that is not duplication .......

Is your feature request related to a problem? Please describe:

The Canvas Object are little bit complication to draw picture to game like https://github.com/gonutz/prototype/blob/main/samples/screenshots/games.png

Is it possible to construct a solution with the existing API?

yes, but verry hard to render picture per pixel Image. ..............

Describe the solution you'd like to see:

two options:

  1. litle modificate https://github.com/ajstarks/fc and make from this futher "Canvas" or "CanvasObjekt", ../fc is based on fyne and use NewContainerWithoutLayout and canvas.Rectangle to backround, there is isues Combining fc with fyne (proper) ajstarks/fc#2 ...
  2. make futher "Canvas" or "CanvasObjekt" with similar functionality:
canvasObject.Circle(50, 0, 100, blue)
canvasObject.CText(50, 25, 10, "hello, world", white)
canvasObject.Image(50, 75, 200, 200, "earth.jpg")

Position of object inside would be relative to canvasObject position.

(edited)There is example how I was able to combinate funkcionality of .../fc and fyne:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
	"golang.org/x/image/colornames"
	"image/color"

	"github.com/ajstarks/fc"
)

func main() {
	width := 500
	height := 500
	blue := color.RGBA{0, 0, 255, 255}
	white := color.RGBA{255, 255, 255, 255}

	canvas := fc.NewCanvas("hello", width, height)

	canvas.Circle(50, 0, 100, blue)
	canvas.Rect(20, 25, 20, 40, colornames.Green)
	canvas.CText(50, 25, 10, "hello, world", white)
	canvas.Image(50, 75, 200, 200, "earth.jpg")

	window := createWindow(canvas)
	window.ShowAndRun()
}

func createWindow(c fc.Canvas) fyne.Window {
	w := c.Window
	w.Resize(fyne.NewSize(float32(c.Width), float32(c.Height)))
	w.SetFixedSize(true)
	w.SetPadded(false)
	hello := widget.NewLabel("Hello Fyne!")
	w.SetContent(container.NewVBox(
		hello,
		widget.NewButton("Hi!", func() {
			hello.SetText("Welcome :)")
		}),
		c.Container,
	))
	return w
}

it is good library, but it would be better to embed it .........

@MatejMagat305
Copy link
Contributor Author

maybe change constructor and it is ordinary "CanvasObject" without hard work .................

@andydotxyz
Copy link
Member

If you wish to render a pixel-specific image please use canvas.Raster - everything else is scaled according to device and user preference.

@andydotxyz
Copy link
Member

I’m not sure what this is asking for - everything illustrated is already possible

@Jacalz
Copy link
Member

Jacalz commented Apr 15, 2022

I read it as wishing to have something like what Java Swing does where you can do something like g2d.drawCircle() (and so on) to draw things directly on a canvas without needing to add things into a container. Each time you repaint (or refresh in our case) the canvas, you draw on a clean canvas instead of drawing more things in the old one. Do I understand that correctly?

@MatejMagat305
Copy link
Contributor Author

@Jacalz yes, something like Java Swing or JavaFX ..........

@MatejMagat305
Copy link
Contributor Author

MatejMagat305 commented Apr 16, 2022

i M REALY SORRY above is not clear..........., the point is: there is library fc based on fyne, which has functionality similar Java Swing or JavaFX and it would be awesome to embed this like futher CanvasObject, above mention issues (and my experiment) show it behave similar (if not equal) like CanvasObject so why not ...., of course there are some useles redundancy, but I think after small modification ................

@andydotxyz
Copy link
Member

I think fc does implement CanvasObject, so you can use it as described.
I don’t think that including it in Fyne core makes sense - the main API is a retained mode toolkit to build user applications. Graphical libraries like that and other can embed CanvasObject or Go Image component to mix modalities if you want - as you demonstrated already.

@Jacalz
Copy link
Member

Jacalz commented Apr 17, 2022

Indeed. If you think fc should integrate better with Fyne, then you probably should open an issue with them instead :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants