The following solution is slightly more general than @Istvàn's answer, and also fixes the icon-size to what seems to be the standard.
First, we define
ClearAll[summaryForm];
summaryForm[name_, icon_, infos_, maxInfos_, form_, expr_] := Interpretation[
RawBoxes@Quiet@Check[
Module[{shown, hidden},
(* convert info-table into summary items *)
{shown, hidden} = Map[BoxForm`MakeSummaryItem[#, form]&, TakeDrop[infos, maxInfos], {2}];
(* arrange the summary and make sure the label is gray (therefore StyleBox) *)
StyleBox[BoxForm`ArrangeSummaryBox[
name,
expr,
Deploy@Show[icon,
(* avoid gray background before mouse-over *)
Background -> White,
(* set standard image size *)
ImageSize -> Dynamic[{
Automatic,
3.5 CurrentValue["FontCapHeight"]/AbsoluteCurrentValue[Magnification]
}]
],
shown,
hidden,
form,
(* formatted object should be uasable as input *)
"Interpretable" -> True
], "NonInterpretableSummary"]
],
(* in case something goes wrong *)
ToBoxes@Panel@Short[expr]
],
expr
]
Now you can specify automatic formatting for your own function, using
Format[testfunction[x_], StandardForm] := summaryForm[
"testfunction",
Graphics[{Circle[], Disk[{0,0},1,{0,x}]}],
{{"Even: ",EvenQ[x]},{"Value: ",x},{"Prime: ",PrimeQ[x]}},2,
StandardForm,
x
]
Then testfunction
is displayed as
testfunction[2]
And of course you can use it as input, and the opener works as expected:
(* -15 *)
Using summaryForm
it does not matter how your object is structured internally, and, once defined, you can use it to create many different kinds of formatted objects with very little additional code.
Since this Q&A is a bit hard to find if you don't know how this feature is called, I mention a few more functions which have these summary panels: InterpolatingFunction
, TimeSeries
, EventSeries
, DataDistribution
.