1

I created a custom page which contains a label and two buttons to control the label's contents. I suppose to set the text of the label within callbacks of the buttons, as the following codes:

Function FuncShowNewFeature
  ; ...
  ; Add Controls
 
  ${NSD_CreateLabel} 0 13u 100% 12u "Show new features here"
  Pop $lblContents
  ${GraphicalInstallerRedrawLabel} $lblContents
  
  ${NSD_CreateButton} 0 -13u 40u 13u "Prev"
  Pop $btnPrev
  ${NSD_OnClick} $btnPrev PrevFeature ; callback
  
  ${NSD_CreateButton} -40u -13u 40u 13u "Next"
  Pop $btnNext
  ${NSD_OnClick} $btnNext NextFeature ; callback
  
  # Put this macro before EACH calling nsDialogs::Show to draw background properly
  ${GraphicalInstallerRedrawnsDialogsPage}
  nsDialogs::Show
FunctionEnd

Function NextFeature
  ${NSD_SetText} $lblContents "To show the next tip of new-feature"
  ${GraphicalInstallerRedrawLabel} $lblContents ;I don't know whether this macro is necessary here
FunctionEnd

Function PrevFeature
  ${NSD_SetText} $lblContents "To show the previous tip of new-feature"
  ${GraphicalInstallerRedrawLabel} $lblContents ;I don't know whether this macro is necessary here
FunctionEnd

But the result shows something wrong, which the "new" text overlapped on the old ones, just like the label has not been refreshed/cleared before redrawing.

enter image description here

Did I miss any necessary calling in my process?

fajir moin
  • 99
  • 8

2 Answers2

1

You are missing GraphicalInstaller::SubclassLabel /NOUNLOAD $variable_name

The correct code:

Function FuncShowNewFeature
  ; ...
  ; Add Controls
 
  ${NSD_CreateLabel} 0 13u 100% 12u "Show new features here"
  Pop $lblContents
  ${GraphicalInstallerRedrawLabel} $lblContents
  GraphicalInstaller::SubclassLabel /NOUNLOAD $lblContents # <<< ADDED HERE
  
  ${NSD_CreateButton} 0 -13u 40u 13u "Prev"
  Pop $btnPrev
  ${NSD_OnClick} $btnPrev PrevFeature ; callback
  
  ${NSD_CreateButton} -40u -13u 40u 13u "Next"
  Pop $btnNext
  ${NSD_OnClick} $btnNext NextFeature ; callback
  
  # Put this macro before EACH calling nsDialogs::Show to draw background properly
  ${GraphicalInstallerRedrawnsDialogsPage}
  nsDialogs::Show
FunctionEnd

Function NextFeature
  ${NSD_SetText} $lblContents "To show the next tip of new-feature"
FunctionEnd

Function PrevFeature
  ${NSD_SetText} $lblContents "To show the previous tip of new-feature"
FunctionEnd

GraphicalInstaller::Subclass[CONTROL] is part of ${GraphicalInstallerRedraw[CONTROL]} macro.

This works fine for [CONTROL] of type RadioButton or CheckBox, but it is missing in Label.

We will fix this in next release, sorry for this inconsistency.

Slappy
  • 5,250
  • 1
  • 23
  • 29
1

One simple workaround is to just hide the label while you update its text:

!include nsDialogs.nsh
Page Custom gfxpage

Function onClick
Pop $0
System::Call 'kernel32::GetTickCount()i.r0' ; "Arbitrary" number
ShowWindow $2 0
${NSD_SetText} $2 "$0$0$0"
ShowWindow $2 1
FunctionEnd

Function .onInit
InitPluginsDir
File /oname=$PLUGINSDIR\image.bmp "${NSISDIR}\Contrib\Graphics\Header\nsis-r.bmp"
FunctionEnd

Function gfxpage
nsDialogs::Create 1018
Pop $0

${NSD_CreateButton} 0 -13u 100% 12u "Click me"
Pop $1
${NSD_OnClick} $1 onClick

${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
Pop $2
SetCtlColors $2 000000 transparent

${NSD_CreateBitmap} 0 0 100% 12u ""
Pop $3
${NSD_SetBitmap} $3 $PLUGINSDIR\image.bmp $4

nsDialogs::Show
${NSD_FreeBitmap} $4
FunctionEnd
Anders
  • 97,548
  • 12
  • 110
  • 164