From 471737f421d61b1de9db35a6ced30f0485b79f08 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 29 Jun 2024 12:13:18 +1200 Subject: [PATCH] gui: add helper function for menu separators --- main.go | 4 +--- util_vcl.go | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 0316c3e..db597b6 100644 --- a/main.go +++ b/main.go @@ -105,9 +105,7 @@ func (f *TMainForm) OnFormCreate(sender vcl.IObject) { // - mnuSep := vcl.NewMenuItem(mnuFile) - mnuSep.SetCaption("-") // Creates separator - mnuFile.Add(mnuSep) + vcl_menuseparator(mnuFile) mnuFileExit := vcl.NewMenuItem(mnuFile) mnuFileExit.SetCaption("Exit") diff --git a/util_vcl.go b/util_vcl.go index cb23c7f..bc82efa 100644 --- a/util_vcl.go +++ b/util_vcl.go @@ -30,9 +30,22 @@ func vcl_row(owner vcl.IWinControl, top int32) *vcl.TPanel { func vcl_menuitem(parent *vcl.TMenuItem, caption string, imageIndex int32, onClick vcl.TNotifyEvent) *vcl.TMenuItem { m := vcl.NewMenuItem(parent) m.SetCaption(caption) - m.SetImageIndex(imageIndex) - m.SetOnClick(onClick) + if imageIndex != -1 { + m.SetImageIndex(imageIndex) + } + if onClick != nil { + m.SetOnClick(onClick) + } parent.Add(m) return m } + +// vcl_menuseparator adds a separator to the parent TMenuItem. +func vcl_menuseparator(parent *vcl.TMenuItem) *vcl.TMenuItem { + s := vcl.NewMenuItem(parent) + s.SetCaption("-") // Creates separator + parent.Add(s) + + return s +}