walk icon indicating copy to clipboard operation
walk copied to clipboard

Unable to set MaxSize

Open Merith-TK opened this issue 4 years ago • 7 comments

I am working on a wallpaper tool. So far it works, but i cant seem to make it NON-RESIZABLE The MaxSize does nothing at all

package main

import (
	"fmt"
	"io/ioutil"
	"strings"

	"github.com/h2non/filetype"
	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"
	"github.com/reujab/wallpaper"
)

var image string

//Main Process/window
func main() {
	fmt.Println("Wallpaper v2.1")
	var textEdit *walk.TextEdit
	MainWindow{
		Title:   "Wallpaper Tool",
		Size: Size{320, 240},
		MinSize: Size{320, 240},
		MaxSize: Size{320, 240},
		Layout:  VBox{},

		// Listen for file being drag'n'dropped
		OnDropFiles: func(files []string) {
			textEdit.SetText(strings.Join(files, "\r\n"))
			//set 'wallpaper' to the filepath of said image
			image = strings.Join(files, "\r\n")

			//check what type of file the provided file is
			buf, err := ioutil.ReadFile(image)
			if err != nil {
				panic(err)
			}

			// See if file is a image
			if filetype.IsImage(buf) {
				textEdit.SetText(strings.Join(files, "\r\n"))
				wallpaper.SetFromFile(image)
			} else {
				fmt.Println("The File is not a Image")
				textEdit.SetText("The File is not a Image")
			}
		},
		Children: []Widget{
			TextEdit{
				AssignTo: &textEdit,
				ReadOnly: true,
				Text:     "Drag your desired wallpaper here.",
			},
		},
	}.Run()
}

Merith-TK avatar Sep 11 '19 18:09 Merith-TK

Sets the window size change event. Just set it to the size of the original window when the window changes. I've asked the author before that the maximize button can't be disabled.

suoyukii avatar Oct 15 '19 06:10 suoyukii

Okay, how do i do that?

Merith-TK avatar Oct 15 '19 21:10 Merith-TK

package main

import (
	"fmt"

	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"
	"github.com/lxn/win"
)

var (
	window *walk.MainWindow
	width  int = 320
	height int = 240
	x      int = 200
	y      int = 200
)

func main() {
	fmt.Println("Wallpaper v2.1")
	MainWindow{
		Title:    "Wallpaper Tool",
		AssignTo: &window,
		Layout:   VBox{},
		OnSizeChanged: func() {
			window.SetWidth(width)
			window.SetHeight(height)
			window.SetX((int(win.GetSystemMetrics(0)) - width) / 2)
			window.SetY((int(win.GetSystemMetrics(1)) - height) / 2)
		},
	}.Run()
}

suoyukii avatar Oct 16 '19 14:10 suoyukii

@Merith-TK Can't you?

suoyukii avatar Oct 19 '19 06:10 suoyukii

havent had the time to get to that, sorry, still busy with other things

Merith-TK avatar Oct 20 '19 03:10 Merith-TK

Just was able to test it, it sorta works, however it still opens at the max size

Merith-TK avatar Sep 01 '20 17:09 Merith-TK

@Merith-TK You mean even though you set MainWindow.Size it opens at full size ? I don't have that behaviour.

Did you just try copy/pase exactly of @HeyDon-Lee's example ? If so, you're missing the size attribute.

alkanna avatar Jan 11 '21 11:01 alkanna