some tips
MatejMagat305 opened this issue · comments
hello I am again sorry(I am only student who do not understand many things), but I am working on my bachalor and I would like to share tip how to improve code(if I do found and it is already exist, sorry):
- I was create interface "shape":
type Shape interface {
GetXY() (int, int)
SetXY(x, y int)
GetSize() (int, int)
SetSize(width, height int)
GetIdName() (int, string)
WasPressed() bool
WasActive() bool
In(x int, y int) bool
GetFunc() func(window draw.Window)
SetFunc(function func(window draw.Window))
Paint(window draw.Window, scaledText float32)
CarryEvent(window draw.Window)
}
- I was create several structures("basic", TextField, Label, CheckBox, Button), "basic" is implementing Shape and other have embed it, so all are Shape and can also overwrite method....... .
type Basic struct {
x, y, endX, endY, width, height float64
id int64
name string
pressed, active bool
function func(draw.Window)
}
......
- you can prepare slice
structures:= make([]Shape,...)
before "animation loop"(or during first turn - I have "init turn" because I use func "GetScaledText") and your "main code" will look like:
func DrawControlAll(window draw.Window) {
for i := 0; i < len(shapes); i++ {
shape := shapes[i]
shape.CarryEvent(window)
shape.Paint(window, 3)
}
}
- if you would like to control themself, you can also at init make lamda with references to themself like this:
label := my_package.NewLabel(name)
label.SetFunc(func(window draw.Window) {
label.DoSomeThingSpecial()//e.g. Hide by name
})
- this only tip ............
Sorry, I am not really sure what you are talking about. Do you mean that you can pass closures to things that use the draw.Window? I am really not sure whether you are proposing an improvement of this library or talking about how you apply this library to your use case. If you want to add something, you can either create a pull request, or if it is a thing that is worth talking about before implementing code that might go to waste, have an issue about. Please clarify what this issue is about.
Thanks for contributing anyway, I also saw the other issue, thanks!
sorry, this issue is more suitable to example than library...., i will create request in summer, ok?
Sure, thanks!