From e2e3108025e839a3295af9b72b92ee1ca3ea9656 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Tue, 8 Oct 2013 18:44:37 +0200 Subject: [PATCH 1/1] comments --- qcsrc/menu/item/listbox.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/qcsrc/menu/item/listbox.c b/qcsrc/menu/item/listbox.c index 1087c3479..0f9502d97 100644 --- a/qcsrc/menu/item/listbox.c +++ b/qcsrc/menu/item/listbox.c @@ -47,13 +47,31 @@ CLASS(ListBox) EXTENDS(Item) METHOD(ListBox, getItemAtPos, float(entity, float)) METHOD(ListBox, getItemStart, float(entity, float)) METHOD(ListBox, getItemHeight, float(entity, float)) + // NOTE: if getItemAt* are overridden, it may make sense to cache the + // start and height of the last item returned by getItemAtPos and fast + // track returning their properties for getItemStart and getItemHeight. + // The "hot" code path calls getItemAtPos first, then will query + // getItemStart and getItemHeight on it soon. + // When overriding, the following consistency rules must hold: + // getTotalHeight() == SUM(getItemHeight(i), i, 0, me.nItems-1) + // getItemStart(i+1) == getItemStart(i) + getItemHeight(i) + // for 0 <= i < me.nItems-1 + // getItemStart(0) == 0 + // getItemStart(getItemAtPos(p)) <= p + // if p >= 0 + // getItemAtPos(p) == 0 + // if p < 0 + // getItemStart(getItemAtPos(p)) + getItemHeight(getItemAtPos(p)) > p + // if p < getTotalHeigt() + // getItemAtPos(p) == me.nItems - 1 + // if p >= getTotalHeight() ENDCLASS(ListBox) #endif #ifdef IMPLEMENTATION void ListBox_setSelected(entity me, float i) { - me.selectedItem = floor(0.5 + bound(0, i, me.nItems - 1)); + me.selectedItem = bound(0, i, me.nItems - 1); } void ListBox_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) { -- 2.39.2