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

Dynamic Resize window and image buttons #5

Open
milkcoke opened this issue Apr 1, 2023 · 0 comments
Open

Dynamic Resize window and image buttons #5

milkcoke opened this issue Apr 1, 2023 · 0 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@milkcoke
Copy link
Owner

milkcoke commented Apr 1, 2023

Image buton size is dynamically resized according to window size

Refer to this repository

resize_layout.go

package layout

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/widget"
	xlayout "fyne.io/x/fyne/layout"
	"github.com/milkcoke/toolbox-gui/src/assets"
	"image/color"
)

func (appConfig *AppConfig) LoadResizeLayout(win fyne.Window) (buttonContainer *fyne.Container) {
       // ..

	totalWidth := float32(1200)
	totalHeight := float32(800)

	hBox := container.NewHBox(downloadDirPathBtn, pathLabel)
	line := container.NewBorder(canvas.NewLine(color.White), nil, nil, nil)

	hBoxSize := hBox.MinSize()
	lineSize := line.MinSize()
	remainHeight := totalHeight - (hBoxSize.Height + lineSize.Height)
	buttonWidth := totalWidth / 3.08
	buttonHeight := remainHeight / 3.08

        // ✅ Responsive and resize the container 
	responsiveContainer := xlayout.NewResponsiveLayout(
		container.NewMax(pythonImgBtn, container.NewCenter(pythonProgress)),
		container.NewMax(nodeImgBtn, container.NewCenter(nodeProgress)),
		container.NewMax(goImgBtn, container.NewCenter(goProgress)),
		container.NewMax(dockerImgBtn, container.NewCenter(dockerProgress)),
		container.NewMax(postmanImgBtn, container.NewCenter(postmanProgress)),
		container.NewMax(notionImgBtn, container.NewCenter(notionProgress)),
	)

	buttonsContainer := container.New(layout.NewGridWrapLayout(fyne.NewSize(buttonWidth, buttonHeight)),
		container.NewMax(pythonImgBtn, container.NewCenter(pythonProgress)),
		container.NewMax(nodeImgBtn, container.NewCenter(nodeProgress)),
		container.NewMax(goImgBtn, container.NewCenter(goProgress)),
		container.NewMax(dockerImgBtn, container.NewCenter(dockerProgress)),
		container.NewMax(postmanImgBtn, container.NewCenter(postmanProgress)),
		container.NewMax(notionImgBtn, container.NewCenter(notionProgress)),
	)

	buttonsContainer.Size()

	vboxContainer := container.NewVBox(
		hBox,
		line,
		container.NewMax(responsiveContainer), 
	)

	return vboxContainer
}
@milkcoke milkcoke added the good first issue Good for newcomers label Apr 1, 2023
@milkcoke milkcoke self-assigned this Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant