CharacterMap: improved initial window size, and position.

* By making it scale with the font size, and by using
  BWindow::CenterOnScreen().
* Minor cleanup.
This commit is contained in:
Axel Dörfler
2015-09-14 20:45:43 +02:00
parent 2603848d7d
commit 0342049e48
+13 -10
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009-2010, Axel Dörfler, [email protected]. * Copyright 2009-2015, Axel Dörfler, [email protected].
* Copyright 2011, Philippe Saint-Pierre, [email protected]. * Copyright 2011, Philippe Saint-Pierre, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -33,9 +33,11 @@
#include "CharacterView.h" #include "CharacterView.h"
#include "UnicodeBlockView.h" #include "UnicodeBlockView.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "CharacterWindow" #define B_TRANSLATION_CONTEXT "CharacterWindow"
static const uint32 kMsgUnicodeBlockSelected = 'unbs'; static const uint32 kMsgUnicodeBlockSelected = 'unbs';
static const uint32 kMsgCharacterChanged = 'chch'; static const uint32 kMsgCharacterChanged = 'chch';
static const uint32 kMsgFontSelected = 'fnts'; static const uint32 kMsgFontSelected = 'fnts';
@@ -134,6 +136,10 @@ CharacterWindow::CharacterWindow()
if (settings.FindRect("window frame", &frame) == B_OK) { if (settings.FindRect("window frame", &frame) == B_OK) {
MoveTo(frame.LeftTop()); MoveTo(frame.LeftTop());
ResizeTo(frame.Width(), frame.Height()); ResizeTo(frame.Width(), frame.Height());
} else {
float scaling = be_plain_font->Size() / 12.0f;
ResizeTo(Frame().Width() * scaling, Frame().Height() * scaling);
CenterOnScreen();
} }
// create GUI // create GUI
@@ -211,7 +217,7 @@ CharacterWindow::CharacterWindow()
fCodeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, fCodeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
fCodeView->PreferredSize().Height())); fCodeView->PreferredSize().Height()));
// set minimum width for character pane to prevent UI // Set minimum width for character pane to prevent UI
// from jumping when longer code strings are displayed. // from jumping when longer code strings are displayed.
// use 'w' character for sizing as it's likely the widest // use 'w' character for sizing as it's likely the widest
// character for a Latin font. 40 characters is a little // character for a Latin font. 40 characters is a little
@@ -219,8 +225,7 @@ CharacterWindow::CharacterWindow()
// non-Latin fonts that may be wider. // non-Latin fonts that may be wider.
BFont viewFont; BFont viewFont;
fCodeView->GetFont(&viewFont); fCodeView->GetFont(&viewFont);
fCharacterView->SetExplicitMinSize(BSize(viewFont.StringWidth( fCharacterView->SetExplicitMinSize(BSize(viewFont.StringWidth("w") * 40,
"w") * 40,
B_SIZE_UNSET)); B_SIZE_UNSET));
BLayoutBuilder::Group<>(this, B_VERTICAL) BLayoutBuilder::Group<>(this, B_VERTICAL)
@@ -467,7 +472,7 @@ CharacterWindow::_LoadSettings(BMessage& settings)
{ {
BFile file; BFile file;
status_t status = _OpenSettings(file, B_READ_ONLY); status_t status = _OpenSettings(file, B_READ_ONLY);
if (status < B_OK) if (status != B_OK)
return status; return status;
return settings.Unflatten(&file); return settings.Unflatten(&file);
@@ -533,7 +538,6 @@ BMenu*
CharacterWindow::_CreateFontMenu() CharacterWindow::_CreateFontMenu()
{ {
BMenu* menu = new BMenu(B_TRANSLATE("Font")); BMenu* menu = new BMenu(B_TRANSLATE("Font"));
_UpdateFontMenu(menu); _UpdateFontMenu(menu);
return menu; return menu;
@@ -589,10 +593,9 @@ CharacterWindow::_UpdateFontMenu(BMenu* menu)
} }
void CharacterWindow::MenusBeginning() void
CharacterWindow::MenusBeginning()
{ {
if (update_font_families(false) == true) { if (update_font_families(false) == true)
_UpdateFontMenu(fFontMenu); _UpdateFontMenu(fFontMenu);
}
} }