10
$\begingroup$

I have a stand alone Manipulator (it is not in a Manipulate) and would like to know how to alter the style of the label. There are no explicit styling options for Manipulator so I tried wrapping it in Style:

Style[
 Manipulator[0.5, AppearanceElements -> None,
  Appearance -> {"Labeled"}, ImageSize -> Small],
 FontSize -> 20]

this didn't work.

I have also noticed that I cannot set an image size other than a named size. In other words ImageSize does not accept a number!

Manipulator[0.5, AppearanceElements -> None,
  Appearance -> {"Labeled"}, ImageSize -> 100]

and

Manipulator[0.5, AppearanceElements -> None,
  Appearance -> {"Labeled"}, ImageSize -> 400]

produce the same output. Are these issues possible bugs or am I overlooking something?

Q1. How can I change the font size (and other font styling but mainly font size) for the Manipulator label?

Q2. How can I make ImageSize accept a number rather than a name?

Edit

My question is not about what alternatives exist to using Manipulator. I have posted an example with AppearanceElements -> None so as to make the label the sole focus. However I want the possibility of being able to add back in the AppearanceElements is desired/required. The setting AppearanceElements -> None obviously looks like a stand alone slider and has led to readers thinking in terms of sliders rather than "fixing" the Manipulator.

Edit #2

In situations when no Manipulator controls are wanted Slider is an alternative but it also has some strange behaviour:

Framed@Slider[Dynamic[x], Appearance -> "Labeled", BaseStyle -> FontSize -> 20, ImageSize -> 100]
Framed@Slider[Dynamic[x], Appearance -> "Labeled", BaseStyle -> FontSize -> 20, ImageSize -> 200]

enter image description here

So it appears that the label occupies the same image size as the slider! This presents a problem in a GUI layout but there is a work around:

Framed@Pane[Slider[Dynamic[x], Appearance -> "Labeled", 
BaseStyle -> FontSize -> 20, ImageSize -> 200], ImageSize -> 260]

enter image description here

But the image space allocated to the label looks like a bug or something unintended. This doesn't address my question but I add it here because slider answered have been given.

FWIW:

enter image description here

Edit #3

Tech support confirm that the strange image sizing for Slider when a label is used is a bug.

$\endgroup$
3
  • 2
    $\begingroup$ You may have checked it already, but inspecting the code for Manipulator04 in the file MiscExpressions.tr in $InstallationDirectory/SystemFiles/FrontEnd/TextResources directory may suggest an explanation for your frustrations. Basically, several parts of the elements you wish to control (such as FontSize, InlineInputField and InputField sizes with option settings are hard coded in Manipulator04. The code is not too long, and perhaps, with some effort, you can modify it make your own custom manipulator and/or define your custom styledata to use as the setting for BaseStyle ... $\endgroup$
    – kglr
    Commented Jun 25, 2012 at 7:38
  • $\begingroup$ I think I found the code fragment: If[#9,{InputFieldBox[#1, Expression,FieldSize -> {{4,10},{1,2}},Enabled -> #6,Appearance -> {"Frameless", #8},BaseStyle -> "Manipulator"]}, {}]... But when I changed it in a text editor Mma wouldn't start up. It suggests that a stylesheet is the only way to change this. $\endgroup$ Commented Jun 25, 2012 at 8:15
  • $\begingroup$ Labeled[Manipulator ... Style e.g.: Labeled[Manipulator[ Dynamic@nrDays, {0, 999, 1}], {Style[Dynamic@nrDays, 27, Bold], Style["Days: ", 23]}, {Right, Left}] $\endgroup$
    – Rabbit
    Commented May 7, 2022 at 20:58

5 Answers 5

7
$\begingroup$

I suppose you could roll your own, as in

s = 0.5;
Row[{Manipulator[Dynamic[s]], " ", 
  Style[Dynamic[s], FontSize -> 16]}]
$\endgroup$
0
7
$\begingroup$

To add to the spectrum of solutions here I suggest these approaches.

1) ----------- Magnify -----------

Magnify will uniformly change the size of Manipulator, its numeric label and everything that is related to that. It will work inside an interface too:

Manipulate[

 DynamicModule[{f = 1}, 
  Column@{Magnify[
     Manipulator[Dynamic[f], {0.25, 5}, AppearanceElements -> None, 
      Appearance -> "Labeled"], x], 
    Dynamic[Plot[Sin[f x], {x, -2 \[Pi], 2 \[Pi]}, ImageSize -> 500]]}]

 , {{x, 1, "Magnification of Manipulator"}, .5, 2, 
  Appearance -> "Labeled"}]

enter image description here

Disadvantage of course is that you cannot change the size of individual elements separately.

2) ----------- Ctrl+Shift+E -----------

I figured it out only for the Manipulator ImageSize, not the label. Maybe it is possible for label too. When you get you Manipulator select its cell, press CTRL+SHIFT+E, put numeric size as shown below, press CTRL+SHIFT+E again.

enter image description here

$\endgroup$
3
  • $\begingroup$ The Magnify approach doesn't fly, since as you have observed it magnifies the entire Manipulator. The ShowExpression stuff is interesting for trying to understand how this works -- but I'm not sure how it could be used for writing code. I guess you could do a replace on the underlying expression once the GUI has been generated. There doesn't seem to be anything that looks like a label size in the underlying expression (?) $\endgroup$ Commented Jun 25, 2012 at 6:18
  • $\begingroup$ @MikeHoneychurch yeah, Magnify is too constrained, but is a nice thing to know. Especially for people who need simpler things. Neat that it works inside interfaces. I could not track the label style either. Future will tell. $\endgroup$ Commented Jun 25, 2012 at 7:05
  • $\begingroup$ I'm logging it with tech support along with what looks to be the slider imagesize bug. $\endgroup$ Commented Jun 25, 2012 at 7:07
7
$\begingroup$

Based on the code digging by @kguler the internal code controlling this is:

FEPrivate`If[#9, {InputFieldBox[#1, Expression, 
   FieldSize -> {{4, 10}, {1, 2}}, Enabled -> #6, 
   Appearance -> {"Frameless", #8}, BaseStyle -> "Manipulator"]}, {}]

so it looks like you can change some of this via a style sheet -- for a notebook wide solution:

Cell[StyleData["Manipulator"],
 FontSize->18,
 Background->RGBColor[1,1,0]]

enter image description here

This still has its obvious limitations: it is notebook wide not local, (and if you wanted to adjust FieldSize to you can't), and the image size problem can't be solved by this approach. I don't regard this as a complete answer to the question but may be of interest.

Edit

Tech support confirm what can be inferred from the code that @kguler found -- namely that the label styling and numerical image size can not be set by the user programmatically.

To alter the label you have to use a stylesheet as per this answer. To alter the image size you would have to do that by changing the underlying expression in the output cell as per @Vitaliy's answer.

$\endgroup$
1
  • $\begingroup$ Looks like time to Accept this one to me. :-) $\endgroup$
    – Mr.Wizard
    Commented Jun 30, 2012 at 7:13
6
$\begingroup$

Use Slider in which case you can use numerical values for ImageSize.

Row[{Slider[Dynamic[n], {0, 100, 1}, ImageSize -> {150, 50}, 
   ImageMargins -> 10], Style[Dynamic[n], FontSize -> 16]}]
$\endgroup$
0
4
$\begingroup$

A Slider seems to have the options you want

Slider[0.5, Appearance -> "Labeled", BaseStyle -> FontSize -> 20, ImageSize -> 100]

enter image description here

I'm not sure of the differences between a Slider and a Manipulator

$\endgroup$
6
  • $\begingroup$ @belisarius I humbly apologize to those who posted alternatives for my criticism of the alternatives. $\endgroup$ Commented Jun 25, 2012 at 3:31
  • $\begingroup$ If you want to play the reputation game, there's a lot of time pressure to get an answer in. You will always have to expect a bunch of quick, incomplete and approximate answers. $\endgroup$
    – wxffles
    Commented Jun 25, 2012 at 3:41
  • $\begingroup$ @wxffles I can't speak for others but when I post a question I am looking for a considered answer not the fastest answer. No offense but posting the first thing that comes into your head is unhelpful ...as you can also see from my own edits and comments -- which also added nothing to the discussion. $\endgroup$ Commented Jun 25, 2012 at 3:45
  • $\begingroup$ @ wxffles your first comment seems now appearing out of thin air $\endgroup$ Commented Jun 25, 2012 at 4:48
  • $\begingroup$ @MikeHoneychurch I edited the post for you $\endgroup$ Commented Jun 25, 2012 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.