From 344180b745382739599785a821295dbf32a0e7ca Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Thu, 27 Nov 2014 17:49:22 +0100 Subject: [PATCH] FontDemo: convert to layout code. Fixes #9241. --- src/apps/fontdemo/ControlView.cpp | 85 +++++++++++-------------------- src/apps/fontdemo/ControlView.h | 10 ++-- src/apps/fontdemo/FontDemo.cpp | 7 ++- 3 files changed, 39 insertions(+), 63 deletions(-) diff --git a/src/apps/fontdemo/ControlView.cpp b/src/apps/fontdemo/ControlView.cpp index 66d8c104c3..ab7da39429 100644 --- a/src/apps/fontdemo/ControlView.cpp +++ b/src/apps/fontdemo/ControlView.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -28,8 +29,8 @@ #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "ControlView" -ControlView::ControlView(BRect rect) - : BView(rect, "ControlView", B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE_JUMP), +ControlView::ControlView() + : BGroupView("ControlView", B_VERTICAL), fMessenger(NULL), fMessageRunner(NULL), fTextControl(NULL), @@ -48,6 +49,7 @@ ControlView::ControlView(BRect rect) fFontStyleindex(0) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + GroupLayout()->SetInsets(B_USE_WINDOW_SPACING); } @@ -61,77 +63,54 @@ ControlView::~ControlView() void ControlView::AttachedToWindow() { - BRect rect(Bounds()); - rect.InsetBySelf(10, 0); - rect.bottom = rect.top + 18; - rect.OffsetBy(0, 11); - - float offsetX = 0; - float offsetY = 0; - - fTextControl = new BTextControl(rect, "TextInput", B_TRANSLATE("Text:"), + fTextControl = new BTextControl("TextInput", B_TRANSLATE("Text:"), B_TRANSLATE("Haiku, Inc."), NULL); - fTextControl->SetDivider(36.0); fTextControl->SetModificationMessage(new BMessage(TEXT_CHANGED_MSG)); AddChild(fTextControl); - rect.OffsetBy(0.0, 27.0); - _AddFontMenu(rect); + _AddFontMenu(); - rect.OffsetBy(0.0, 36.0); - fFontsizeSlider = new BSlider(rect, "Fontsize", B_TRANSLATE("Size: 50"), - NULL, 4, 360); + fFontsizeSlider = new BSlider("Fontsize", B_TRANSLATE("Size: 50"), + NULL, 4, 360, B_HORIZONTAL); fFontsizeSlider->SetModificationMessage(new BMessage(FONTSIZE_MSG)); fFontsizeSlider->SetValue(50); AddChild(fFontsizeSlider); - // Get the preferred size for the sliders - fFontsizeSlider->GetPreferredSize(&offsetY, &offsetX); - offsetX += 1; - - rect.OffsetBy(0.0, offsetX); - fShearSlider = new BSlider(rect, "Shear", B_TRANSLATE("Shear: 90"), NULL, - 45, 135); + fShearSlider = new BSlider("Shear", B_TRANSLATE("Shear: 90"), NULL, + 45, 135, B_HORIZONTAL); fShearSlider->SetModificationMessage(new BMessage(FONTSHEAR_MSG)); fShearSlider->SetValue(90); AddChild(fShearSlider); - rect.OffsetBy(0.0, offsetX); - fRotationSlider = new BSlider(rect, "Rotation", B_TRANSLATE("Rotation: 0"), - NULL, 0, 360); + fRotationSlider = new BSlider("Rotation", B_TRANSLATE("Rotation: 0"), + NULL, 0, 360, B_HORIZONTAL); fRotationSlider->SetModificationMessage( new BMessage(ROTATION_MSG)); fRotationSlider->SetValue(0); AddChild(fRotationSlider); - rect.OffsetBy(0.0, offsetX); - fSpacingSlider = new BSlider(rect, "Spacing", B_TRANSLATE("Spacing: 0"), - NULL, -5, 50); + fSpacingSlider = new BSlider("Spacing", B_TRANSLATE("Spacing: 0"), + NULL, -5, 50, B_HORIZONTAL); fSpacingSlider->SetModificationMessage(new BMessage(SPACING_MSG)); fSpacingSlider->SetValue(0); AddChild(fSpacingSlider); - rect.OffsetBy(0.0, offsetX); - fOutlineSlider = new BSlider(rect, "Outline", B_TRANSLATE("Outline:"), - NULL, 0, 20); + fOutlineSlider = new BSlider("Outline", B_TRANSLATE("Outline:"), + NULL, 0, 20, B_HORIZONTAL); fOutlineSlider->SetModificationMessage(new BMessage(OUTLINE_MSG)); AddChild(fOutlineSlider); - rect.OffsetBy(0.0, offsetX); - fAliasingCheckBox = new BCheckBox(rect, "Aliasing", + fAliasingCheckBox = new BCheckBox("Aliasing", B_TRANSLATE("Antialiased text"), new BMessage(ALIASING_MSG)); fAliasingCheckBox->SetValue(B_CONTROL_ON); AddChild(fAliasingCheckBox); - rect.OffsetBy(0.0, 30.0f); - _AddDrawingModeMenu(rect); + _AddDrawingModeMenu(); - rect.OffsetBy(0.0, 30.0f); - fBoundingboxesCheckBox = new BCheckBox(rect, "BoundingBoxes", + fBoundingboxesCheckBox = new BCheckBox("BoundingBoxes", B_TRANSLATE("Bounding boxes"), new BMessage(BOUNDING_BOX_MSG)); AddChild(fBoundingboxesCheckBox); - rect.OffsetBy(0.0, 30.0f); - fCyclingFontButton = new BButton(rect, "Cyclefonts", + fCyclingFontButton = new BButton("Cyclefonts", B_TRANSLATE("Cycle fonts"), new BMessage(CYCLING_FONTS_MSG)); AddChild(fCyclingFontButton); @@ -378,7 +357,7 @@ ControlView::_UpdateFontmenus(bool setInitialfont) for (int32 i = 0; i < fontfamilies; i++) { if (get_font_family(i, &fontFamilyName) == B_OK) { - stylemenu = new BMenu(fontFamilyName); + stylemenu = new BPopUpMenu(fontFamilyName); const int32 styles = count_font_styles(fontFamilyName); BMessage* familyMsg = new BMessage(FONTFAMILY_CHANGED_MSG); @@ -422,25 +401,22 @@ ControlView::_UpdateFontmenus(bool setInitialfont) void -ControlView::_AddFontMenu(BRect rect) +ControlView::_AddFontMenu() { - fFontFamilyMenu = new BMenu("fontfamlilymenu"); + fFontFamilyMenu = new BPopUpMenu("fontfamlilymenu"); _UpdateFontmenus(true); - rect.bottom += 4; - fFontMenuField = new BMenuField(rect, "FontMenuField", - B_TRANSLATE("Font:"), fFontFamilyMenu, true); - fFontMenuField->SetDivider( - fFontMenuField->StringWidth(B_TRANSLATE("Font:")) + 5); + fFontMenuField = new BMenuField("FontMenuField", + B_TRANSLATE("Font:"), fFontFamilyMenu); AddChild(fFontMenuField); } void -ControlView::_AddDrawingModeMenu(BRect rect) +ControlView::_AddDrawingModeMenu() { - fDrawingModeMenu = new BMenu("drawingmodemenu"); + fDrawingModeMenu = new BPopUpMenu("drawingmodemenu"); BMessage* drawingMsg = NULL; drawingMsg = new BMessage(DRAWINGMODE_CHANGED_MSG); @@ -480,11 +456,8 @@ ControlView::_AddDrawingModeMenu(BRect rect) fDrawingModeMenu->SetLabelFromMarked(true); - rect.bottom += 4; - BMenuField* drawingModeMenuField = new BMenuField(rect, "FontMenuField", - B_TRANSLATE("Drawing mode:"), fDrawingModeMenu, true); - drawingModeMenuField->SetDivider( - fDrawingModeMenu->StringWidth(B_TRANSLATE("Drawing mode:") + 5)); + BMenuField* drawingModeMenuField = new BMenuField("FontMenuField", + B_TRANSLATE("Drawing mode:"), fDrawingModeMenu); AddChild(drawingModeMenuField); } diff --git a/src/apps/fontdemo/ControlView.h b/src/apps/fontdemo/ControlView.h index 0e347ed493..f944ea0387 100644 --- a/src/apps/fontdemo/ControlView.h +++ b/src/apps/fontdemo/ControlView.h @@ -9,7 +9,7 @@ #define CONTROL_VIEW_H -#include +#include class BButton; @@ -24,9 +24,9 @@ class BSlider; class BTextControl; -class ControlView : public BView { +class ControlView : public BGroupView { public: - ControlView(BRect rect); + ControlView(); virtual ~ControlView(); virtual void AttachedToWindow(); @@ -35,8 +35,8 @@ class ControlView : public BView { void SetTarget(BHandler* handler); private: - void _AddFontMenu(BRect rect); - void _AddDrawingModeMenu(BRect rect); + void _AddFontMenu(); + void _AddDrawingModeMenu(); void _UpdateFontmenus(bool setInitialfont = false); void _DeselectOldItems(); diff --git a/src/apps/fontdemo/FontDemo.cpp b/src/apps/fontdemo/FontDemo.cpp index 94206c499a..4a81307341 100644 --- a/src/apps/fontdemo/FontDemo.cpp +++ b/src/apps/fontdemo/FontDemo.cpp @@ -12,6 +12,7 @@ #include "FontDemoView.h" #include +#include #include #undef B_TRANSLATION_CONTEXT @@ -31,9 +32,11 @@ FontDemo::FontDemo() BWindow* controlWindow = new BWindow(BRect(500, 30, 700, 420), B_TRANSLATE("Controls"), B_FLOATING_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL, - B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS); + B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE + | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS); - ControlView* controlView = new ControlView(controlWindow->Bounds()); + ControlView* controlView = new ControlView(); + controlWindow->SetLayout(new BGroupLayout(B_VERTICAL)); controlWindow->AddChild(controlView); controlView->SetTarget(demoView);