New method FWidget::initLayout() for setting widget layouts after terminal initialization

This commit is contained in:
Markus Gans 2021-03-28 23:19:01 +02:00
parent 0e7488f646
commit 597f9e772b
34 changed files with 586 additions and 308 deletions

View File

@ -1,3 +1,10 @@
2021-03-28 Markus Gans <guru.mail@muenster.de>
* Widget now have the virtual method initLayout() to set
the widget layouts automatically before the first drawing
on the terminal is done. Also texts in full-width characters,
whose character width is determined automatically, should be
calculated here.
2021-03-15 Markus Gans <guru.mail@muenster.de> 2021-03-15 Markus Gans <guru.mail@muenster.de>
* Dynamic adjustment of the terminal refresh rate between * Dynamic adjustment of the terminal refresh rate between
5 and 60 Hz 5 and 60 Hz

View File

@ -378,15 +378,20 @@ class dialogWidget : public FDialog
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{parent} : FDialog{parent}
{ {
setText ("Dialog");
setGeometry (FPoint{25, 5}, FSize{23, 4});
label.setGeometry (FPoint{1, 1}, FSize{10, 1});
label.setAlignment (Align::Right); label.setAlignment (Align::Right);
value.setGeometry (FPoint{11, 1}, FSize{10, 1});
id = addTimer(100); id = addTimer(100);
} }
private: private:
void initLayout()
{
setText ("Dialog");
setGeometry (FPoint{25, 5}, FSize{23, 4});
label.setGeometry (FPoint{1, 1}, FSize{10, 1});
value.setGeometry (FPoint{11, 1}, FSize{10, 1});
FDialog::initLayout();
}
void onTimer (FTimerEvent* ev) override void onTimer (FTimerEvent* ev) override
{ {
if ( id == ev->getTimerId() && n < 9999999999 ) if ( id == ev->getTimerId() && n < 9999999999 )
@ -495,12 +500,16 @@ class dialogWidget final : public FDialog
public: public:
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{"User event", parent} : FDialog{"User event", parent}
{ }
private:
void initLayout()
{ {
FDialog::setGeometry (FPoint{25, 5}, FSize{40, 6}); FDialog::setGeometry (FPoint{25, 5}, FSize{40, 6});
loadavg_label.setGeometry (FPoint{2, 2}, FSize{36, 1}); loadavg_label.setGeometry (FPoint{2, 2}, FSize{36, 1});
FDialog::initLayout();
} }
private:
void onUserEvent (FUserEvent* ev) override void onUserEvent (FUserEvent* ev) override
{ {
const auto& lavg = ev->getData<LoadAvg>(); const auto& lavg = ev->getData<LoadAvg>();
@ -891,10 +900,6 @@ class dialogWidget : public FDialog
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{parent} : FDialog{parent}
{ {
setText ("Callback method");
setGeometry (FPoint{25, 5}, FSize{25, 7});
button.setGeometry (FPoint{7, 3}, FSize{10, 1});
// Connect the button signal "clicked" with the callback method // Connect the button signal "clicked" with the callback method
button.addCallback button.addCallback
( (
@ -906,6 +911,14 @@ class dialogWidget : public FDialog
} }
private: private:
void initLayout()
{
setText ("Callback method");
setGeometry (FPoint{25, 5}, FSize{25, 7});
button.setGeometry (FPoint{7, 3}, FSize{10, 1});
FDialog::initLayout();
}
FButton button{"&Quit", this}; FButton button{"&Quit", this};
}; };
@ -954,14 +967,8 @@ class dialogWidget : public FDialog
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{parent} : FDialog{parent}
{ {
setGeometry (FPoint{25, 5}, FSize{22, 7});
setText ("Emit signal");
const FSize size{5, 1};
label.setGeometry (FPoint{8, 1}, size);
label.setAlignment (Align::Right); label.setAlignment (Align::Right);
label.setForegroundColor (FColor::Black); label.setForegroundColor (FColor::Black);
plus.setGeometry (FPoint{3, 3}, size);
minus.setGeometry (FPoint{3, 3} + FPoint{10, 0}, size);
plus.setNoUnderline(); plus.setNoUnderline();
minus.setNoUnderline(); minus.setNoUnderline();
@ -976,6 +983,17 @@ class dialogWidget : public FDialog
} }
private: private:
void initLayout()
{
setGeometry (FPoint{25, 5}, FSize{22, 7});
setText ("Emit signal");
const FSize size{5, 1};
label.setGeometry (FPoint{8, 1}, size);
plus.setGeometry (FPoint{3, 3}, size);
minus.setGeometry (FPoint{3, 3} + FPoint{10, 0}, size);
FDialog::initLayout();
}
void cb_plus() void cb_plus()
{ {
if ( t < 100 ) if ( t < 100 )
@ -1375,8 +1393,6 @@ class dialogWidget : public FDialog
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{parent} : FDialog{parent}
{ {
setText ("Dialog");
setGeometry (FPoint{28, 2}, FSize{24, 21});
scrollview.setGeometry(FPoint{1, 1}, FSize{22, 11}); scrollview.setGeometry(FPoint{1, 1}, FSize{22, 11});
scrollview.setScrollSize(FSize{60, 27}); scrollview.setScrollSize(FSize{60, 27});
// Attention: getColorTheme() requires an initialized terminal // Attention: getColorTheme() requires an initialized terminal
@ -1420,6 +1436,13 @@ class dialogWidget : public FDialog
private: private:
typedef std::tuple<FString, FPoint, FPoint, FColorPair> direction; typedef std::tuple<FString, FPoint, FPoint, FColorPair> direction;
void initLayout()
{
setText ("Dialog");
setGeometry (FPoint{28, 2}, FSize{24, 21});
FDialog::initLayout();
}
void cb_button (const FPoint& p) void cb_button (const FPoint& p)
{ {
scrollview.scrollTo(p); scrollview.scrollTo(p);

View File

@ -361,20 +361,15 @@ class dialogWidget final : public FDialog
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{"Theming test application", parent} : FDialog{"Theming test application", parent}
{ {
FDialog::setGeometry (FPoint{15, 5}, FSize{50, 9});
Input.setGeometry (FPoint{2, 2}, FSize{39, 1});
Input.setLabelText("File name:"); Input.setLabelText("File name:");
Input.setLabelOrientation(FLineEdit::LabelOrientation::Above); Input.setLabelOrientation(FLineEdit::LabelOrientation::Above);
Input.setStatusbarMessage("Enter a file name"); Input.setStatusbarMessage("Enter a file name");
Browse.setGeometry (FPoint{43, 2}, FSize{4, 1});
Browse.addCallback Browse.addCallback
( (
"clicked", "clicked",
this, &dialogWidget::cb_FileBrowse this, &dialogWidget::cb_FileBrowse
); );
Apply.setGeometry (FPoint{24, 5}, FSize{10, 1});
Apply.setStatusbarMessage("Apply settings"); Apply.setStatusbarMessage("Apply settings");
Quit.setGeometry (FPoint{37, 5}, FSize{10, 1});
Quit.setStatusbarMessage("Exit the program"); Quit.setStatusbarMessage("Exit the program");
Quit.addCallback Quit.addCallback
( (
@ -391,6 +386,16 @@ class dialogWidget final : public FDialog
} }
private: private:
void initLayout()
{
setGeometry (FPoint{15, 5}, FSize{50, 9});
Input.setGeometry (FPoint{2, 2}, FSize{39, 1});
Browse.setGeometry (FPoint{43, 2}, FSize{4, 1});
Apply.setGeometry (FPoint{24, 5}, FSize{10, 1});
Quit.setGeometry (FPoint{37, 5}, FSize{10, 1});
FDialog::initLayout();
}
void cb_FileBrowse() void cb_FileBrowse()
{ {
auto filename = FFileDialog::fileOpenChooser(this); auto filename = FFileDialog::fileOpenChooser(this);

View File

@ -59,6 +59,7 @@ class SegmentView final : public finalcut::FDialog
void hexEncoding(); void hexEncoding();
void get7Segment (const wchar_t); void get7Segment (const wchar_t);
void draw() override; void draw() override;
void initLayout() override;
// Data members // Data members
std::map<wchar_t, sevenSegment> code{}; std::map<wchar_t, sevenSegment> code{};
@ -71,26 +72,16 @@ class SegmentView final : public finalcut::FDialog
SegmentView::SegmentView (finalcut::FWidget* parent) SegmentView::SegmentView (finalcut::FWidget* parent)
: FDialog{parent} : FDialog{parent}
{ {
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setText ("Seven-segment display");
FDialog::setGeometry (FPoint{25, 5}, FSize{42, 15});
// Set encoding // Set encoding
hexEncoding(); hexEncoding();
// Input field // Input field
input.setGeometry (FPoint(2, 2), FSize{12, 1});
input.setLabelText (L"&Hex value"); input.setLabelText (L"&Hex value");
input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)"); input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)");
input.setLabelOrientation(finalcut::FLineEdit::LabelOrientation::Above); input.setLabelOrientation(finalcut::FLineEdit::LabelOrientation::Above);
input.setMaxLength(9); input.setMaxLength(9);
input.setInputFilter("[:.hHlLpPuU[:xdigit:]]"); input.setInputFilter("[:.hHlLpPuU[:xdigit:]]");
// Exit button
exit.setGeometry(FPoint{28, 11}, FSize{10, 1});
// Add some function callbacks // Add some function callbacks
input.addCallback input.addCallback
( (
@ -221,6 +212,19 @@ void SegmentView::draw()
<< FPoint {4, 10} << finalcut::FString{36, ' '}; << FPoint {4, 10} << finalcut::FString{36, ' '};
} }
//----------------------------------------------------------------------
void SegmentView::initLayout()
{
// Dialog settings
FDialog::setText ("Seven-segment display");
FDialog::setGeometry (FPoint{25, 5}, FSize{42, 15});
// Input field
input.setGeometry (FPoint(2, 2), FSize{12, 1});
// Exit button
exit.setGeometry(FPoint{28, 11}, FSize{10, 1});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// main part // main part

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2019-2020 Markus Gans * * Copyright 2019-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -55,6 +55,9 @@ class Background final : public finalcut::FDialog
Background& operator = (const Background&) = delete; Background& operator = (const Background&) = delete;
private: private:
// Methods
void initLayout() override;
// Callback method // Callback method
void cb_changed(); void cb_changed();
void cb_choice(); void cb_choice();
@ -92,14 +95,7 @@ class Background final : public finalcut::FDialog
Background::Background (finalcut::FWidget* parent) Background::Background (finalcut::FWidget* parent)
: FDialog{parent} : FDialog{parent}
{ {
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setText ("Background color palette");
FDialog::setGeometry (FPoint{25, 5}, FSize{32, 12});
// Combobox // Combobox
color_choice.setGeometry (FPoint{2, 2}, FSize{18, 1});
color_choice.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above); color_choice.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above);
color_choice.setLabelText ("Color choice"); color_choice.setLabelText ("Color choice");
color_choice.unsetEditable(); color_choice.unsetEditable();
@ -111,19 +107,16 @@ Background::Background (finalcut::FWidget* parent)
} }
// Spin boxes // Spin boxes
red.setGeometry (FPoint{2, 5}, FSize{7, 1});
red.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above); red.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above);
red.setLabelText ("Red"); red.setLabelText ("Red");
red.setRange (0, 255); red.setRange (0, 255);
red.setValue (0x80); red.setValue (0x80);
green.setGeometry (FPoint{12, 5}, FSize{7, 1});
green.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above); green.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above);
green.setLabelText ("Green"); green.setLabelText ("Green");
green.setRange (0, 255); green.setRange (0, 255);
green.setValue (0xa4); green.setValue (0xa4);
blue.setGeometry (FPoint{22, 5}, FSize{7, 1});
blue.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above); blue.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above);
blue.setLabelText ("Blue"); blue.setLabelText ("Blue");
blue.setRange (0, 255); blue.setRange (0, 255);
@ -138,9 +131,6 @@ Background::Background (finalcut::FWidget* parent)
, int(blue.getValue()) ); , int(blue.getValue()) );
} }
// Quit button
quit.setGeometry(FPoint{19, 8}, FSize{10, 1});
// Add some function callbacks // Add some function callbacks
quit.addCallback quit.addCallback
( (
@ -172,6 +162,19 @@ Background::Background (finalcut::FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Background::~Background() noexcept = default; // destructor Background::~Background() noexcept = default; // destructor
//----------------------------------------------------------------------
void Background::initLayout()
{
FDialog::setText ("Background color palette");
FDialog::setGeometry (FPoint{25, 5}, FSize{32, 12});
color_choice.setGeometry (FPoint{2, 2}, FSize{18, 1});
red.setGeometry (FPoint{2, 5}, FSize{7, 1});
green.setGeometry (FPoint{12, 5}, FSize{7, 1});
blue.setGeometry (FPoint{22, 5}, FSize{7, 1});
quit.setGeometry(FPoint{19, 8}, FSize{10, 1}); // Quit button
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Background::cb_changed() void Background::cb_changed()
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2020 Markus Gans * * Copyright 2020-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -35,6 +35,7 @@ class Dialog final : public finalcut::FDialog
explicit Dialog (FWidget* parent = nullptr); explicit Dialog (FWidget* parent = nullptr);
private: private:
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Event handler // Event handler
@ -54,14 +55,9 @@ class Dialog final : public finalcut::FDialog
Dialog::Dialog (FWidget* parent) Dialog::Dialog (FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
FDialog::setText ("Dialog");
finalcut::FDialog::setGeometry (FPoint{26, 5}, FSize{28, 10});
seconds.setGeometry (FPoint{10, 2}, FSize{10, 1});
seconds.setLabelText ("Seconds"); seconds.setLabelText ("Seconds");
seconds.setRange (0, 60); seconds.setRange (0, 60);
seconds.setValue (3); seconds.setValue (3);
start.setGeometry (FPoint{2, 6}, FSize{10, 1});
quit.setGeometry (FPoint{15, 6}, FSize{10, 1});
// Add button callbacks // Add button callbacks
seconds.addCallback seconds.addCallback
@ -85,6 +81,17 @@ Dialog::Dialog (FWidget* parent)
); );
} }
//----------------------------------------------------------------------
void Dialog::initLayout()
{
FDialog::setText ("Dialog");
FDialog::setGeometry (FPoint{26, 5}, FSize{28, 10});
seconds.setGeometry (FPoint{10, 2}, FSize{10, 1});
start.setGeometry (FPoint{2, 6}, FSize{10, 1});
quit.setGeometry (FPoint{15, 6}, FSize{10, 1});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Dialog::adjustSize() void Dialog::adjustSize()
{ {

View File

@ -112,9 +112,6 @@ void Button::onKeyPress (finalcut::FKeyEvent* ev)
class Calc final : public finalcut::FDialog class Calc final : public finalcut::FDialog
{ {
public: public:
// Using-declaration
using FDialog::setGeometry;
// Constructor // Constructor
explicit Calc (finalcut::FWidget* parent = nullptr); explicit Calc (finalcut::FWidget* parent = nullptr);
@ -209,6 +206,7 @@ class Calc final : public finalcut::FDialog
void setInfixOperator (char); void setInfixOperator (char);
void clearInfixOperator(); void clearInfixOperator();
void calcInfixOperator(); void calcInfixOperator();
void initLayout() override;
void adjustSize() override; void adjustSize() override;
const wchar_t* getButtonText (const ButtonName&) const; const wchar_t* getButtonText (const ButtonName&) const;
void mapKeyFunctions(); void mapKeyFunctions();
@ -257,12 +255,6 @@ class Calc final : public finalcut::FDialog
Calc::Calc (FWidget* parent) Calc::Calc (FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setText ("Calculator");
FDialog::setGeometry (FPoint{19, 6}, FSize{37, 18});
mapKeyFunctions(); mapKeyFunctions();
clearInfixOperator(); clearInfixOperator();
@ -271,17 +263,6 @@ Calc::Calc (FWidget* parent)
auto btn = std::make_shared<Button>(this); auto btn = std::make_shared<Button>(this);
auto index = std::size_t(key); auto index = std::size_t(key);
button_no[index] = key; button_no[index] = key;
if ( key == ButtonName::Equals )
btn->setGeometry(FPoint{30, 15}, FSize{5, 3});
else
{
const int n = ( key <= ButtonName::Three ) ? 0 : 1;
const int x = (int(key) + n) % 5 * 7 + 2;
const int y = (int(key) + n) / 5 * 2 + 3;
btn->setGeometry(FPoint{x, y}, FSize{5, 1});
}
btn->setFlat(); btn->setFlat();
btn->setNoUnderline(); btn->setNoUnderline();
btn->setText(getButtonText(key)); btn->setText(getButtonText(key));
@ -1084,6 +1065,31 @@ void Calc::calcInfixOperator()
clearInfixOperator(); clearInfixOperator();
} }
//----------------------------------------------------------------------
void Calc::initLayout()
{
// Dialog settings
FDialog::setText ("Calculator");
FDialog::setGeometry (FPoint{19, 6}, FSize{37, 18});
for (ButtonName key{ButtonName::Sine}; key < ButtonName::NUM_OF_BUTTONS; key++)
{
auto btn = calculator_buttons[ButtonName(key)];
if ( key == ButtonName::Equals )
btn->setGeometry(FPoint{30, 15}, FSize{5, 3});
else
{
const int n = ( key <= ButtonName::Three ) ? 0 : 1;
const int x = (int(key) + n) % 5 * 7 + 2;
const int y = (int(key) + n) / 5 * 2 + 3;
btn->setGeometry(FPoint{x, y}, FSize{5, 1});
}
}
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::adjustSize() void Calc::adjustSize()
{ {

View File

@ -40,9 +40,6 @@ using finalcut::FSize;
class CheckList final : public finalcut::FDialog class CheckList final : public finalcut::FDialog
{ {
public: public:
// Using-declaration
using FDialog::setGeometry;
// Constructor // Constructor
explicit CheckList (finalcut::FWidget* = nullptr); explicit CheckList (finalcut::FWidget* = nullptr);
@ -58,6 +55,7 @@ class CheckList final : public finalcut::FDialog
private: private:
// Method // Method
void populate(); void populate();
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Event handlers // Event handlers
@ -76,16 +74,8 @@ class CheckList final : public finalcut::FDialog
CheckList::CheckList (finalcut::FWidget* parent) CheckList::CheckList (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setText (L"Shopping list");
const std::size_t nf_offset = ( finalcut::FTerm::isNewFont() ) ? 1 : 0;
FDialog::setSize (FSize{28 + nf_offset, 13} );
setShadow(); // Instead of the transparent window shadow setShadow(); // Instead of the transparent window shadow
listview.ignorePadding(); listview.ignorePadding();
listview.setGeometry ( FPoint{1 + int(nf_offset), 2}
, FSize{getWidth() - nf_offset, getHeight() - 1} );
// Add columns to the view // Add columns to the view
listview.addColumn ("Item"); listview.addColumn ("Item");
@ -140,6 +130,17 @@ void CheckList::populate()
} }
} }
//----------------------------------------------------------------------
void CheckList::initLayout()
{
FDialog::setText (L"Shopping list");
const std::size_t nf_offset = ( finalcut::FTerm::isNewFont() ) ? 1 : 0;
FDialog::setSize (FSize{28 + nf_offset, 13} );
listview.setGeometry ( FPoint{1 + int(nf_offset), 2}
, FSize{getWidth() - nf_offset, getHeight() - 1} );
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void CheckList::adjustSize() void CheckList::adjustSize()
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2020 Markus Gans * * Copyright 2020-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -41,9 +41,6 @@ class EventLog; // class forward declaration
class EventDialog final : public finalcut::FDialog class EventDialog final : public finalcut::FDialog
{ {
public: public:
// Using-declaration
using FDialog::setGeometry;
// Constructor // Constructor
explicit EventDialog (finalcut::FWidget* = nullptr); explicit EventDialog (finalcut::FWidget* = nullptr);
@ -58,6 +55,7 @@ class EventDialog final : public finalcut::FDialog
private: private:
// Methods // Methods
void initLayout() override;
finalcut::FString getMouseButtonName (const finalcut::MouseButton&) const; finalcut::FString getMouseButtonName (const finalcut::MouseButton&) const;
void logMouseEvent ( const finalcut::FString& void logMouseEvent ( const finalcut::FString&
, const finalcut::FMouseEvent& ); , const finalcut::FMouseEvent& );
@ -85,22 +83,25 @@ class EventDialog final : public finalcut::FDialog
EventDialog::EventDialog (finalcut::FWidget* parent) EventDialog::EventDialog (finalcut::FWidget* parent)
: FDialog{parent} : FDialog{parent}
{ {
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setText ("Event dialog");
FDialog::setGeometry (FPoint{15, 2}, FSize{53, 12});
setShadow(); setShadow();
label.setText("\n\nUse the keyboard or mouse\n" label.setText("\n\nUse the keyboard or mouse\n"
"in this dialog to create events"); "in this dialog to create events");
label.setAlignment(finalcut::Align::Center); label.setAlignment(finalcut::Align::Center);
label.setGeometry (FPoint(1, 1), getClientSize(), false);
addTimer(60000); // Starts the timer every minute addTimer(60000); // Starts the timer every minute
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
EventDialog::~EventDialog() noexcept = default; // destructor EventDialog::~EventDialog() noexcept = default; // destructor
//----------------------------------------------------------------------
void EventDialog::initLayout()
{
FDialog::setText ("Event dialog");
FDialog::setGeometry (FPoint{15, 2}, FSize{53, 12});
label.setGeometry (FPoint(1, 1), getClientSize(), false);
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
finalcut::FString EventDialog::getMouseButtonName (const finalcut::MouseButton& btn_state) const finalcut::FString EventDialog::getMouseButtonName (const finalcut::MouseButton& btn_state) const
{ {
@ -240,9 +241,6 @@ void EventDialog::onWindowLowered (finalcut::FEvent* ev)
class EventLog final : public finalcut::FDialog, public std::ostringstream class EventLog final : public finalcut::FDialog, public std::ostringstream
{ {
public: public:
// Using-declaration
using FDialog::setGeometry;
// Constructor // Constructor
explicit EventLog (finalcut::FWidget* = nullptr); explicit EventLog (finalcut::FWidget* = nullptr);
@ -261,6 +259,7 @@ class EventLog final : public finalcut::FDialog, public std::ostringstream
private: private:
// Method // Method
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Data members // Data members
@ -272,16 +271,9 @@ class EventLog final : public finalcut::FDialog, public std::ostringstream
EventLog::EventLog (finalcut::FWidget* parent) EventLog::EventLog (finalcut::FWidget* parent)
: FDialog{parent} : FDialog{parent}
{ {
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setText ("Event log");
FDialog::setGeometry (FPoint{4, 16}, FSize{75, 8});
FDialog::setResizeable();
setMinimumSize (FSize{75, 5}); setMinimumSize (FSize{75, 5});
setShadow(); setShadow();
scrolltext.ignorePadding(); scrolltext.ignorePadding();
scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
event_dialog->setFocus(); event_dialog->setFocus();
addTimer(250); // Starts the timer every 250 milliseconds addTimer(250); // Starts the timer every 250 milliseconds
} }
@ -307,6 +299,16 @@ void EventLog::onClose (finalcut::FCloseEvent* ev)
finalcut::FApplication::closeConfirmationDialog (this, ev); finalcut::FApplication::closeConfirmationDialog (this, ev);
} }
//----------------------------------------------------------------------
void EventLog::initLayout()
{
FDialog::setText ("Event log");
FDialog::setGeometry (FPoint{4, 16}, FSize{75, 8});
FDialog::setResizeable();
scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void EventLog::adjustSize() void EventLog::adjustSize()
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2017-2020 Markus Gans * * Copyright 2017-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -93,6 +93,9 @@ class Listbox final : public FDialog
Listbox& operator = (const Listbox&) = delete; Listbox& operator = (const Listbox&) = delete;
private: private:
// Method
void initLayout() override;
// Event handlers // Event handlers
void onClose (FCloseEvent*) override; void onClose (FCloseEvent*) override;
@ -113,7 +116,6 @@ Listbox::Listbox (FWidget* parent)
// listbox 1 // listbox 1
//---------- //----------
list1.setGeometry(FPoint{2, 1}, FSize{18, 10});
list1.setText ("FListBoxItem"); list1.setText ("FListBoxItem");
for (auto i{1}; i < 30; i++) for (auto i{1}; i < 30; i++)
@ -124,7 +126,6 @@ Listbox::Listbox (FWidget* parent)
for (auto i{1}; i <= 15; i++) for (auto i{1}; i <= 15; i++)
double_list.push_back(2 * double(i) + (double(i) / 100)); double_list.push_back(2 * double(i) + (double(i) / 100));
list2.setGeometry(FPoint{21, 1}, FSize{10, 10});
list2.setText ("double"); list2.setText ("double");
// //
@ -147,11 +148,9 @@ Listbox::Listbox (FWidget* parent)
TLD["gov"] = "Government"; TLD["gov"] = "Government";
list3.insert (TLD.begin(), TLD.end(), mapToString); list3.insert (TLD.begin(), TLD.end(), mapToString);
list3.setGeometry(FPoint{32, 1}, FSize{21, 10});
list3.setText ("key: value"); list3.setText ("key: value");
// Quit button // Quit button
quit.setGeometry(FPoint{42, 12}, FSize{10, 1});
quit.setText (L"&Quit"); quit.setText (L"&Quit");
// Add quit button function callback // Add quit button function callback
@ -164,6 +163,16 @@ Listbox::Listbox (FWidget* parent)
); );
} }
//----------------------------------------------------------------------
void Listbox::initLayout()
{
list1.setGeometry(FPoint{2, 1}, FSize{18, 10});
list2.setGeometry(FPoint{21, 1}, FSize{10, 10});
list3.setGeometry(FPoint{32, 1}, FSize{21, 10});
quit.setGeometry(FPoint{42, 12}, FSize{10, 1});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Listbox::onClose (FCloseEvent* ev) void Listbox::onClose (FCloseEvent* ev)
{ {

View File

@ -54,6 +54,7 @@ class Listview final : public finalcut::FDialog
private: private:
// Method // Method
void populate(); void populate();
void initLayout() override;
// Event handlers // Event handlers
void onClose (finalcut::FCloseEvent*) override; void onClose (finalcut::FCloseEvent*) override;
@ -70,9 +71,6 @@ class Listview final : public finalcut::FDialog
Listview::Listview (finalcut::FWidget* parent) Listview::Listview (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
// Set FListView geometry
listview.setGeometry(FPoint{2, 1}, FSize{33, 14});
// Add columns to the view // Add columns to the view
listview.addColumn ("City"); listview.addColumn ("City");
listview.addColumn ("Condition"); listview.addColumn ("Condition");
@ -104,7 +102,6 @@ Listview::Listview (finalcut::FWidget* parent)
populate(); populate();
// Quit button // Quit button
quit.setGeometry(FPoint{24, 16}, FSize{10, 1});
quit.setText (L"&Quit"); quit.setText (L"&Quit");
// Add some function callbacks // Add some function callbacks
@ -178,6 +175,16 @@ void Listview::populate()
} }
} }
//----------------------------------------------------------------------
void Listview::initLayout()
{
// Set FListView geometry
listview.setGeometry(FPoint{2, 1}, FSize{33, 14});
// Set quit button geometry
quit.setGeometry(FPoint{24, 16}, FSize{10, 1});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Listview::onClose (finalcut::FCloseEvent* ev) void Listview::onClose (finalcut::FCloseEvent* ev)
{ {

View File

@ -46,6 +46,7 @@ class Mandelbrot final : public finalcut::FDialog
private: private:
// Methods // Methods
void initLayout() override;
void draw() override; void draw() override;
void adjustSize() override; void adjustSize() override;
}; };
@ -54,8 +55,14 @@ class Mandelbrot final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Mandelbrot::Mandelbrot (finalcut::FWidget* parent) Mandelbrot::Mandelbrot (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ }
//----------------------------------------------------------------------
void Mandelbrot::initLayout()
{ {
FDialog::setText ("Mandelbrot set"); FDialog::setText ("Mandelbrot set");
FDialog::setGeometry (FPoint{6, 1}, FSize{70, 23});
FDialog::initLayout();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -162,7 +169,6 @@ int main (int argc, char* argv[])
// Create a simple dialog box // Create a simple dialog box
Mandelbrot mb{&app}; Mandelbrot mb{&app};
mb.setGeometry (FPoint{6, 1}, FSize{70, 23});
mb.setShadow(); // Instead of the transparent window shadow mb.setShadow(); // Instead of the transparent window shadow
// Set the mandelbrot object as main widget // Set the mandelbrot object as main widget

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2015-2020 Markus Gans * * Copyright 2015-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -55,6 +55,7 @@ class Menu final : public finalcut::FDialog
void configureStyleMenuItems(); void configureStyleMenuItems();
void configureBorderMenuItems(); void configureBorderMenuItems();
void defaultCallback (const finalcut::FMenuList*); void defaultCallback (const finalcut::FMenuList*);
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Event handler // Event handler
@ -140,12 +141,10 @@ Menu::Menu (finalcut::FWidget* parent)
// Headline labels // Headline labels
Headline1 << " Key "; Headline1 << " Key ";
Headline1.ignorePadding(); Headline1.ignorePadding();
Headline1.setGeometry(FPoint{3, 2}, FSize{5, 1});
Headline1.setEmphasis(); Headline1.setEmphasis();
Headline2 << " Function "; Headline2 << " Function ";
Headline2.ignorePadding(); Headline2.ignorePadding();
Headline2.setGeometry(FPoint{19, 2}, FSize{10, 1});
Headline2.setEmphasis(); Headline2.setEmphasis();
// Info label // Info label
@ -154,7 +153,6 @@ Menu::Menu (finalcut::FWidget* parent)
<< "<Menu> Activate menu bar\n" << "<Menu> Activate menu bar\n"
<< "<Shift>+<Menu> Open dialog menu\n" << "<Shift>+<Menu> Open dialog menu\n"
<< "<Meta>+<X> Exit"; << "<Meta>+<X> Exit";
Info.setGeometry(FPoint{2, 1}, FSize{36, 5});
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -194,8 +192,8 @@ void Menu::configureEditMenuItems()
Undo.setStatusbarMessage ("Undo the previous operation"); Undo.setStatusbarMessage ("Undo the previous operation");
Redo.setDisable(); Redo.setDisable();
Line3.setSeparator(); Line3.setSeparator();
Cut.setStatusbarMessage ( "Remove the input text " Cut.setStatusbarMessage ("Remove the input text "
"and put it in the clipboard" ); "and put it in the clipboard");
Copy.setStatusbarMessage ("Copy the input text into the clipboad"); Copy.setStatusbarMessage ("Copy the input text into the clipboad");
Paste.setStatusbarMessage ("Insert text form clipboard"); Paste.setStatusbarMessage ("Insert text form clipboard");
Line4.setSeparator(); Line4.setSeparator();
@ -286,6 +284,15 @@ void Menu::defaultCallback (const finalcut::FMenuList* mb)
} }
} }
//----------------------------------------------------------------------
void Menu::initLayout()
{
Headline1.setGeometry (FPoint{3, 2}, FSize{5, 1});
Headline2.setGeometry (FPoint{19, 2}, FSize{10, 1});
Info.setGeometry(FPoint{2, 1}, FSize{36, 5});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Menu::adjustSize() void Menu::adjustSize()
{ {

View File

@ -54,6 +54,7 @@ class ColorChooser final : public finalcut::FWidget
private: private:
// Mutator // Mutator
void initLayout() override;
void setSize (const FSize&, bool = true) override; void setSize (const FSize&, bool = true) override;
// Method // Method
@ -74,12 +75,9 @@ class ColorChooser final : public finalcut::FWidget
ColorChooser::ColorChooser (finalcut::FWidget* parent) ColorChooser::ColorChooser (finalcut::FWidget* parent)
: FWidget{parent} : FWidget{parent}
{ {
FWidget::setSize (FSize{8, 12});
setFixedSize (FSize{8, 12});
unsetFocusable(); unsetFocusable();
// Text label // Text label
headline.setGeometry (FPoint{1, 1}, FSize{8, 1});
headline.setEmphasis(); headline.setEmphasis();
headline.setAlignment (finalcut::Align::Center); headline.setAlignment (finalcut::Align::Center);
headline << "Color"; headline << "Color";
@ -97,6 +95,15 @@ inline FColor ColorChooser::getBackground() const
return bg_color; return bg_color;
} }
//----------------------------------------------------------------------
void ColorChooser::initLayout()
{
FWidget::setSize (FSize{8, 12});
setFixedSize (FSize{8, 12});
headline.setGeometry (FPoint{1, 1}, FSize{8, 1});
FWidget::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ColorChooser::setSize (const FSize& size, bool adjust) void ColorChooser::setSize (const FSize& size, bool adjust)
{ {
@ -196,6 +203,7 @@ class Brushes final : public finalcut::FWidget
private: private:
// Mutator // Mutator
void initLayout() override;
void setSize (const FSize&, bool = true) override; void setSize (const FSize&, bool = true) override;
// Method // Method
@ -216,17 +224,23 @@ class Brushes final : public finalcut::FWidget
Brushes::Brushes (finalcut::FWidget* parent) Brushes::Brushes (finalcut::FWidget* parent)
: FWidget{parent} : FWidget{parent}
{ {
FWidget::setSize (FSize{8, 4});
setFixedSize (FSize{8, 4});
unsetFocusable(); unsetFocusable();
// Text label // Text label
headline.setGeometry(FPoint{1, 1}, FSize{8, 1});
headline.setEmphasis(); headline.setEmphasis();
headline.setAlignment (finalcut::Align::Center); headline.setAlignment (finalcut::Align::Center);
headline << "Brush"; headline << "Brush";
} }
//----------------------------------------------------------------------
void Brushes::initLayout()
{
FWidget::setSize (FSize{8, 4});
setFixedSize (FSize{8, 4});
headline.setGeometry(FPoint{1, 1}, FSize{8, 1});
FWidget::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Brushes::setSize (const FSize& size, bool adjust) void Brushes::setSize (const FSize& size, bool adjust)
{ {
@ -310,9 +324,6 @@ inline void Brushes::setBackground (FColor color)
class MouseDraw final : public finalcut::FDialog class MouseDraw final : public finalcut::FDialog
{ {
public: public:
// Using-declaration
using FWidget::setGeometry;
// Constructor // Constructor
explicit MouseDraw (finalcut::FWidget* = nullptr); explicit MouseDraw (finalcut::FWidget* = nullptr);
@ -338,6 +349,7 @@ class MouseDraw final : public finalcut::FDialog
void drawBrush (int, int, bool = false); void drawBrush (int, int, bool = false);
void drawCanvas(); void drawCanvas();
void createCanvas(); void createCanvas();
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Event handler // Event handler
@ -359,14 +371,12 @@ MouseDraw::MouseDraw (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
FDialog::setText ("Drawing with the mouse"); FDialog::setText ("Drawing with the mouse");
c_chooser.setPos (FPoint{1, 1});
c_chooser.addCallback c_chooser.addCallback
( (
"clicked", "clicked",
this, &MouseDraw::cb_colorChanged this, &MouseDraw::cb_colorChanged
); );
brush.setPos (FPoint{1, 12});
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -523,6 +533,14 @@ void MouseDraw::createCanvas()
adjustSize(); adjustSize();
} }
//----------------------------------------------------------------------
void MouseDraw::initLayout()
{
c_chooser.setPos (FPoint{1, 1});
brush.setPos (FPoint{1, 12});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MouseDraw::adjustSize() void MouseDraw::adjustSize()
{ {

View File

@ -49,7 +49,8 @@ class Scrollview final : public finalcut::FScrollView
void setScrollSize (const FSize&) override; void setScrollSize (const FSize&) override;
private: private:
// Method // Methods
void initLayout() override;
void draw() override; void draw() override;
// Callback methods // Callback methods
@ -73,16 +74,6 @@ class Scrollview final : public finalcut::FScrollView
Scrollview::Scrollview (finalcut::FWidget* parent) Scrollview::Scrollview (finalcut::FWidget* parent)
: finalcut::FScrollView{parent} : finalcut::FScrollView{parent}
{ {
// Sets the navigation button geometry
go_east.setGeometry (FPoint{1, 1}, FSize{5, 1});
go_south.setGeometry ( FPoint{int(getScrollWidth()) - 5, 1}
, FSize{5, 1} );
go_west.setGeometry ( FPoint{ int(getScrollWidth()) - 5
, int(getScrollHeight()) - 2 }
, FSize{5, 1} );
go_north.setGeometry ( FPoint{1, int(getScrollHeight()) - 2}
, FSize{5, 1} );
// Add scroll function callbacks to the buttons // Add scroll function callbacks to the buttons
go_east.addCallback go_east.addCallback
( (
@ -109,6 +100,20 @@ Scrollview::Scrollview (finalcut::FWidget* parent)
); );
} }
//----------------------------------------------------------------------
void Scrollview::initLayout()
{
// Sets the navigation button geometry
go_east.setGeometry (FPoint{1, 1}, FSize{5, 1});
go_south.setGeometry ( FPoint{int(getScrollWidth()) - 5, 1}
, FSize{5, 1} );
go_west.setGeometry ( FPoint{ int(getScrollWidth()) - 5
, int(getScrollHeight()) - 2 }
, FSize{5, 1} );
go_north.setGeometry ( FPoint{1, int(getScrollHeight()) - 2}
, FSize{5, 1} );
FScrollView::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Scrollview::setScrollSize (const FSize& size) void Scrollview::setScrollSize (const FSize& size)
{ {
@ -194,6 +199,10 @@ class Scrollviewdemo final : public finalcut::FDialog
// Destructor // Destructor
~Scrollviewdemo() override = default; ~Scrollviewdemo() override = default;
private:
// Method
void initLayout() override;
// Event handler // Event handler
void onClose (finalcut::FCloseEvent*) override; void onClose (finalcut::FCloseEvent*) override;
@ -211,13 +220,6 @@ class Scrollviewdemo final : public finalcut::FDialog
Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent) Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
FDialog::setGeometry (FPoint{16, 3}, FSize{50, 19});
FDialog::setText ("Scrolling viewport example");
// The scrolling viewport widget
sview.setGeometry(FPoint{3, 2}, FSize{44, 12});
sview.setScrollSize(FSize{188, 124});
// Quit button // Quit button
quit_btn.setGeometry(FPoint{37, 15}, FSize{10, 1}); quit_btn.setGeometry(FPoint{37, 15}, FSize{10, 1});
@ -236,9 +238,15 @@ Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Scrollviewdemo::cb_quit() void Scrollviewdemo::initLayout()
{ {
close(); FDialog::setGeometry (FPoint{16, 3}, FSize{50, 19});
FDialog::setText ("Scrolling viewport example");
// The scrolling viewport widget
sview.setGeometry(FPoint{3, 2}, FSize{44, 12});
sview.setScrollSize(FSize{188, 124});
FDialog::initLayout();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -247,6 +255,12 @@ void Scrollviewdemo::onClose (finalcut::FCloseEvent* ev)
finalcut::FApplication::closeConfirmationDialog (this, ev); finalcut::FApplication::closeConfirmationDialog (this, ev);
} }
//----------------------------------------------------------------------
void Scrollviewdemo::cb_quit()
{
close();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// main part // main part

View File

@ -63,6 +63,7 @@ class AttribDlg final : public finalcut::FDialog
private: private:
// Method // Method
void initLayout() override;
void adjustSize() override; void adjustSize() override;
void draw() override; void draw() override;
@ -76,11 +77,7 @@ class AttribDlg final : public finalcut::FDialog
AttribDlg::AttribDlg (finalcut::FWidget* parent) AttribDlg::AttribDlg (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
next_button.setGeometry ( FPoint{int(getWidth()) - 13, int(getHeight()) - 4}
, FSize{10, 1} );
next_button.addAccelerator (finalcut::FKey::Right); next_button.addAccelerator (finalcut::FKey::Right);
back_button.setGeometry ( FPoint{int(getWidth()) - 25, int(getHeight()) - 4}
, FSize{10, 1} );
back_button.addAccelerator (finalcut::FKey::Left); back_button.addAccelerator (finalcut::FKey::Left);
// Add function callbacks // Add function callbacks
@ -167,6 +164,16 @@ void AttribDlg::cb_back()
redraw(); redraw();
} }
//----------------------------------------------------------------------
void AttribDlg::initLayout()
{
next_button.setGeometry ( FPoint{int(getWidth()) - 13, int(getHeight()) - 4}
, FSize{10, 1} );
back_button.setGeometry ( FPoint{int(getWidth()) - 25, int(getHeight()) - 4}
, FSize{10, 1} );
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void AttribDlg::adjustSize() void AttribDlg::adjustSize()
{ {

View File

@ -58,7 +58,8 @@ class Transparent final : public finalcut::FDialog
Transparent& operator = (const Transparent&) = delete; Transparent& operator = (const Transparent&) = delete;
private: private:
// Method // Methods
void initLayout() override;
void draw() override; void draw() override;
// Event handlers // Event handlers
@ -73,11 +74,16 @@ Transparent::Transparent ( finalcut::FWidget* parent
, Transparent::Type tt ) , Transparent::Type tt )
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
, type{tt} , type{tt}
{ }
//----------------------------------------------------------------------
void Transparent::initLayout()
{ {
// Set statusbar text for this window // Set statusbar text for this window
// Avoids calling a virtual function from the constructor // Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP) // (CERT, OOP50-CPP)
FWidget::setStatusbarMessage("Press Q to quit"); FWidget::setStatusbarMessage("Press Q to quit");
FDialog::initLayout();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -166,6 +166,7 @@ class Treeview final : public finalcut::FDialog
auto initNorthAmerica() const -> std::initializer_list<TreeItem>; auto initNorthAmerica() const -> std::initializer_list<TreeItem>;
auto initSouthAmerica() const -> std::initializer_list<TreeItem>; auto initSouthAmerica() const -> std::initializer_list<TreeItem>;
auto initOceania() const -> std::initializer_list<TreeItem>; auto initOceania() const -> std::initializer_list<TreeItem>;
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Event handler // Event handler
@ -209,9 +210,6 @@ struct Treeview::TreeItem
Treeview::Treeview (finalcut::FWidget* parent) Treeview::Treeview (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
// Set FListView geometry
listview.setGeometry(FPoint{2, 1}, FSize{53, 14});
// Add columns to the view // Add columns to the view
listview.addColumn ("Name", 23); listview.addColumn ("Name", 23);
listview.addColumn ("Population"); listview.addColumn ("Population");
@ -257,8 +255,7 @@ Treeview::Treeview (finalcut::FWidget* parent)
} }
} }
// quit button // Quit button text
quit.setGeometry(FPoint{24, 16}, FSize{10, 1});
quit.setText (L"&Quit"); quit.setText (L"&Quit");
// Callback function // Callback function
@ -418,6 +415,16 @@ auto Treeview::initOceania() const -> std::initializer_list<Treeview::TreeItem>
return list; return list;
} }
//----------------------------------------------------------------------
void Treeview::initLayout()
{
// Set FListView geometry
listview.setGeometry(FPoint{2, 1}, FSize{53, 14});
// Set quit button geometry
quit.setGeometry(FPoint{24, 16}, FSize{10, 1});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Treeview::adjustSize() void Treeview::adjustSize()
{ {

View File

@ -43,9 +43,6 @@ using finalcut::FSize;
class ProgressDialog final : public finalcut::FDialog class ProgressDialog final : public finalcut::FDialog
{ {
public: public:
// Using-declaration
using FDialog::setGeometry;
// Constructor // Constructor
explicit ProgressDialog (finalcut::FWidget* = nullptr); explicit ProgressDialog (finalcut::FWidget* = nullptr);
@ -59,6 +56,9 @@ class ProgressDialog final : public finalcut::FDialog
ProgressDialog& operator = (const ProgressDialog&) = delete; ProgressDialog& operator = (const ProgressDialog&) = delete;
private: private:
// Method
void initLayout() override;
// Event handlers // Event handlers
void onShow (finalcut::FShowEvent*) override; void onShow (finalcut::FShowEvent*) override;
void onTimer (finalcut::FTimerEvent*) override; void onTimer (finalcut::FTimerEvent*) override;
@ -79,29 +79,18 @@ class ProgressDialog final : public finalcut::FDialog
ProgressDialog::ProgressDialog (finalcut::FWidget* parent) ProgressDialog::ProgressDialog (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setGeometry ( FPoint{int((getParentWidget()->getWidth() - 40) / 2), 7}
, FSize{40, 10} );
FDialog::setText("Progress bar");
//setModal(); //setModal();
reset.setText("&Reset"); reset.setText("&Reset");
reset.setStatusbarMessage ("Reset the progress bar"); reset.setStatusbarMessage ("Reset the progress bar");
reset.setGeometry(FPoint{2, 6}, FSize{8, 1}, false);
reset.setDisable(); reset.setDisable();
more.setText("&More"); more.setText("&More");
more.setStatusbarMessage ("Increases the progress bar position"); more.setStatusbarMessage ("Increases the progress bar position");
more.setGeometry(FPoint{15, 6}, FSize{8, 1}, false);
more.setDisable(); more.setDisable();
quit.setText("E&xit"); quit.setText("E&xit");
quit.setGeometry(FPoint{28, 6}, FSize{8, 1}, false);
quit.setDisable(); quit.setDisable();
progressbar.setGeometry(FPoint{2, 3}, FSize{34, 1}, false);
//progressbar.setPercentage(78); //progressbar.setPercentage(78);
reset.addCallback reset.addCallback
@ -132,6 +121,19 @@ ProgressDialog::~ProgressDialog() // destructor
delCallback(&reset); delCallback(&reset);
} }
//----------------------------------------------------------------------
void ProgressDialog::initLayout()
{
FDialog::setGeometry ( FPoint{int((getParentWidget()->getWidth() - 40) / 2), 7}
, FSize{40, 10} );
FDialog::setText("Progress bar");
reset.setGeometry(FPoint{2, 6}, FSize{8, 1}, false);
more.setGeometry(FPoint{15, 6}, FSize{8, 1}, false);
quit.setGeometry(FPoint{28, 6}, FSize{8, 1}, false);
progressbar.setGeometry(FPoint{2, 3}, FSize{34, 1}, false);
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ProgressDialog::onShow (finalcut::FShowEvent*) void ProgressDialog::onShow (finalcut::FShowEvent*)
{ {
@ -207,6 +209,7 @@ class TextWindow final : public finalcut::FDialog
private: private:
// Method // Method
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Data members // Data members
@ -218,8 +221,6 @@ TextWindow::TextWindow (finalcut::FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
scrolltext.ignorePadding(); scrolltext.ignorePadding();
scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
setMinimumSize (FSize{51, 6});
scrolltext.setFocus(); scrolltext.setFocus();
scrolltext.insert(" -----------------------------------------------\n" scrolltext.insert(" -----------------------------------------------\n"
" line 1\n" " line 1\n"
@ -237,6 +238,14 @@ void TextWindow::append (const finalcut::FString& str)
scrolltext.append(str); scrolltext.append(str);
} }
//----------------------------------------------------------------------
void TextWindow::initLayout()
{
scrolltext.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
setMinimumSize (FSize{51, 6});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void TextWindow::adjustSize() void TextWindow::adjustSize()
{ {
@ -280,6 +289,7 @@ class MyDialog final : public finalcut::FDialog
void initButtons(); void initButtons();
void initLabels(); void initLabels();
void initWidgetsCallbacks(); void initWidgetsCallbacks();
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Event handlers // Event handlers
@ -574,7 +584,6 @@ void MyDialog::initWidgets()
initToggleButtons(); initToggleButtons();
// A text input field // A text input field
myLineEdit.setGeometry(FPoint{22, 1}, FSize{10, 1});
myLineEdit.setLabelText (L"&Input"); myLineEdit.setLabelText (L"&Input");
myLineEdit.setStatusbarMessage ("Press Enter to set the title"); myLineEdit.setStatusbarMessage ("Press Enter to set the title");
myLineEdit << finalcut::FString{"EnTry"}.toLower(); myLineEdit << finalcut::FString{"EnTry"}.toLower();
@ -583,9 +592,8 @@ void MyDialog::initWidgets()
initButtons(); initButtons();
// A multiple selection listbox // A multiple selection listbox
myList.setGeometry(FPoint{38, 1}, FSize{14, 17});
myList.setText ("Items");
myList.setText ("Items");
myList.setStatusbarMessage ("99 items in a list"); myList.setStatusbarMessage ("99 items in a list");
myList.setMultiSelection(); myList.setMultiSelection();
myList.reserve(100); myList.reserve(100);
@ -601,21 +609,18 @@ void MyDialog::initWidgets()
void MyDialog::initFlatButtons() void MyDialog::initFlatButtons()
{ {
// Flat buttons // Flat buttons
MyButton1.setGeometry(FPoint{3, 3}, FSize{5, 1});
MyButton1.setText (L"&SIN"); MyButton1.setText (L"&SIN");
MyButton1.setStatusbarMessage ("Sine function"); MyButton1.setStatusbarMessage ("Sine function");
MyButton1.setNoUnderline(); MyButton1.setNoUnderline();
MyButton1.setFlat(); MyButton1.setFlat();
MyButton1.setDoubleFlatLine (finalcut::Side::Bottom); MyButton1.setDoubleFlatLine (finalcut::Side::Bottom);
MyButton2.setGeometry(FPoint{3, 5}, FSize{5, 1});
MyButton2.setText (L"&COS"); MyButton2.setText (L"&COS");
MyButton2.setStatusbarMessage ("Cosine function"); MyButton2.setStatusbarMessage ("Cosine function");
MyButton2.setNoUnderline(); MyButton2.setNoUnderline();
MyButton2.setFlat(); MyButton2.setFlat();
MyButton2.setDoubleFlatLine (finalcut::Side::Top); MyButton2.setDoubleFlatLine (finalcut::Side::Top);
MyButton3.setGeometry(FPoint{10, 3}, FSize{5, 3});
MyButton3.setText (L"&="); MyButton3.setText (L"&=");
MyButton3.setStatusbarMessage ("Equal"); MyButton3.setStatusbarMessage ("Equal");
MyButton3.setNoUnderline(); MyButton3.setNoUnderline();
@ -648,25 +653,16 @@ void MyDialog::initFlatButtons()
void MyDialog::initToggleButtons() void MyDialog::initToggleButtons()
{ {
// Radio buttons in a group // Radio buttons in a group
radioButtonGroup.setGeometry(FPoint{3, 8}, FSize{14, 4});
//radioButtonGroup->unsetBorder(); //radioButtonGroup->unsetBorder();
radio1.setGeometry(FPoint{1, 1}, FSize{10, 1});
radio1.setStatusbarMessage ("Enable button Test"); radio1.setStatusbarMessage ("Enable button Test");
radio2.setGeometry(FPoint{1, 2}, FSize{11, 1});
radio2.setText ("&Disable"); radio2.setText ("&Disable");
radio2.setStatusbarMessage ("Disable button Test"); radio2.setStatusbarMessage ("Disable button Test");
radio2.setChecked(); radio2.setChecked();
//radio2.setDisable(); //radio2.setDisable();
// Checkboxes in a group // Checkboxes in a group
checkButtonGroup.setGeometry(FPoint{3, 12}, FSize{14, 4});
check1.setGeometry(FPoint{1, 1}, FSize{11, 1});
check1.setNoUnderline(); check1.setNoUnderline();
check2.setGeometry(FPoint{1, 2}, FSize{9, 1});
check2.setChecked(); check2.setChecked();
check2.setNoUnderline(); check2.setNoUnderline();
} }
@ -675,17 +671,15 @@ void MyDialog::initToggleButtons()
void MyDialog::initButtons() void MyDialog::initButtons()
{ {
// Buttons // Buttons
MyButton4.setGeometry(FPoint{20, 8}, FSize{12, 1});
MyButton4.setText (L"&Get input"); MyButton4.setText (L"&Get input");
MyButton4.setStatusbarMessage ("Take text from input field"); MyButton4.setStatusbarMessage ("Take text from input field");
MyButton4.setFocus(); MyButton4.setFocus();
MyButton5.setGeometry(FPoint{20, 11}, FSize{12, 1});
MyButton5.setText (L"&Test"); MyButton5.setText (L"&Test");
MyButton5.setStatusbarMessage ("Progressbar testing dialog"); MyButton5.setStatusbarMessage ("Progressbar testing dialog");
MyButton5.setDisable(); MyButton5.setDisable();
MyButton6.setGeometry(FPoint{20, 14}, FSize{12, 1});
MyButton6.setText (L"&Quit"); MyButton6.setText (L"&Quit");
MyButton6.setStatusbarMessage ("Exit the program"); MyButton6.setStatusbarMessage ("Exit the program");
MyButton6.addAccelerator(FKey('x')); MyButton6.addAccelerator(FKey('x'));
@ -717,20 +711,12 @@ void MyDialog::initButtons()
void MyDialog::initLabels() void MyDialog::initLabels()
{ {
// Text labels // Text labels
headline.setGeometry(FPoint{21, 3}, FSize{10, 1});
headline.setEmphasis(); headline.setEmphasis();
headline.setAlignment (finalcut::Align::Center); headline.setAlignment (finalcut::Align::Center);
headline = L"List items"; headline = L"List items";
tagged.setGeometry(FPoint{21, 4}, FSize{7, 1});
tagged_count.setGeometry(FPoint{29, 4}, FSize{5, 1});
tagged_count << 0; tagged_count << 0;
sum.setGeometry(FPoint{21, 5}, FSize{7, 3});
sum.setAlignment (finalcut::Align::Right); sum.setAlignment (finalcut::Align::Right);
sum_count.setGeometry(FPoint{29, 5}, FSize{5, 3});
sum_count << myList.getCount(); sum_count << myList.getCount();
} }
@ -767,6 +753,31 @@ void MyDialog::initWidgetsCallbacks()
); );
} }
//----------------------------------------------------------------------
void MyDialog::initLayout()
{
MyButton1.setGeometry(FPoint{3, 3}, FSize{5, 1});
MyButton2.setGeometry(FPoint{3, 5}, FSize{5, 1});
MyButton3.setGeometry(FPoint{10, 3}, FSize{5, 3});
MyButton4.setGeometry(FPoint{20, 8}, FSize{12, 1});
MyButton5.setGeometry(FPoint{20, 11}, FSize{12, 1});
MyButton6.setGeometry(FPoint{20, 14}, FSize{12, 1});
radioButtonGroup.setGeometry(FPoint{3, 8}, FSize{14, 4});
radio1.setGeometry(FPoint{1, 1}, FSize{10, 1});
radio2.setGeometry(FPoint{1, 2}, FSize{11, 1});
checkButtonGroup.setGeometry(FPoint{3, 12}, FSize{14, 4});
check1.setGeometry(FPoint{1, 1}, FSize{11, 1});
check2.setGeometry(FPoint{1, 2}, FSize{9, 1});
headline.setGeometry(FPoint{21, 3}, FSize{10, 1});
tagged.setGeometry(FPoint{21, 4}, FSize{7, 1});
tagged_count.setGeometry(FPoint{29, 4}, FSize{5, 1});
sum.setGeometry(FPoint{21, 5}, FSize{7, 3});
sum_count.setGeometry(FPoint{29, 5}, FSize{5, 3});
myLineEdit.setGeometry(FPoint{22, 1}, FSize{10, 1});
myList.setGeometry(FPoint{38, 1}, FSize{14, 17});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::adjustSize() void MyDialog::adjustSize()
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2015-2020 Markus Gans * * Copyright 2015-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -59,6 +59,7 @@ class Watch final : public finalcut::FDialog
protected: protected:
// Method // Method
void initLayout() override;
void adjustSize() override; void adjustSize() override;
private: private:
@ -75,25 +76,12 @@ class Watch final : public finalcut::FDialog
Watch::Watch (FWidget* parent) Watch::Watch (FWidget* parent)
: finalcut::FDialog{parent} : finalcut::FDialog{parent}
{ {
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setText ("Watch");
FDialog::setSize ({22, 13});
// Labels // Labels
time_label.setGeometry(FPoint{5, 2}, FSize{5, 1});
time_label.setEmphasis(); time_label.setEmphasis();
time_str.setGeometry(FPoint{10, 2}, FSize{8, 1});
// Checkbox buttons // Switch
clock_sw.setGeometry(FPoint{4, 4}, FSize{9, 1});
seconds_sw.setGeometry(FPoint{2, 6}, FSize{11, 1});
sec = seconds_sw.setChecked(); sec = seconds_sw.setChecked();
// Quit button
quit_btn.setGeometry(FPoint{6, 9}, FSize{9, 1});
// Connect switch signal "toggled" with a callback member function // Connect switch signal "toggled" with a callback member function
clock_sw.addCallback clock_sw.addCallback
( (
@ -185,6 +173,27 @@ void Watch::cb_seconds()
} }
} }
//----------------------------------------------------------------------
void Watch::initLayout()
{
// Dialog settings
FDialog::setText ("Watch");
FDialog::setSize ({22, 13}, false);
// Labels
time_label.setGeometry(FPoint{5, 2}, FSize{5, 1});
time_str.setGeometry(FPoint{10, 2}, FSize{8, 1});
// Switches
clock_sw.setGeometry(FPoint{4, 4}, FSize{9, 1});
seconds_sw.setGeometry(FPoint{2, 6}, FSize{11, 1});
// Quit button
quit_btn.setGeometry(FPoint{6, 9}, FSize{9, 1});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Watch::adjustSize() void Watch::adjustSize()
{ {

View File

@ -50,6 +50,7 @@ class SmallWindow final : public finalcut::FDialog
private: private:
// Method // Method
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Event handlers // Event handlers
@ -77,24 +78,20 @@ SmallWindow::SmallWindow (finalcut::FWidget* parent)
left_arrow.setForegroundColor (wc->label_inactive_fg); left_arrow.setForegroundColor (wc->label_inactive_fg);
left_arrow.setEmphasis(); left_arrow.setEmphasis();
left_arrow.ignorePadding(); left_arrow.ignorePadding();
left_arrow.setGeometry (FPoint{2, 2}, FSize{1, 1});
right_arrow = arrow_up; right_arrow = arrow_up;
right_arrow.setForegroundColor (wc->label_inactive_fg); right_arrow.setForegroundColor (wc->label_inactive_fg);
right_arrow.setEmphasis(); right_arrow.setEmphasis();
right_arrow.ignorePadding(); right_arrow.ignorePadding();
right_arrow.setGeometry (FPoint{int(getWidth()) - 1, 2}, FSize{1, 1});
top_left_label.setText("menu"); top_left_label.setText("menu");
top_left_label.setForegroundColor (wc->label_inactive_fg); top_left_label.setForegroundColor (wc->label_inactive_fg);
top_left_label.setEmphasis(); top_left_label.setEmphasis();
top_left_label.setGeometry (FPoint{1, 1}, FSize{6, 1});
top_right_label.setText("zoom"); top_right_label.setText("zoom");
top_right_label.setAlignment (finalcut::Align::Right); top_right_label.setAlignment (finalcut::Align::Right);
top_right_label.setForegroundColor (wc->label_inactive_fg); top_right_label.setForegroundColor (wc->label_inactive_fg);
top_right_label.setEmphasis(); top_right_label.setEmphasis();
top_right_label.setGeometry (FPoint{int(getClientWidth()) - 5, 1}, FSize{6, 1});
finalcut::FString bottom_label_text { "resize\n" finalcut::FString bottom_label_text { "resize\n"
"corner\n" }; "corner\n" };
@ -103,7 +100,17 @@ SmallWindow::SmallWindow (finalcut::FWidget* parent)
bottom_label.setAlignment (finalcut::Align::Right); bottom_label.setAlignment (finalcut::Align::Right);
bottom_label.setForegroundColor (wc->label_inactive_fg); bottom_label.setForegroundColor (wc->label_inactive_fg);
bottom_label.setEmphasis(); bottom_label.setEmphasis();
}
//----------------------------------------------------------------------
void SmallWindow::initLayout()
{
left_arrow.setGeometry (FPoint{2, 2}, FSize{1, 1});
right_arrow.setGeometry (FPoint{int(getWidth()) - 1, 2}, FSize{1, 1});
top_left_label.setGeometry (FPoint{1, 1}, FSize{6, 1});
top_right_label.setGeometry (FPoint{int(getClientWidth()) - 5, 1}, FSize{6, 1});
bottom_label.setGeometry (FPoint{13, 3}, FSize{6, 3}); bottom_label.setGeometry (FPoint{13, 3}, FSize{6, 3});
FDialog::initLayout();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -199,6 +206,8 @@ class Window final : public finalcut::FDialog
void configureFileMenuItems(); void configureFileMenuItems();
void configureDialogButtons(); void configureDialogButtons();
void activateWindow (finalcut::FDialog*) const; void activateWindow (finalcut::FDialog*) const;
void initLayout() override;
void adjustSize() override; void adjustSize() override;
template <typename InstanceT template <typename InstanceT
, typename CallbackT , typename CallbackT
@ -317,11 +326,8 @@ void Window::configureFileMenuItems()
void Window::configureDialogButtons() void Window::configureDialogButtons()
{ {
// Dialog buttons // Dialog buttons
CreateButton.setGeometry (FPoint{2, 2}, FSize{9, 1});
CreateButton.setText (L"&Create"); CreateButton.setText (L"&Create");
CloseButton.setGeometry (FPoint{15, 2}, FSize{9, 1});
CloseButton.setText (L"C&lose"); CloseButton.setText (L"C&lose");
QuitButton.setGeometry (FPoint{28, 2}, FSize{9, 1});
QuitButton.setText (L"&Quit"); QuitButton.setText (L"&Quit");
// Add button callback // Add button callback
@ -346,6 +352,15 @@ void Window::activateWindow (finalcut::FDialog* win) const
win->redraw(); win->redraw();
} }
//----------------------------------------------------------------------
void Window::initLayout()
{
CreateButton.setGeometry (FPoint{2, 2}, FSize{9, 1});
CloseButton.setGeometry (FPoint{15, 2}, FSize{9, 1});
QuitButton.setGeometry (FPoint{28, 2}, FSize{9, 1});
FDialog::initLayout();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Window::adjustSize() void Window::adjustSize()
{ {

View File

@ -1172,10 +1172,11 @@ void FDialog::drawTextBar()
const auto width = getWidth(); const auto width = getWidth();
const auto zoom_btn = getZoomButtonWidth(); const auto zoom_btn = getZoomButtonWidth();
const auto tb_width = width - MENU_BTN - zoom_btn;
const auto length = getColumnWidth(tb_text); const auto length = getColumnWidth(tb_text);
if ( width > length + MENU_BTN + zoom_btn ) if ( width > length + MENU_BTN + zoom_btn )
center_offset = (width - length - MENU_BTN - zoom_btn) / 2; center_offset = (tb_width - length) / 2;
for ( ; x <= center_offset; x++) for ( ; x <= center_offset; x++)
print (' '); print (' ');
@ -1183,12 +1184,13 @@ void FDialog::drawTextBar()
// Print title bar text // Print title bar text
if ( ! tb_text.isEmpty() ) if ( ! tb_text.isEmpty() )
{ {
if ( length <= width - MENU_BTN - zoom_btn ) if ( length <= tb_width )
print (tb_text); print (tb_text);
else else
{ {
// Print ellipsis // Print ellipsis
print (tb_text.left(width - MENU_BTN - zoom_btn - 2)); const auto len = getLengthFromColumnWidth (tb_text, tb_width - 2);
print (tb_text.left(len));
print (".."); print ("..");
} }
} }

View File

@ -171,17 +171,7 @@ void FMenuItem::unsetSelected()
void FMenuItem::setText (const FString& txt) void FMenuItem::setText (const FString& txt)
{ {
text.setString(txt); text.setString(txt);
text_length = text.getLength(); calculateTextDimensions();
text_width = getColumnWidth(txt);
hotkey = finalcut::getHotkey(text);
if ( hotkey != FKey::None )
{
text_length--;
text_width--;
}
updateSuperMenuDimensions();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -481,6 +471,11 @@ bool FMenuItem::isMenu (const FWidget* w) const
return m1 || m2; return m1 || m2;
} }
//----------------------------------------------------------------------
void FMenuItem::initLayout()
{
calculateTextDimensions();
}
// private methods of FMenuItem // private methods of FMenuItem
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -557,6 +552,23 @@ void FMenuItem::init()
} }
} }
//----------------------------------------------------------------------
void FMenuItem::calculateTextDimensions()
{
text_length = text.getLength();
text_width = getColumnWidth(text);
hotkey = finalcut::getHotkey(text);
if ( hotkey != FKey::None )
{
text_length--;
text_width--;
}
updateMenubarDimensions();
updateSuperMenuDimensions();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::updateSuperMenuDimensions() void FMenuItem::updateSuperMenuDimensions()
{ {
@ -567,6 +579,18 @@ void FMenuItem::updateSuperMenuDimensions()
menu_ptr->calculateDimensions(); menu_ptr->calculateDimensions();
} }
//----------------------------------------------------------------------
void FMenuItem::updateMenubarDimensions()
{
FWidget* parent = getParentWidget();
if ( ! parent || ! isMenuBar(parent) )
return;
auto menubar_ptr = static_cast<FMenuBar*>(parent);
menubar_ptr->calculateDimensions();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::processEnable() const void FMenuItem::processEnable() const
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2014-2020 Markus Gans * * Copyright 2014-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -120,6 +120,13 @@ FMessageBox::ButtonType FMessageBox::exec()
} }
// protected methods of FMessageBox // protected methods of FMessageBox
//----------------------------------------------------------------------
void FMessageBox::initLayout()
{
calculateDimensions();
adjustButtons();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMessageBox::adjustSize() void FMessageBox::adjustSize()
{ {

View File

@ -42,7 +42,6 @@
#include <algorithm> #include <algorithm>
#include <string> #include <string>
#include <thread>
#include <vector> #include <vector>
#include "final/emptyfstring.h" #include "final/emptyfstring.h"
@ -132,6 +131,54 @@ FTermcap::Status FTermcap::paddingPrint ( const std::string& string
|| ( ! xon_xoff_flow_control && padding_baudrate || ( ! xon_xoff_flow_control && padding_baudrate
&& (baudrate >= padding_baudrate) ); && (baudrate >= padding_baudrate) );
auto iter = string.begin(); auto iter = string.begin();
using iter_type = decltype(iter);
auto read_digits = [] (iter_type& iter, int& number)
{
while ( std::isdigit(int(*iter)) && number < 1000 )
{
number = number * 10 + (*iter - '0');
++iter;
}
number *= 10;
};
auto decimal_point = [] (iter_type& iter, int& number)
{
if ( *iter == '.' )
{
++iter;
if ( std::isdigit(int(*iter)) )
{
number += (*iter - '0'); // Position after decimal point
++iter;
}
while ( std::isdigit(int(*iter)) )
++iter;
}
};
auto asterisk_slash = [&affcnt, &has_delay] (iter_type& iter, int& number)
{
while ( *iter == '*' || *iter == '/' )
{
if ( *iter == '*' )
{
// Padding is proportional to the number of affected lines (suffix '*')
number *= affcnt;
++iter;
}
else
{
// Padding is mandatory (suffix '/')
has_delay = true;
++iter;
}
}
};
while ( iter != string.end() ) while ( iter != string.end() )
{ {
@ -161,44 +208,9 @@ FTermcap::Status FTermcap::paddingPrint ( const std::string& string
} }
int number = 0; int number = 0;
read_digits (iter, number);
while ( std::isdigit(int(*iter)) && number < 1000 ) decimal_point (iter, number);
{ asterisk_slash (iter, number);
number = number * 10 + (*iter - '0');
++iter;
}
number *= 10;
if ( *iter == '.' )
{
++iter;
if ( std::isdigit(int(*iter)) )
{
number += (*iter - '0'); // Position after decimal point
++iter;
}
while ( std::isdigit(int(*iter)) )
++iter;
}
while ( *iter == '*' || *iter == '/' )
{
if ( *iter == '*' )
{
// Padding is proportional to the number of affected lines (suffix '*')
number *= affcnt;
++iter;
}
else
{
// Padding is mandatory (suffix '/')
has_delay = true;
++iter;
}
}
if ( *iter != '>' ) if ( *iter != '>' )
{ {
@ -435,28 +447,6 @@ std::string FTermcap::encodeParams ( const std::string& cap
return ( str ) ? str : std::string(); return ( str ) ? str : std::string();
} }
//----------------------------------------------------------------------
void FTermcap::delay_output (int ms, const defaultPutChar& outc)
{
if ( no_padding_char )
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
else
{
static constexpr int baudbyte = 9; // = 7 bit + 1 parity + 1 stop
for ( int pad_char_count = (ms * baudrate) / (baudbyte * 1000);
pad_char_count > 0;
pad_char_count-- )
{
outc(int(PC));
}
std::fflush(stdout);
}
}
// private Data Member of FTermcap - termcap capabilities // private Data Member of FTermcap - termcap capabilities
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -464,6 +464,21 @@ void FTextView::onFocusOut (FFocusEvent*)
// protected methods of FTextView // protected methods of FTextView
//----------------------------------------------------------------------
void FTextView::initLayout()
{
if ( data.empty() )
return;
for (auto&& line : data)
{
const auto column_width = getColumnWidth(line);
if ( column_width > max_line_width )
max_line_width = column_width;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::adjustSize() void FTextView::adjustSize()
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the FINAL CUT widget toolkit * * This file is part of the FINAL CUT widget toolkit *
* * * *
* Copyright 2016-2020 Markus Gans * * Copyright 2016-2021 Markus Gans *
* * * *
* FINAL CUT is free software; you can redistribute it and/or modify * * FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -176,9 +176,14 @@ void FToolTip::calculateDimensions()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToolTip::adjustSize() void FToolTip::initLayout()
{ {
calculateDimensions(); calculateDimensions();
}
//----------------------------------------------------------------------
void FToolTip::adjustSize()
{
FWindow::adjustSize(); FWindow::adjustSize();
} }

View File

@ -972,8 +972,9 @@ void FWidget::show()
show_root_widget = this; show_root_widget = this;
} }
adjustSize(); // Alignment before drawing initWidgetLayout(); // Makes initial layout settings
draw(); // Draw the widget adjustSize(); // Alignment before drawing
draw(); // Draw the widget
flags.hidden = false; flags.hidden = false;
flags.shown = true; flags.shown = true;
@ -1284,6 +1285,13 @@ void FWidget::initDesktop()
init_desktop = true; init_desktop = true;
} }
//----------------------------------------------------------------------
void FWidget::initLayout()
{
// This method must be reimplemented in a subclass to automatically
// set the widget layouts, before the initial drawing on the terminal
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::adjustSize() void FWidget::adjustSize()
{ {
@ -1767,6 +1775,24 @@ void FWidget::initRootWidget()
determineDesktopSize(); determineDesktopSize();
} }
//----------------------------------------------------------------------
void FWidget::initWidgetLayout()
{
initLayout();
if ( ! hasChildren() )
return;
for (auto&& child : getChildren())
{
if ( child->isWidget() )
{
auto widget = static_cast<FWidget*>(child);
widget->initWidgetLayout();
}
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::finish() void FWidget::finish()
{ {

View File

@ -148,13 +148,18 @@ class FMenuItem : public FWidget
bool isMenuBar (const FWidget*) const; bool isMenuBar (const FWidget*) const;
bool isMenu (const FWidget*) const; bool isMenu (const FWidget*) const;
// Method
void initLayout() override;
private: private:
// Accessor // Accessor
FMenuList* getFMenuList (FWidget&); FMenuList* getFMenuList (FWidget&);
// Methods // Methods
void init(); void init();
void calculateTextDimensions();
void updateSuperMenuDimensions(); void updateSuperMenuDimensions();
void updateMenubarDimensions();
void processEnable() const; void processEnable() const;
void processDisable() const; void processDisable() const;
void processActivate() const; void processActivate() const;

View File

@ -139,6 +139,7 @@ class FMessageBox : public FDialog
, ButtonType = ButtonType::Reject ); , ButtonType = ButtonType::Reject );
protected: protected:
// Method // Method
void initLayout() override;
void adjustSize() override; void adjustSize() override;
void done (ButtonType); void done (ButtonType);

View File

@ -37,6 +37,7 @@
#include <array> #include <array>
#include <string> #include <string>
#include <thread>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -129,7 +130,8 @@ class FTermcap final
static void termcapKeys(); static void termcapKeys();
static std::string encodeParams ( const std::string& static std::string encodeParams ( const std::string&
, const std::vector<int>& ); , const std::vector<int>& );
static void delay_output (int, const defaultPutChar&); template<typename PutChar>
static void delay_output (int, const PutChar&);
// Data member // Data member
static bool initialized; static bool initialized;
@ -162,6 +164,29 @@ inline void FTermcap::setBaudrate (int baud)
baudrate = baud; baudrate = baud;
} }
//----------------------------------------------------------------------
template<typename PutChar>
inline void FTermcap::delay_output (int ms, const PutChar& outc)
{
if ( no_padding_char )
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
else
{
static constexpr int baudbyte = 9; // = 7 bit + 1 parity + 1 stop
for ( int pad_char_count = (ms * baudrate) / (baudbyte * 1000);
pad_char_count > 0;
pad_char_count-- )
{
outc(int(PC));
}
std::fflush(stdout);
}
}
} // namespace finalcut } // namespace finalcut

View File

@ -134,6 +134,7 @@ class FTextView : public FWidget
protected: protected:
// Method // Method
void initLayout() override;
void adjustSize() override; void adjustSize() override;
private: private:

View File

@ -103,6 +103,7 @@ class FToolTip : public FWindow
void init(); void init();
void draw() override; void draw() override;
void calculateDimensions(); void calculateDimensions();
void initLayout() override;
void adjustSize() override; void adjustSize() override;
// Data members // Data members

View File

@ -349,6 +349,7 @@ class FWidget : public FVTerm, public FObject
// Methods // Methods
void initTerminal() override; void initTerminal() override;
void initDesktop(); void initDesktop();
virtual void initLayout();
virtual void adjustSize(); virtual void adjustSize();
void adjustSizeGlobal(); void adjustSizeGlobal();
void hideArea (const FSize&); void hideArea (const FSize&);
@ -424,6 +425,7 @@ class FWidget : public FVTerm, public FObject
// Methods // Methods
void determineDesktopSize(); void determineDesktopSize();
void initRootWidget(); void initRootWidget();
void initWidgetLayout();
void finish(); void finish();
void insufficientSpaceAdjust(); void insufficientSpaceAdjust();
void KeyPressEvent (FKeyEvent*); void KeyPressEvent (FKeyEvent*);