It is currently November 21st, 2019, 10:18 am

Working with Angle on a String Meter (redux)

Our most popular Tips and Tricks from the Rainmeter Team and others
User avatar
jsmorley
Developer
Posts: 19743
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with Angle on a String Meter (redux)

jsmorley » September 14th, 2019, 12:03 pm

I doubt that there is any practical way to do this.

About the best you can do is something like:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeterOne]
Meter=String
X=20
StringAlign=Center
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
Text=V#CRLF#E#CRLF#R#CRLF#T#CRLF#I#CRLF#C#CRLF#A#CRLF#L

1.jpg

You might be able to write some Lua code that could evaluate a string and insert the #CRLF# variables.

Keep in mind that 1) You want to "center" the string, so when you are using variable-spaced fonts, the horizontal alignment of the various letters is correct, and 2) Be aware that you have NO control over how the letters are spaced vertically. It will be based on the default "line spacing" supported by the font you are using.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 19743
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with Angle on a String Meter (redux)

jsmorley » September 14th, 2019, 12:43 pm

This could probably be done in Lua like this:

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Lua]
Measure=Script
ScriptFile=#CURRENTPATH#Test.lua
Disabled=1

[MeterString]
Meter=String
X=20
StringAlign=Center
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
DynamicVariables=1
Text=[&Lua:AddCRLF('VERTICAL')]
Test.lua:

Code: Select all

function AddCRLF(stringArg)

	newString=string.gsub(stringArg, '(.-)', '%1\r\n')
	trimedString=string.gsub(newString, '^\r\n(.*)\r\n$', '%1')

	return trimedString

end

1.jpg


Or if you are getting the string value from a Measure:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Lua]
Measure=Script
ScriptFile=#CURRENTPATH#Test.lua
Disabled=1

[MeasureString]
Measure=String
String=VERTICAL

[MeterString]
Meter=String
X=20
StringAlign=Center
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
DynamicVariables=1
Text=[&Lua:AddCRLF('[&MeasureString]')]
You do not have the required permissions to view the files attached to this post.
User avatar
ryanchuang
Posts: 17
Joined: September 13th, 2019, 4:23 am

Re: Working with Angle on a String Meter (redux)

ryanchuang » September 14th, 2019, 3:04 pm

balala wrote:
September 14th, 2019, 11:52 am
Yes, but how do you add those #CRLF# variables between each two consecutive characters if it doesn't matter? Post please a sample code.
Right,you meant two consecutive characters from streaming weather condition from Weather.com?? Well,I think HipHopium's theme from Deviantart.com has one language file(.inc) which can automatically translate/define strings from consecutive letters to characters,I just added #CRLF# between the characters,it's doable;ex Conditions="Sunny Day":"晴#CRLF#天",

Hi.Jsmorley

Thank you for replying,I will try the Lua way later on because somehow I found the way to make multi-columns possible,I will show what I have accomplished so far.

This is theme I am working on,as you can see,it has ton of Chinese characters,but they all aligned horizontally with 9 rows from top to bottom. I would like to align them vertically with 9 columns from right to left:
Image
User avatar
jsmorley
Developer
Posts: 19743
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with Angle on a String Meter (redux)

jsmorley » September 14th, 2019, 3:19 pm

I really think this is just a bridge too far. I wouldn't even now where to start with this, and it would be a real Rube Goldberg deal in my view. You would need 9 relatively positioned meters, and then use Lua to do what I did before for each meter. This would be next to impossible to do with anything but some static text you define.
User avatar
ryanchuang
Posts: 17
Joined: September 13th, 2019, 4:23 am

Re: Working with Angle on a String Meter (redux)

ryanchuang » September 14th, 2019, 3:30 pm

Ha :D ,sorry,Jsmorley,

Yeah,I intentionally made the theme from HipHopium to fully being shown Chinese characters and some numerics only.

This is old Japanese poem,as you can see it was written from right to left:
Image

I do understand the latin letters could not write this way,that's why I come here for alternatives or solution at the first place.
User avatar
ryanchuang
Posts: 17
Joined: September 13th, 2019, 4:23 am

Re: Working with Angle on a String Meter (redux)

ryanchuang » September 14th, 2019, 3:45 pm

jsmorley wrote:
September 14th, 2019, 3:19 pm
This would be next to impossible to do with anything but some static text you define.
Yeah,any dynamic string would be define in the Language file(.inc) to make them vertically possible. :D
User avatar
balala
Rainmeter Sage
Posts: 9107
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Working with Angle on a String Meter (redux)

balala » September 14th, 2019, 9:05 pm

ryanchuang wrote:
September 14th, 2019, 3:04 pm
Well,I think HipHopium's theme from Deviantart.com has one language file(.inc) which can automatically translate/define strings from consecutive letters to characters,I just added #CRLF# between the characters,it's doable;ex Conditions="Sunny Day":"晴#CRLF#天",
Yep, it indeed is doable. However not very convenient, because:
  • There probably are a lot of string which have to be transformed this way one by one (a lot of work, with high probability to mistake).
  • For instance weather.com can translate the returned strings, there is no need to use a "translation" file. In a such case although not impossible to add the needed #CRLF# character between the consecutive letters, this would require to add a new String measure to the code for each returned string which has to be transformed in this way.
For instance supposing [MeasureDesc] returns the current weather condition and this is the string you'd like to transform in the described mode, you have to add the following measure:

Code: Select all

[MeasureDescRotate]
Measure=String
String=[MeasureDesc]
DynamicVariables=1
RegExpSubstitute=1
Substitute="(.)":"\1#CRLF#"
The above [MeasureDescRotate] returns the same string as [MeasureDesc], with a #CRLF# added between each two consecutive characters.
User avatar
ryanchuang
Posts: 17
Joined: September 13th, 2019, 4:23 am

Re: Working with Angle on a String Meter (redux)

ryanchuang » September 15th, 2019, 10:35 am

balala wrote:
September 14th, 2019, 9:05 pm
There probably are a lot of string which have to be transformed this way one by one (a lot of work, with high probability to mistake).
You're right,it's very repetitive and has to correct one by one by if something is not shown right.

balala wrote:
September 14th, 2019, 9:05 pm

[*]For instance weather.com can translate the returned strings, there is no need to use a "translation" file.
It does?? How?? I noticed that you're from Romania,does your weather theme for Rainmeter has Romanian from Weather.com?? I do know that Weather.com does has Română,but how does it work to show Romanian weather condition directly in Rainmeter theme,not through translate file (.inc)??

I will try your codes later on as I do not know to catch the localized weather condition directly from Weather.com without translated file (.inc).

Here is theme I have done,exactly what I have wanted:
Image
User avatar
balala
Rainmeter Sage
Posts: 9107
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Working with Angle on a String Meter (redux)

balala » September 15th, 2019, 3:14 pm

ryanchuang wrote:
September 15th, 2019, 10:35 am
It does?? How?? I noticed that you're from Romania,does your weather theme for Rainmeter has Romanian from Weather.com?? I do know that Weather.com does has Română,but how does it work to show Romanian weather condition directly in Rainmeter theme,not through translate file (.inc)??
Yep, it does and weather.com is able to return the strings into a lot of languages (including Romanian, but not just, Japanese, Korean, Chinese are also available). This is done by adding an appropriate parameter to the used URL. For instance let's take the following URL: http://wxdata.weather.com/wxdata/weather/local/#Location#?cc=*&unit=#Unit#&dayf=4&locale=#LanguageCode# (the newly added parameter is marked red).
This URL returns the string into the language specified by the LanguageCode variable. As you probably have figured it out, Location is the desired weather code, Unit is either m (metric), or i (imperial), while the LanguageCode variable specifies the language in which the strings are returned. You can find the possible values of this variable here.
User avatar
ikarus1969
Posts: 351
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Working with Angle on a String Meter (redux)

ikarus1969 » September 24th, 2019, 7:55 am

I played a little with creating vertical text that is read from right to left.
There are of course still the restrictions jsmorley talked about (mono-spaced font and vertical spacing). But if they doesn't matter you can probably use the following code (a combination of the skin and some lua code). The text in this skin is directly coded into a string-meter but could come from whatever source you like i guess:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=4080C0C0
SkinWidth=300

[Metadata]
Author=ikarus1969
Name=Vertical text
Description=Make text vertical, reading from right to left

[Variables]
SPACING_VAL=10
SENTENCE_DIVIDER=|


; --------------------------------------------------------------------------------
; Measures
; --------------------------------------------------------------------------------
[Measure_LUA]
Measure=SCRIPT
ScriptFile=TextVertical.lua
DIVIDER=#SENTENCE_DIVIDER#
CONTAIN_DIVIDER=0
DynamicVariables=1
UpdateDivider=-1

[Measure_Text]
Measure=STRING
String=But I must explain to you how this was born|I will give you a complete account|No one rejects or avoids pleasure itself|Nor is there anyone who loves to obtain pain|To take a trivial example|

[Measure_Text_V]
Measure=STRING
String=[&Measure_LUA:getVertical("[&Measure_Text]")]
RegexpSubstitute=1
Substitute=" ":"_"
OnUpdateAction=[!EnableMeasure "Measure_StartAlign"][!SetOption "Measure_StartAlign" "UpdateDivider" "1"][!UpdateMeasure "Measure_StartAlign"]
DynamicVariables=1
UpdateDivider=-1

[Measure_StartAlign]
Measure=CALC
Formula=[Meter_Vertical_Text:X]
IfConditionMode=1
IfCondition=[Meter_Vertical_Text:X] > 10
IfTrueAction= [!UpdateMeasure "Measure_Increase_Spacing"]
IfFalseAction=[!UpdateMeasure "Measure_Decrease_Spacing"][!SetOption "#CURRENTSECTION#" "UpdateDivider" "-1"][!UpdateMeasure "#CURRENTSECTION#"]
Disabled=1
UpdateDivider=-1
DynamicVariables=1

[Measure_Increase_Spacing]
Measure=CALC
Formula=#SPACING_VAL#
OnUpdateAction=[!SetVariable "SPACING_VAL" "(#SPACING_VAL# + 2)"][!UpdateMeter "Meter_Vertical_Text"][!Redraw]
UpdateDivider=-1
DynamicVariables=1

[Measure_Decrease_Spacing]
Measure=CALC
Formula=#SPACING_VAL#
OnUpdateAction=[!SetVariable "SPACING_VAL" "(#SPACING_VAL# - 2)"][!UpdateMeter "Meter_Vertical_Text"][!Redraw]
UpdateDivider=-1
DynamicVariables=1



; --------------------------------------------------------------------------------
; Meter(s)
; --------------------------------------------------------------------------------
[Meter_Vertical_Text]
Meter=STRING
MeasureName=Measure_Text_V
X=(#WORKAREAX# + 0.5 * #CURRENTCONFIGWIDTH#)
Y=10
InlineSetting= Face   | Courier New
InlineSetting2=Size   | 12
InlineSetting3=Color  | FFFFFFFF
InlineSetting4=Weight | 600
InlineSetting5=CharacterSpacing | 0 | #SPACING_VAL#
InlinePattern5=(?siU)([^#CRLF#]+)[^#CRLF#](#CRLF#|$)
InlineSetting6=Color  | FF000000
InlinePattern6=_
StringAlign=CENTER
AntiAlias=1
DynamicVariables=1

Code: Select all

-- LUA for vertical text

local ch_divider;
local contain_divider;

function Initialize()

  ch_divider      = SELF:GetOption('DIVIDER');
  contain_divider = tonumber(SELF:GetOption('CONTAIN_DIVIDER'));

  return 0;

end -- function Initialize

function Update()

  return 1;

end

function getVertical(parm_text)

  -- local ms            = SKIN:GetMeasure('Measure_Text');
  -- local parm_text     = ms:GetStringValue();
  local saetze        = {};
  local maxlen_saetze = 0;
  local satz;

  for satz in string.gmatch(parm_text, '([^%'..ch_divider..']+%'..ch_divider..')')
    do
      satz = string.gsub(satz, '^ -([^ ])', '%1');

      if contain_divider == 0 then
        satz = string.gsub(satz, ch_divider..'$', '');
      end

      if string.len(satz) > maxlen_saetze then
        maxlen_saetze = string.len(satz);
      end

      table.insert(saetze, satz);
    end


  local zeilen       = {};
  local indexZeichen = 0;
  local l, ch, aktueller_satz;

  for l = 1, maxlen_saetze
    do
      zeilen[l]    = '';
      indexZeichen = indexZeichen + 1;

      for aktueller_satz = 1, # saetze
        do

          if indexZeichen <= string.len(saetze[aktueller_satz]) then
            ch = string.sub(saetze[aktueller_satz], indexZeichen, indexZeichen);
          else
            ch = ' ';
          end

          zeilen[l] = ch..zeilen[l];
        end

    end

  local meterStr = '';

  for l = 1, # zeilen
    do
      if l == 1 then
        meterStr = zeilen[l];
      else
        meterStr = meterStr..'\r\n'..zeilen[l];
      end
    end

  return meterStr;

end