It is currently February 25th, 2021, 10:34 pm

Advanced custom skin context menus

Tips and Tricks from the Rainmeter Community
User avatar
jsmorley
Developer
Posts: 21546
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Advanced custom skin context menus

Post by jsmorley »

Custom skin context menus

Rainmeter has the capability to add custom skin Context Menus, which allows you to add functionality to the standard skin context menu when you right-click the skin.

In addition, you can use the !SkinCustomMenu bang to have your custom context menu appear at the current mouse position, independent of the normal skin context menu. Just your "custom" menu entries will appear.

Example:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
ContextTitle=My Actions
ContextAction=[]
ContextTitle2=---
ContextAction2=[]
ContextTitle3=Refresh Skin
ContextAction3=[!Refresh "#CURRENTCONFIG#"]
ContextTitle4=Refresh All
ContextAction4=[!Refresh "*"]
ContextTitle5=Refresh Rainmeter
ContextAction5=[!RefreshApp]

[MeterSkinDemo]
Meter=String
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=RIGHT-Click Me#CRLF#Full Skin Context Menu

[MeterSkinBangDemo]
Meter=String
Y=5R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=LEFT-Click Me#CRLF#Full Skin Context Menu
LeftMouseUpAction=[!SkinMenu]

[MeterSkinCustomDemo]
Meter=String
Y=5R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=LEFT-Click Me#CRLF#Custom Skin Context Menu
LeftMouseUpAction=[!SkinCustomMenu]
1.jpg
Some limitations

There is a limit of 15 sets of ContextTitle / ContextAction in a single skin. So in one [Rainmeter] section of a skin, you can only define up to 15 context menu items, including any "separators" you define.

Some limit needed to be set, so a context menu isn't defined that runs off the screen. The current limit is 15 items per skin.

If you are using the !SkinCustomMenu bang multiple times on different meters, you may want to have different custom context menus appear depending on which meter you click. With a skin with all items defined in the [Rainmeter] section of that skin, that isn't possible. All items (up to the 15 maximum) you define are part of a single context menu for the skin.

An advanced solution

The solution for creating more robust context menu functionality involves using multiple skins. One will be the main or "parent" skin the user sees and interacts with, and then you can have an unlimited number of what I call "context skins" that are simply meant to provide different custom skin context menus for that "parent" skin. These context skins don't measure or display anything, other than a context menu associated with them.

The best way to explain is to just give you an example skin and a little animation of how it might work and look. Then I will describe a couple of tricks I used to make it work.
ContextDemo_1.0.rmskin
Click to animate
test.gif
So you have no custom context menu in the "parent' (ContextDemo.ini) skin at all. (although you certainly could) Instead you have LeftMouseUpAction options on the meters, to load (!ActivateConfig) a particular "context skin" (Context1.ini, Context2.ini, Context3.ini) that are contained in sub-folders of that parent skin. That way they can be loaded at the same time the parent is.

In each of the small context skins, You simply have the context items you want defined (again up to 15 in each) and an OnRefreshAction that automatically fires the context menu at the mouse location when the context skin is loaded.

Then when the user selects one of the context items, the actions are fired, and the little skin context menu closes itself.

Note that you specify a config parameter on your bangs, as the intent is to have the context items in each context skin cause changes to the "parent" skin.

One last little housekeeping trick is to have each of the context skins in a group, and then have the parent skin !DeactivateConfigGroup this group when it is refreshed or obtains mouse focus. This is to ensure that if the user selects a context menu, but doesn't select an item from it (which means the little context skin may not be "unloaded") the parent skin makes sure all the little context skins are always unloaded as they should be.

The folders
2.jpg
The code

ContextDemo.ini

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
OnRefreshAction=[!DeactivateConfigGroup "ContextMenus"]
OnFocusAction=[!DeactivateConfigGroup "ContextMenus"]

[Metadata]
Name=ContextDemo
Author=JSMorley
Version=Jan 9, 2015
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Information=Demonstration of Rainmeter skin context menus

[Variables]
FontSize=11
FontColor=255,255,255,255
FontFace=Arial

[MeterExample]
Meter=String
FontFace=#FontFace#
FontSize=#FontSize#
FontColor=#FontColor#
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=abcdefghijkl#CRLF#ABCDEFGHIJKL#CRLF#0123456789
DynamicVariables=1

[MeterContext1]
Meter=String
Y=10R
FontFace=#FontFace#
FontSize=#FontSize#
FontColor=#FontColor#
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Change FontSize
DynamicVariables=1
LeftMouseUpAction=[!ActivateConfig "ContextDemo\Context1" "Context1.ini"]

[MeterContext2]
Meter=String
Y=2R
FontFace=#FontFace#
FontSize=#FontSize#
FontColor=#FontColor#
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=Change FontColor
LeftMouseUpAction=[!ActivateConfig "ContextDemo\Context2" "Context2.ini"]

[MeterContext3]
Meter=String
Y=2R
FontFace=#FontFace#
FontSize=#FontSize#
FontColor=#FontColor#
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=Change FontFace
LeftMouseUpAction=[!ActivateConfig "ContextDemo\Context3" "Context3.ini"]
Context1.ini

Code: Select all

[Rainmeter]
Group=ContextMenus
ContextTitle=Select FontSize
ContextAction=[]
ContextTitle2=---
ContextAction2=[]
ContextTitle3=9
ContextAction3=[!SetVariable FontSize "9" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle4=10
ContextAction4=[!SetVariable FontSize "10" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle5=11
ContextAction5=[!SetVariable FontSize "11" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle6=20
ContextAction6=[!SetVariable FontSize "20" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle7=30
ContextAction7=[!SetVariable FontSize "30" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]

OnRefreshAction=[!SkinCustomMenu]

[MeterDummy]
Meter=String
Context2.ini

Code: Select all

[Rainmeter]
Group=ContextMenus
ContextTitle=Select FontColor
ContextAction=[]
ContextTitle2=---
ContextAction2=[]
ContextTitle3=White
ContextAction3=[!SetVariable FontColor "255,255,255,255" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle4=Red
ContextAction4=[!SetVariable FontColor "255,119,110,255" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle5=Green
ContextAction5=[!SetVariable FontColor "201,255,201,255" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle6=Blue
ContextAction6=[!SetVariable FontColor "201,221,255,255" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle7=Cyan
ContextAction7=[!SetVariable FontColor "219,255,255,255" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]

OnRefreshAction=[!SkinCustomMenu]

[MeterDummy]
Meter=String
Context3.ini

Code: Select all

[Rainmeter]
Group=ContextMenus
ContextTitle=Select FontFace
ContextAction=[]
ContextTitle2=---
ContextAction2=[]
ContextTitle3=Arial
ContextAction3=[!SetVariable FontFace "Arial" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle4=Trebuchet MS
ContextAction4=[!SetVariable FontFace "Trebuchet MS" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle5=Segoe UI
ContextAction5=[!SetVariable FontFace "Segoe UI" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle6=Calibri
ContextAction6=[!SetVariable FontFace "Calibri" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]
ContextTitle7=Tahoma
ContextAction7=[!SetVariable FontFace "Tahoma" "ContextDemo"][!UpdateMeter "*" "ContextDemo"][!Redraw "ContextDemo"][!DeactivateConfig #CURRENTCONFIG#]

OnRefreshAction=[!SkinCustomMenu]

[MeterDummy]
Meter=String
Note that I just used !SetVariable in my example, so the changes are "temporary". If you wanted the change to be permanent, you would want to use both !WriteKeyValue and !SetVariable / !SetOption bangs when you make some change.

Let me know if you have any questions.
You do not have the required permissions to view the files attached to this post.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4226
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Advanced custom skin context menus

Post by eclectic-tech »

I was just trying to do this same thing using @includes and was striking out...

Thanks! :great:
User avatar
winterwulf
Posts: 94
Joined: August 17th, 2016, 1:48 am
Location: São Paulo - Brazil

Re: Advanced custom skin context menus

Post by winterwulf »

Thank you so much for this tutorial! :D

I have one lil problem tho, after I activate the custom context menu, it wont unload.

Initially thats ok, because the user wont notice it, but on restart it will show up at X=0 Y=0 (left upper corner) of the screen.
is there a easy way to fix it?

Thanks!

EDIT: Answering my question, I got it done with

Code: Select all

OnUnfocusAction=[!DeactivateConfig]
Stratosteel
Posts: 12
Joined: December 13th, 2016, 10:28 pm

Re: Advanced custom skin context menus

Post by Stratosteel »

Nice tutorial, but is there any way to bold an action title?

EDIT: There is not a way :confused:
Last edited by Stratosteel on December 19th, 2016, 4:23 am, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 21546
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Advanced custom skin context menus

Post by jsmorley »

Stratosteel wrote:Nice tutorial, but is there any way to bold an action title?
There is not.