CharacterMap: several fixes to char. view scroll
* Select items in the encoding list by block identifier rather than list index (there are holes in the list) * Scroll to the start of the list when the application starts * Add and use IsBlockVisible to detect when we need to make a block visible, avoiding unwanted scrollings in some cases with the previous method of testing for only one character in the block. Signed-off-by: Adrien Destugues <pulkomandy@gmail.com> Fixes some problems with previous enhancements from #3651.
This commit is contained in:
parent
b8a8557aa9
commit
0340e4b336
@ -38,6 +38,7 @@ CharacterView::CharacterView(const char* name)
|
||||
fCharacterFont.SetSize(fCharacterFont.Size() * 1.5f);
|
||||
|
||||
_UpdateFontSize();
|
||||
DoLayout();
|
||||
}
|
||||
|
||||
|
||||
@ -108,10 +109,10 @@ CharacterView::IsShowingBlock(int32 blockIndex) const
|
||||
void
|
||||
CharacterView::ScrollToBlock(int32 blockIndex)
|
||||
{
|
||||
// don't scroll if the selected character is already in view.
|
||||
// don't scroll if the selected block is already in view.
|
||||
// this prevents distracting jumps when crossing a block
|
||||
// boundary in the character view.
|
||||
if (IsCharacterVisible(fCurrentCharacter))
|
||||
if (IsBlockVisible(blockIndex))
|
||||
return;
|
||||
|
||||
if (blockIndex < 0)
|
||||
@ -141,6 +142,19 @@ CharacterView::IsCharacterVisible(uint32 c) const
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CharacterView::IsBlockVisible(int32 block) const
|
||||
{
|
||||
int32 topBlock = _BlockAt(BPoint(Bounds().left, Bounds().top));
|
||||
int32 bottomBlock = _BlockAt(BPoint(Bounds().right, Bounds().bottom));
|
||||
|
||||
if (block >= topBlock && block <= bottomBlock)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ void
|
||||
CharacterView::UnicodeToUTF8(uint32 c, char* text, size_t textSize)
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
void ScrollToBlock(int32 blockIndex);
|
||||
void ScrollToCharacter(uint32 c);
|
||||
bool IsCharacterVisible(uint32 c) const;
|
||||
bool IsBlockVisible(int32 block) const;
|
||||
|
||||
static void UnicodeToUTF8(uint32 c, char* text,
|
||||
size_t textSize);
|
||||
|
@ -275,6 +275,8 @@ CharacterWindow::CharacterWindow()
|
||||
fUnicodeBlockView->SetTarget(this);
|
||||
|
||||
fFilterControl->MakeFocus();
|
||||
|
||||
fUnicodeBlockView->SelectBlockForCharacter(0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -133,7 +133,13 @@ UnicodeBlockView::SelectBlockForCharacter(uint32 character)
|
||||
break;
|
||||
}
|
||||
|
||||
Select(i);
|
||||
ScrollToSelection();
|
||||
BlockListItem* block = fBlocks.ItemAt(i);
|
||||
|
||||
int32 blockNum = IndexOf(block);
|
||||
|
||||
if (blockNum >= 0) {
|
||||
Select(blockNum);
|
||||
ScrollToSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user