From df43cb2554fd520d2776b6e812434f67b9f25ba8 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 4 Jan 2023 15:32:26 +0000 Subject: [PATCH] Canvas: make setVisible chainable Change Element.setVisible to return self, so it can be chain called like most other setters. Note this also requires some C++ changes in FlightGear. --- Nasal/canvas/api/element.nas | 1 + Nasal/canvas/gui/dialogs/WidgetsFactoryDialog.nas | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Nasal/canvas/api/element.nas b/Nasal/canvas/api/element.nas index ae8e19737..e1bb2c738 100644 --- a/Nasal/canvas/api/element.nas +++ b/Nasal/canvas/api/element.nas @@ -55,6 +55,7 @@ var Element = { # @param visible Whether the element should be visible setVisible: func(visible = 1) { me.setBool("visible", visible); + return me; }, getVisible: func { diff --git a/Nasal/canvas/gui/dialogs/WidgetsFactoryDialog.nas b/Nasal/canvas/gui/dialogs/WidgetsFactoryDialog.nas index 2b6694b61..aa8a22cf6 100644 --- a/Nasal/canvas/gui/dialogs/WidgetsFactoryDialog.nas +++ b/Nasal/canvas/gui/dialogs/WidgetsFactoryDialog.nas @@ -47,12 +47,11 @@ var WidgetsFactoryDialog = { m.tab_2.addItem(m.button); m.image = gui.widgets.Label.new(m.tabsContent, style, {}) .setImage("Textures/Splash1.png") + .setVisible(0) .setFixedSize(128, 128); + m.tab_2.addItem(m.image); - # XXX: setVisible(0) must be called AFTER adding the widget to the layout - # doing that before layout.addItem causes FG to crash with a SIGSEGV - # see https://sourceforge.net/p/flightgear/mailman/flightgear-devel/thread/CABg8F9Rb87Fy%252B2ppXjJouYcZH9xyiQxts-jkdrPq0GK_Ymq-6w%2540mail.gmail.com/ - m.image.setVisible(0); + m.checkable_button = gui.widgets.Button.new(m.tabsContent, style, {}) .setCheckable(1) .setChecked(0)