Skip to content

Instantly share code, notes, and snippets.

@fushnisoft
Created July 31, 2012 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fushnisoft/d18a4600c9925cd07e22 to your computer and use it in GitHub Desktop.
Save fushnisoft/d18a4600c9925cd07e22 to your computer and use it in GitHub Desktop.
Clarion clock widget, using AdjustFontSizeByHeight for prompt resizing
PROGRAM
INCLUDE('EQUATES.CLW') !Include standard equates
MAP
Main PROCEDURE()
AdjustFontSizeByHeight PROCEDURE(LONG xDesiredHInPixels, UNSIGNED xFEQ)
END
CODE
Main()
Main PROCEDURE()
Window WINDOW,AT(,,300,99),GRAY,IMM,SYSTEM,FONT('Segoe UI',,,,CHARSET:ANSI),TIMER(100), |
RESIZE
BOX,AT(-1,-1,304,17),USE(?BoxHeader),COLOR(040403EH),FILL(0262523H),LINEWIDTH(4)
PROMPT('Prompt 1'),AT(7,3),USE(?PromptHeader),TRN,FONT(,,0D4D4D3H,,CHARSET:ANSI)
BOX,AT(-1,86,304,13),USE(?BoxFooter),COLOR(040403EH),FILL(0262523H),LINEWIDTH(1)
BOX,AT(0,15,300,72),USE(?BoxMain),COLOR(COLOR:Black),FILL(COLOR:Black), |
LINEWIDTH(1)
PROMPT('Time'),AT(7,19),USE(?PromptTime),FONT(,20,0D4D4D3H,,CHARSET:ANSI), |
COLOR(COLOR:Black)
BOX,AT(-4,49,304,37),USE(?BoxDayDate),COLOR(040403EH),FILL(0262523H),LINEWIDTH(1)
PROMPT('Day'),AT(7,54),USE(?PromptDay),FONT(,12,0494744H,,CHARSET:ANSI), |
COLOR(0262523H)
PROMPT('Time'),AT(7,66),USE(?PromptDate),FONT(,12,0757270H,,CHARSET:ANSI), |
COLOR(0262523H)
PROMPT('Prompt 1'),AT(7,88),USE(?PromptFooter),TRN,FONT(,7,0D4D4D3H,,CHARSET:ANSI)
END
CODE
Open(Window)
0{PROP:Pixels} = 1
0{PROP:Buffer} = 1
?PromptHeader{PROP:Text} = 'Put a location here e.g. NETHERLANDS'
?PromptFooter{PROP:Text} = 'Current Time (GMT +/- <timezone>)'
ACCEPT
CASE Event()
OF EVENT:Timer
?PromptTime{PROP:Text} = Format(Clock(), @T3)
EXECUTE (Today()+1)%7
?PromptDay{PROP:Text} = 'Sunday'
?PromptDay{PROP:Text} = 'Monday'
?PromptDay{PROP:Text} = 'Tuesday'
?PromptDay{PROP:Text} = 'Wednesday'
?PromptDay{PROP:Text} = 'Thursday'
?PromptDay{PROP:Text} = 'Friday'
?PromptDay{PROP:Text} = 'Saturday'
END
?PromptDate{PROP:Text} = Format(Today(), @D17)
OF EVENT:Sized
! Some quick and dirty positioning. This would be using the ABC resizer class in a real app!
?BoxHeader{PROP:Width} = 0{PROP:Width} + 2
?BoxMain{PROP:Width} = 0{PROP:Width} + 6
?BoxDayDate{PROP:Ypos} = 0{PROP:Height} - ?BoxDayDate{PROP:Height} - ?BoxFooter{PROP:Height}
?BoxDayDate{PROP:Width} = 0{PROP:Width} + 6
?BoxMain{PROP:Height} = ?BoxDayDate{PROP:Ypos} - ?BoxHeader{PROP:Height} + 5
?PromptDay{PROP:Ypos} = ?BoxDayDate{PROP:Ypos} + 5
?PromptDate{PROP:Ypos} = ?BoxDayDate{PROP:Ypos} + 25
?BoxFooter{PROP:Ypos} = 0{PROP:Height} - ?BoxFooter{PROP:Height}
?BoxFooter{PROP:Width} = 0{PROP:Width} + 2
?PromptFooter{PROP:Ypos} = ?BoxFooter{PROP:Ypos} + 2
AdjustFontSizeByHeight(?BoxMain{PROP:Height}-10, ?PromptTime)
?PromptTime{PROP:Ypos} = ?BoxMain{PROP:Ypos} + 2
?PromptTime{PROP:Xpos} = 5
END
END
AdjustFontSizeByHeight PROCEDURE(LONG xDesiredHInPixels, UNSIGNED xFEQ)
holdPixels LONG
CODE
holdPixels = 0{PROP:Pixels}
0{PROP:Pixels} = TRUE
IF xFEQ{PROP:Height} < xDesiredHInPixels
DO SearchByIncreasing
ELSIF xFEQ{PROP:Height} > xDesiredHInPixels
DO SearchByDecreasing
END
0{PROP:Pixels} = HoldPixels
SearchByIncreasing ROUTINE
LOOP
IF xFEQ{PROP:Height} = xDesiredHInPixels
BREAK
ELSIF xFEQ{PROP:Height} > xDesiredHInPixels
xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} - 1
BREAK
ELSE
xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} + 1
END
END
SearchByDecreasing ROUTINE
LOOP
IF xFEQ{PROP:Height} = xDesiredHInPixels
BREAK
ELSIF xFEQ{PROP:Height} < xDesiredHInPixels
xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} + 1
BREAK
ELSE
xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} - 1
END
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment