0.1.1 Refactoring almost done. /JL

This commit is contained in:
2022-12-17 15:53:29 +01:00
parent 9b5856ddf1
commit 1e4e718e0c
5 changed files with 223 additions and 146 deletions
+20 -3
View File
@@ -1,6 +1,10 @@
package main package main
import "github.com/lxn/walk" import (
"log"
"github.com/lxn/walk"
)
type ( type (
Canvas struct { Canvas struct {
@@ -8,6 +12,19 @@ type (
} }
) )
func NewCanvas() *Canvas { func CreateCanvasGroup(mw *MyMainWindow) {
return new(Canvas) log.Println("Creating canvas group...")
cg, _ := walk.NewGroupBox(mw.content)
cg.SetTitle("Canvas")
cg.SetAlignment(walk.AlignHNearVNear)
cg.SetLayout(walk.NewVBoxLayout())
log.Println("Creating canvas...")
mw.canvasScroll, _ = walk.NewScrollView(cg)
vb := walk.NewVBoxLayout()
mw.canvasScroll.SetLayout(vb)
mw.canvasScroll.SetAlignment(walk.AlignHNearVNear)
//vb.SetMargins(walk.Margins{0, 0, 0, 0})
//dw, _ := walk.NewCustomWidgetPixels(mw.canvasScroll, 0, mw.drawStuff)
//dw.SetClearsBackground(true)
//dw.SetInvalidatesOnResize(true)
} }
+15
View File
@@ -28,6 +28,21 @@ type (
} }
) )
func CreateBeadsGroup(mw *MyMainWindow) {
gb, _ := walk.NewGroupBox(mw.leftPanel)
gb.SetTitle("Beads")
gb.SetLayout(walk.NewVBoxLayout())
btn, _ := walk.NewPushButton(gb)
btn.SetText("Select all colors")
btn.Clicked().Attach(func() {
for _, bead := range mw.beads {
bead.Checkbox.SetChecked(true)
}
})
mw.colors, _ = walk.NewScrollView(gb)
mw.colors.SetLayout(walk.NewVBoxLayout())
}
func LoadBeads(mw *MyMainWindow) { func LoadBeads(mw *MyMainWindow) {
for _, brand := range mw.pallette.Brands.Brand { for _, brand := range mw.pallette.Brands.Brand {
if brand.BrandName == mw.brand_combo.Text() { if brand.BrandName == mw.brand_combo.Text() {
+28 -7
View File
@@ -6,12 +6,13 @@ import (
"os/user" "os/user"
"github.com/lxn/walk" "github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
) )
type MyMainWindow struct { type MyMainWindow struct {
*walk.MainWindow MainWindow *walk.MainWindow
content *walk.Composite
leftPanel *walk.Composite leftPanel *walk.Composite
rightPanel *walk.Composite
colors *walk.ScrollView colors *walk.ScrollView
canvasScroll *walk.ScrollView canvasScroll *walk.ScrollView
drawWidget *walk.CustomWidget drawWidget *walk.CustomWidget
@@ -29,7 +30,7 @@ type MyMainWindow struct {
const ( const (
AppName string = "BeadImager" AppName string = "BeadImager"
Version string = "0.1.0" Version string = "0.1.1"
CopyRight string = "©2022 Jan Lerking" CopyRight string = "©2022 Jan Lerking"
STD_MESS string = "Ready" STD_MESS string = "Ready"
LogFile string = "BeadImager.log" LogFile string = "BeadImager.log"
@@ -48,6 +49,20 @@ var (
ConfigBackgroundColor string ConfigBackgroundColor string
) )
func SetupMainWindow(mw *MyMainWindow) {
mw.MainWindow, _ = walk.NewMainWindow()
mw.MainWindow.SetTitle(AppName + " " + Version)
mw.MainWindow.SetMinMaxSize(walk.Size{Width: 800, Height: 600}, walk.Size{Width: math.MaxInt32, Height: math.MaxInt32})
//mw.MainWindow.SetSize(walk.Size{Width: 800, Height: 600})
vb := walk.NewVBoxLayout()
mw.MainWindow.SetLayout(vb)
vb.SetMargins(walk.Margins{5, 0, 5, 5})
mw.content, _ = walk.NewComposite(mw.MainWindow)
hb := walk.NewHBoxLayout()
mw.content.SetLayout(hb)
hb.SetMargins(walk.Margins{0, 0, 0, 0})
}
func main() { func main() {
// Get current user // Get current user
currentUser, err := user.Current() currentUser, err := user.Current()
@@ -74,15 +89,18 @@ func main() {
walk.ValidationErrorEffect, _ = walk.NewBorderGlowEffect(walk.RGB(255, 0, 0)) walk.ValidationErrorEffect, _ = walk.NewBorderGlowEffect(walk.RGB(255, 0, 0))
}) })
mw := &MyMainWindow{} mw := &MyMainWindow{}
SetupMainWindow(mw)
log.Println("MainWindow created") log.Println("MainWindow created")
CreatePallette(mw) CreatePallette(mw)
log.Println("Pallette created: ", mw.pallette) log.Println("Pallette created: ", mw.pallette)
mw.brand_model = CreateBrandsList(mw) mw.brand_model = CreateBrandsList(mw)
brand_trigged := false CreatePalletteGroup(mw)
serie_trigged := false CreateBeadsGroup(mw)
pegboard_trigged := false CreateCanvasGroup(mw)
settings_trigged := false CreateSettingsGroup(mw)
LoadBeads(mw)
/*
DD_Pallette := GroupBox{ DD_Pallette := GroupBox{
Title: "Pallette", Title: "Pallette",
Layout: VBox{}, Layout: VBox{},
@@ -235,6 +253,9 @@ func main() {
}.Run()); err != nil { }.Run()); err != nil {
log.Fatal(err) log.Fatal(err)
} }
*/
mw.MainWindow.Show()
mw.MainWindow.Run()
} }
func (mv *MyMainWindow) clearBackground(canvas *walk.Canvas, updateBounds walk.Rectangle) error { func (mv *MyMainWindow) clearBackground(canvas *walk.Canvas, updateBounds walk.Rectangle) error {
+9 -2
View File
@@ -76,11 +76,18 @@ type (
) )
func CreatePalletteGroup(mw *MyMainWindow) *walk.GroupBox { func CreatePalletteGroup(mw *MyMainWindow) *walk.GroupBox {
mw.leftPanel, _ = walk.NewComposite(mw.content)
vb := walk.NewVBoxLayout()
mw.leftPanel.SetLayout(vb)
vb.SetMargins(walk.Margins{0, 0, 0, 0})
mw.leftPanel.SetMinMaxSize(walk.Size{Width: 280, Height: 0}, walk.Size{Width: 280, Height: 0})
pallette_group, _ := walk.NewGroupBox(mw.leftPanel) pallette_group, _ := walk.NewGroupBox(mw.leftPanel)
pallette_group.SetTitle("Pallette") pallette_group.SetTitle("Pallette")
pallette_group.SetLayout(walk.NewVBoxLayout()) vb = walk.NewVBoxLayout()
pallette_group.SetLayout(vb)
comp, _ := walk.NewComposite(pallette_group) comp, _ := walk.NewComposite(pallette_group)
comp.SetLayout(walk.NewHBoxLayout()) hb := walk.NewHBoxLayout()
comp.SetLayout(hb)
comp.Layout().SetMargins(walk.Margins{0, 0, 0, 0}) comp.Layout().SetMargins(walk.Margins{0, 0, 0, 0})
lbl, _ := walk.NewLabel(comp) lbl, _ := walk.NewLabel(comp)
lbl.SetText("Brand:") lbl.SetText("Brand:")
+17
View File
@@ -29,6 +29,23 @@ type (
} }
) )
func CreateSettingsGroup(mw *MyMainWindow) {
log.Println("Setting up settings...")
mw.rightPanel, _ = walk.NewComposite(mw.content)
vb := walk.NewVBoxLayout()
mw.rightPanel.SetLayout(vb)
vb.SetMargins(walk.Margins{0, 0, 0, 0})
mw.rightPanel.SetMinMaxSize(walk.Size{Width: 220, Height: 0}, walk.Size{Width: 220, Height: 0})
sg, _ := walk.NewGroupBox(mw.rightPanel)
sg.SetTitle("Settings")
sg.SetAlignment(walk.AlignHNearVNear)
vb = walk.NewVBoxLayout()
sg.SetLayout(vb)
vb.SetMargins(walk.Margins{0, 0, 0, 0})
mw.propScroll, _ = walk.NewScrollView(sg)
ShowProperties(mw)
}
func ShowProperties(mw *MyMainWindow) { func ShowProperties(mw *MyMainWindow) {
log.Println("Showing properties") log.Println("Showing properties")
mw.properties = new(properties) mw.properties = new(properties)