{-|
PriLabels are labels with a priority.
PriLabels are usefull when widgets can have their label set multiple
times. This happens with genericcally created widgets. For example in:
data Foo = Foo { someName :: Bar }
data Bar = Bar Int
widgets created from Bar instances can have labels set due it's
constructor name and the fieldName in Foo (someName). A GUI
application programmer may also set the widgets label.
When a widget has set it's label multiple times, the priority can be
used to decide which label should be chosen.
-}moduleGraphics.UI.SybWidget.PriLabel(PriLabel(..),Priority(..),badConstrLabel,goodConstrLabel,fieldNameLabel,userDefinedLabel,bestLabel,humanizeLabel,defaultLabel,labelless)whereimportData.Char-- |Prioritized label. If two 'PriLabel' can be used for some-- component, then the one with highest priority is used.dataPriLabel=PriLabel{priority::Priority,labelString::String}deriving(Show,Eq)-- |The label priority.dataPriority=BadConstr|GoodConstr|FieldName|UserDefinedderiving(Show,Ord,Eq,Bounded,Enum)badConstrLabel,goodConstrLabel,fieldNameLabel,userDefinedLabel::String->PriLabelbadConstrLabellabel=PriLabelBadConstrlabelgoodConstrLabellabel=PriLabelGoodConstrlabelfieldNameLabellabel=PriLabelFieldNamelabeluserDefinedLabellabel=PriLabelUserDefinedlabel-- |Creates a default (lowest priority) PriLabeldefaultLabel::String->PriLabeldefaultLabellabel=PriLabelBadConstrlabellabelless::PriLabellabelless=defaultLabel""-- |Choose label with highest priority. If equal then choose the left-- |(first parameter) label.bestLabel::PriLabel->PriLabel->PriLabelbestLabelleft@(PriLabelpriL_)right@(PriLabelpriR_)|priL>=priR=left|otherwise=right-- |Humanized label strings, by turning labels like "someLabelName"-- into "Some label name".humanizeLabel::PriLabel->PriLabelhumanizeLabel(PriLabelprilabel)=PriLabelprilabel'wherelabel'|pri==UserDefined||not(and(mapisLegitCharlabel))-- safegaurd against accidentally calling humanizeLabel twice -- and against parsing special labels like "()"=label|elem'_'label=(firsttoUpper.nonCamel)label|otherwise=camelCaselabel-- humanizing non-camel case identifiersisLegitCharx=isAlphaNumx||elemx['_','\'']nonCamel[]=[]nonCamel('_':[])=[]nonCamel(x:[])=x:[]nonCamel('_':x:[])=' ':toUpperx:[]nonCamel(x:y:[])=x:nonCamel[y]nonCamel('_':x:y:xs)|isUppery=' ':toUpperx:nonCamel(y:xs)|otherwise=' ':toLowerx:nonCamel(y:xs)nonCamel(x:xs)=x:nonCamelxs--camelCase[]=[]camelCase(x:xs)=toUpperx:(seperateWords[]xs)seperateWordscs[]=csseperateWords[](x:xs)|isUpperx=' ':seperateWords[x]xs|otherwise=x:seperateWords[]xsseperateWords(c:[])(x:xs)|isUpperx=seperateWords(c:x:[])xs|otherwise=toLowerc:x:seperateWords[](xs)seperateWords(cs)(x:xs)|isUpperx=seperateWords(cs++[x])xs|otherwise=(initcs)++' ':(toLower$lastcs):x:seperateWords[]xsfirst_[]=[]firstf(x:xs)=(fx):xs