I'd like to create a button that works like the gif below. I'm not concerned with the content of the field changing. I just want to learn how to create a button that looks and works like the one in the gif. The button should be clickable on the top and bottom and temporarily become blue when clicked so that you know you clicked it. Togglerbar and setterbar do not seem to work this way. Is there another button option or a modification that I can use to get this functionality?
Asked
Active
Viewed 364 times
2 Answers
7
You can use two individual instances of Button
Column[{
Button["\[UpArrow]", Print["up"]],
Button["\[DownArrow]", Print["down"]]},
Spacings -> -1]
Unfortunately Button misbehaves on some systems when it comes to changing its size to just encompass its label (see this question). You might also notice a small optical glitch (visible in the .gif above as well) that when pressing the top button, part of the bottom button gets hidden behind a white margin.
Together with an InputField and smaller labels to fit in one row with the InputField the whole thing might look like this
DynamicModule[{x = 0},
Row[{
InputField[Dynamic@x, FieldSize -> 2],
Column[{
Button["\[FilledUpTriangle]", x++, ImageSize -> Small],
Button["\[FilledDownTriangle]", x--, ImageSize -> Small]},
Spacings -> -0.65]
}]
]
4
I thought this would fun to try. I got something close, but perhaps not close enough to get a cigar.
With[{size = 20},
up =
Graphics[
{Circle[{0, .75}, 1, {0, π}],
Line[{{-1, .75}, {-1, 0}, {1, 0}, {1, .75}}],
Triangle[{{-.75, .75}, {0, 1.5}, {.75, .75}}]},
ImageSize -> size];
down =
Graphics[
Rotate[#, 180 °, {0, 0}] & /@
{Circle[{0, .75}, 1, {0, π}],
Line[{{-1, .75}, {-1, 0}, {1, 0}, {1, .75}}],
Triangle[{{-.75, .75}, {0, 1.5}, {.75, .75}}]},
ImageSize -> size]];
Manipulate[
n,
{{n, 0}, None},
Panel[
Column[
{Button[up, n++, Appearance -> None],
Button[down, n--, Appearance -> None]},
Spacings -> 0],
ContentPadding -> False,
FrameMargins -> None],
AppearanceElements -> None,
ControlPlacement -> Right]
This certainly has the desired functionality. The question is whether or not it fakes the desired look-and-feel well enough.
Sascha
- 8,459
- 2
- 32
- 66
m_goldberg
- 107,779
- 16
- 103
- 257
-
-
You are welcome:) if you are using macOS I can highly recommend this app for capturing .gif files from your screen – Sascha Dec 16 '16 at 07:44




Button[]. It seems you can't go smaller than a certain width for some reason, unless you change appearance to "palette". http://mathematica.stackexchange.com/questions/100990/making-a-button-smaller-in-width – B flat Dec 16 '16 at 08:31