From c94329e2735f184953b01b460509607f015858aa Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 9 Jan 2023 11:28:18 -0500 Subject: [PATCH] Added useful run methods to ParentHooks --- tomo.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tomo.go b/tomo.go index b51ec47..ca57fd2 100644 --- a/tomo.go +++ b/tomo.go @@ -43,6 +43,29 @@ type ParentHooks struct { SelectionRequest func () } +// RunDraw runs the Draw hook if it is not nil. If it is nil, it does nothing. +func (hooks ParentHooks) RunDraw (region Image) { + if hooks.Draw != nil { + hooks.Draw(region) + } +} + +// RunMinimumSizeChange runs the MinimumSizeChange hook if it is not nil. If it +// is nil, it does nothing. +func (hooks ParentHooks) RunMinimumSizeChange (width, height int) { + if hooks.MinimumSizeChange != nil { + hooks.MinimumSizeChange(width, height) + } +} + +// RunSelectionRequest runs the SelectionRequest hook if it is not nil. If it is +// nil, it does nothing. +func (hooks ParentHooks) RunSelectionRequest () { + if hooks.SelectionRequest != nil { + hooks.SelectionRequest() + } +} + // Element represents a basic on-screen object. type Element interface { // Element must implement the Image interface. Elements should start out