Feature request incl. solution: Listview.First to be settable (S)

Discuss GUI programming with the RapaGUI plugin here
Post Reply
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Feature request incl. solution: Listview.First to be settable (S)

Post by mrupp »

It would be great, if Listview.First could be made settable (applicability S). I wrote a function to do this and thought that maybe this logic could be included with RapaGUI 2.0.

Here's the code including a test suite with a listbox and a listview. Feel free to use it as you see fit.
The function p_ListViewSetFirst() tries to set the first visible entry in a listview and if that's not possible (because the desired position is within the last entries of the list), it ensures the entry is visible and returns the current "first":

Test.hws:

Code: Select all

@REQUIRE "RapaGUI", {Link = True}
@APPTITLE "ListView-Test"
@FILE 1, "TestGUI.xml"

Function p_ListViewSetFirst(id$, pos)
	Local count = moai.Get(id$, "entries")
	Local countVisible = moai.Get(id$, "visible")
	Local maxFirst = count - countVisible
	Local currentFirst = moai.Get(id$, "first")
	Local jumpToPos = pos

	If jumpToPos > maxFirst
		jumpToPos = "bottom"
	ElseIf currentFirst < pos
		jumpToPos = jumpToPos + countVisible - 1
	EndIf

	moai.DoMethod(id$, "jump", jumpToPos)

	Return(moai.Get(id$, "first"))
EndFunction

Function p_EventFunc(msg)
	Switch(msg.ID)
	Case "btnSetFirst1":
		Local first = p_ListViewSetFirst("listview1", ToNumber(moai.Get("ctrlSetFirst1", "text")))
		moai.Set("ctrlTrulyFirst1", "text", first)
	Case "btnSetFirst2":
		Local first = p_ListViewSetFirst("listview2", ToNumber(moai.Get("ctrlSetFirst2", "text")))
		moai.Set("ctrlTrulyFirst2", "text", first)
	EndSwitch
EndFunction

moai.CreateApp(ReadString(1))
InstallEventHandler({RapaGUI = p_EventFunc})

For Local i = 0 To 100
	moai.DoMethod("listview1", "insert", "bottom", "Item " .. i)
	moai.DoMethod("listview2", "insert", "bottom", i, "Item " .. i)
Next

Repeat
	 WaitEvent
Forever
TestGUI.xml:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
	<window id="mainWindow" title="ListView-Test">
		<vgroup>
			<hgroup frame="true" frametitle="Listbox">
				<colgroup columns="2">
					<button id="btnSetFirst1">Set first</button>
					<textentry id="ctrlSetFirst1" accept="0123456789">50</textentry>
					<label align="center">Truly first</label>
					<textentry id="ctrlTrulyFirst1" disabled="true">0</textentry>
					<rectangle/>
					<rectangle/>
				</colgroup>
				<rectangle/>																							
				<listview id="listview1">
					<column/>
				</listview>	
			</hgroup>	
			<hgroup frame="true" frametitle="Listview">
				<colgroup columns="2">
					<button id="btnSetFirst2">Set first</button>
					<textentry id="ctrlSetFirst2" accept="0123456789">50</textentry>
					<label align="center">Truly first</label>
					<textentry id="ctrlTrulyFirst2" disabled="true">0</textentry>
					<rectangle/>
					<rectangle/>
				</colgroup>
				<rectangle/>																							
				<listview id="listview2">
					<column title="ID" />
					<column title="Text" />
				</listview>	
			</hgroup>	
		</vgroup>				
	</window>
</application>
Cheers,
Michael
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Re: Feature request incl. solution: Listview.First to be settable (S)

Post by mrupp »

Please note:
I noticed that although the code above works perfectly on Windows, that this is not the case with MUI. I traced it down to an inconsistency when getting the number of visible entries in a Listview using Listview.Visible on different platforms.

See the following post for more details: viewtopic.php?f=27&t=3265
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Feature request incl. solution: Listview.First to be settable (S)

Post by airsoftsoftwair »

This should be possible to implement because MUIA_List_First is indeed SG so I'm wondering why I didn't make it settable in the first place...
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Re: Feature request incl. solution: Listview.First to be settable (S)

Post by mrupp »

Errr... I noticed that my solution as posted above is unnecessarily complicated and the same can be achieved with as simply as this and it works on all platforms, too:

Code: Select all

Function p_ListViewSetFirst(id$, pos)
	moai.DoMethod(id$, "jump", "bottom")
	moai.DoMethod(id$, "jump", pos)
	Return(moai.Get(id$, "first"))
EndFunction
Still, it would be nice to have "first" to be settable in RP 2.0.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Feature request incl. solution: Listview.First to be settable (S)

Post by airsoftsoftwair »

Code: Select all

- New: Listview.First has an applicability of SG now
Post Reply