4
$\begingroup$

Mathematica makes use of nine-patch images in styling its resizable interfaces like Panel and Button. Nicer than remaking new ones for our own work, though, would be to repurpose the internal ones.

The general way this works is via something like:

Button[
 Style["Blah", Hue[0, .1, .9], Bold],
 Null,
 FrameMargins -> {{10, 10}, {0, 0}},
 Appearance ->
  {
   "Default" -> 
    FrontEnd`FileName[{"Dialogs", "Activation"}, 
     "RedButton-Default.9.png"],
   "Hover" -> 
    FrontEnd`FileName[{"Dialogs", "Activation"}, 
     "RedButton-Hover.9.png"],
   "Pressed" ->
    FrontEnd`FileName[{"Dialogs", "Activation"}, 
     "RedButton-Pressed.9.png"]
   }
 ]

enter image description here

The question, then is how do we find all possible options for this FrontEnd`FileName.

I'm gonna leave this question open in case someone has a really smooth answer, but I thought I'd lay it out there that the complete search path for these looks like:

ToFileName /@ 
 AbsoluteCurrentValue[$FrontEndSession, {PrivatePaths, "Bitmaps"}]

So at a minimum we can use:

fefnames =
  With[{fp = FileNameSplit[#[[2]]]},
     FrontEnd`FileName[Evaluate@Most[fp], Evaluate[Last[fp]]]
     ] & /@
   StringSplit[
    FileNames[
     "*.9.png",
     ToFileName /@ 
      AbsoluteCurrentValue[$FrontEndSession, {PrivatePaths, 
        "Bitmaps"}],
     3
     ],
    FileNameJoin@{"SystemResources", "Bitmaps"}
    ];

And we can visualize these like:

Dataset[AssociationMap[
  RawBoxes@DynamicBox@FEPrivate`ImportImage[#] &, fefnames]]

enter image description here

I'm down for anything cleaner or more complete, though (or if someone wants to repurpose that into their own answer I'll delete this)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.