GTK Scale/Volume Buttons Show Muted Icon on Startup
Ron Tarrant
rontarrant at gmail.com
Thu Apr 25 11:36:26 UTC 2019
I've scoured the docs, the wrapper code, the Internet, but can't
come up with an explanation...
When running this example of a VolumeButton, no matter what the
initial value of the slider, the icon showing is
audio-volume-muted.
I wrote up a second test using the parent, a ScaleButton, passing
a list of icons to the constructor. The order of the icons in the
string array is correct, but the result was the same as with the
VolumeButton. The muted icon shows on startup despite the initial
value.
After fiddling with either one of these, moving the value up or
down, the icons behave as described in the docs.
I've put both buttons in this one sample code file below.
Another odd thing...
If I run this example repeatedly, sometimes it doesn't find the
icon set for one of the buttons. When it can't find the icons,
and which button it can't find them for, seems to be random. This
also happens if only one of these buttons is present in the code.
```
// Test Rig Foundation for Learning GtkD Coding
import std.stdio;
import gtk.MainWindow;
import gtk.Main;
import gtk.Box;
import gtk.Widget;
import gtk.VolumeButton;
import gtk.ScaleButton;
import gtk.Adjustment;
import gtk.c.types;
void main(string[] args)
{
Main.init(args);
TestRigWindow myTestRig = new TestRigWindow("Test Rig with
VolumeButton");
Main.run();
} // main()
class TestRigWindow : MainWindow
{
int borderWidth = 10;
int width = 250;
int height = 175;
AppBox appBox;
this(string title)
{
super(title);
addOnDestroy(&quitApp);
setBorderWidth(borderWidth);
setSizeRequest(width, height);
appBox = new AppBox();
add(appBox);
showAll();
} // this() CONSTRUCTOR
void quitApp(Widget widget)
{
writeln("Bye.");
Main.quit();
} // quitApp()
} // class myAppWindow
class AppBox : Box
{
MyVolumeButton myVolumeButton;
MyScaleButton myScaleButton;
this()
{
super(Orientation.VERTICAL, 10);
myVolumeButton = new MyVolumeButton();
packStart(myVolumeButton, false, false, 0);
myScaleButton = new MyScaleButton();
packStart(myScaleButton, false, false, 0);
} // this()
} // class AppBox
class MyScaleButton : ScaleButton
{
double minimum = 0;
double maximum = 10;
double step = 1;
Adjustment adjustment;
double initialValue = 0;
double pageIncrement = 1;
double pageSize = 0;
string[] icons = ["audio-volume-muted", "audio-volume-high",
"audio-volume-low", "audio-volume-medium"];
// string[] icons = ["audio-volume-low", "audio-volume-high"];
this()
{
super(IconSize.BUTTON, minimum, maximum, step, icons);
adjustment = new Adjustment(initialValue, minimum, maximum,
step, pageIncrement, pageSize);
setAdjustment(adjustment);
addOnValueChanged(&valueChanged);
} // this()
void valueChanged(double value, ScaleButton sb)
{
writeln(getValue());
} // valueChanged()
} // class MyScaleButton
class MyVolumeButton : VolumeButton
{
double minimum = 0;
double maximum = 10;
double step = 1;
Adjustment adjustment;
double initialValue = 7;
double pageIncrement = 1;
double pageSize = 1;
this()
{
super();
adjustment = new Adjustment(initialValue, minimum, maximum,
step, pageIncrement, pageSize);
setAdjustment(adjustment);
addOnValueChanged(&valueChanged);
} // this()
void valueChanged(double value, ScaleButton sb)
{
writeln(getValue());
} // valueChanged()
} // class MyVolumeButton
```
More information about the Digitalmars-d-learn
mailing list