Board index FlightGear Development Canvas

Is it possible to color a button in the gui ?

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Is it possible to color a button in the gui ?

Postby abassign » Sat Dec 05, 2020 1:09 am

Hi, is it possible to color a button in the gui, both foreground and background?

This is my code:
Code: Select all
var button = canvas.gui.widgets.Button.new(aRoot, canvas.style, {} )
        .setFixedSize(width, 25)
        .setText(label);


It seems not, or at least not as it seemed natural to me, for example by entering this option:

Code: Select all
 .setColorBackground(1,1,1,0.8)


Which obviously doesn't work, otherwise I wouldn't have asked the question ...

Thanks for your collaboration
Developer of the program https://wiki.flightgear.org/Julia_photoscenery_generator
FDM developer of the G91R1B aircraft https://wiki.flightgear.org/FIAT_G91R1B
JSBSim collaborator
abassign
 
Posts: 947
Joined: Mon Feb 27, 2012 6:09 pm
Location: Italy (living 5 Km from airport LIME)
Callsign: I-BASSY
Version: 2020.4
OS: Ubuntu 20.10

Re: Is it possible to color a button in the gui ?

Postby Hooray » Sat Dec 05, 2020 1:45 am

look at the implementation, buttons are just raster images with a label, see $FG_ROOT/Nasal/canvas/styles/DefaultStyle.nas:

Code: Select all
 var bg_color_name = "button_bg_color";
    if( backdrop )
      bg_color_name = "button_backdrop_bg_color";
    else if( !model._enabled )
      bg_color_name = "button_bg_color_insensitive";
    else if( model._down )
      bg_color_name = "button_bg_color_down";
    else if( model._hover )
      bg_color_name = "button_bg_color_hover";
    me._bg.set("fill", me._style.getColor(bg_color_name));




So it's subject to default Canvas styling
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Canvas

Who is online

Users browsing this forum: No registered users and 3 guests