Back to index

nux  3.0.0
shortcut-keys.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License version 3, as published
00006  * by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * version 3 along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>
00016  *
00017  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00018  *
00019  */
00020 
00021 #include "Nux/Nux.h"
00022 #include "Nux/VLayout.h"
00023 #include "Nux/HLayout.h"
00024 #include "Nux/WindowThread.h"
00025 #include "Nux/StaticText.h"
00026 
00027 #include "line-separator.h"
00028 
00029 int SECTION_NAME_FONT_SIZE = 17;
00030 int SHORTKEY_ENTRY_FONT_SIZE = 13;
00031 int INTER_SPACE_SHORTKEY_DESCRIPTION = 0;
00032 int SHORTKEY_COLUMN_WIDTH = 150 + 100;
00033 int DESCRIPTION_COLUMN_WIDTH = 265 + 100;
00034 
00035 
00036 nux::LinearLayout *CreateSectionLayout(const char *section_name)
00037 {
00038   nux::VLayout *layout = new nux::VLayout(NUX_TRACKER_LOCATION);
00039 
00040   nux::StaticText* section_name_view = new nux::StaticText(section_name, NUX_TRACKER_LOCATION);
00041   section_name_view->SetTextPointSize(SECTION_NAME_FONT_SIZE);
00042   section_name_view->SetFontName("Ubuntu Bold");
00043   layout->AddView(section_name_view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
00044   layout->AddView(new nux::SpaceLayout(30, 30, 30, 30), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
00045 
00046   return layout;
00047 }
00048 
00049 nux::LinearLayout *CreateShortKeyEntryLayout(const char *shortkey, const char *description)
00050 {
00051   nux::HLayout *layout = new nux::HLayout("EntryLayout", NUX_TRACKER_LOCATION);
00052   nux::HLayout *shortkey_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
00053   nux::HLayout *description_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
00054 
00055   nux::StaticText* shortkey_view = new nux::StaticText(shortkey, NUX_TRACKER_LOCATION);
00056   shortkey_view->SetTextAlignment(nux::StaticText::ALIGN_LEFT);
00057   shortkey_view->SetTextPointSize(SHORTKEY_ENTRY_FONT_SIZE);
00058   shortkey_view->SetMinimumWidth(SHORTKEY_COLUMN_WIDTH);
00059   shortkey_view->SetMaximumWidth(SHORTKEY_COLUMN_WIDTH);
00060 
00061   nux::StaticText* description_view = new nux::StaticText(description, NUX_TRACKER_LOCATION);
00062   description_view->SetTextAlignment(nux::StaticText::ALIGN_LEFT);
00063   description_view->SetTextPointSize(SHORTKEY_ENTRY_FONT_SIZE);
00064   description_view->SetMinimumWidth(DESCRIPTION_COLUMN_WIDTH);
00065   description_view->SetMaximumWidth(DESCRIPTION_COLUMN_WIDTH);
00066 
00067   shortkey_layout->AddView(shortkey_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
00068   shortkey_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
00069   shortkey_layout->SetMinimumWidth(SHORTKEY_COLUMN_WIDTH);
00070   shortkey_layout->SetMaximumWidth(SHORTKEY_COLUMN_WIDTH);
00071 
00072   description_layout->AddView(description_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
00073   description_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
00074   description_layout->SetMinimumWidth(DESCRIPTION_COLUMN_WIDTH);
00075   description_layout->SetMaximumWidth(DESCRIPTION_COLUMN_WIDTH);
00076 
00077   layout->AddLayout(shortkey_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
00078   layout->AddLayout(description_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
00079   layout->SetSpaceBetweenChildren(INTER_SPACE_SHORTKEY_DESCRIPTION);
00080   description_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
00081 
00082   return layout;
00083 }
00084 
00085 nux::LinearLayout *CreateIntermediateLayout()
00086 {
00087   nux::VLayout *layout = new nux::VLayout(NUX_TRACKER_LOCATION);
00088 
00089   return layout;
00090 }
00091 
00092 void UserInterfaceInitialization(nux::NThread* thread, void* InitData)
00093 {
00094   nux::VLayout *root_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
00095 
00096   nux::LinearLayout *section_layout = CreateSectionLayout("Launcher");
00097   nux::LinearLayout *intermediate_layout = CreateIntermediateLayout();
00098   intermediate_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
00099 
00100   intermediate_layout->AddLayout(CreateShortKeyEntryLayout("Super (Press)",           "Open Launcher, displays shortcuts."), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);
00101   intermediate_layout->AddLayout(CreateShortKeyEntryLayout("Alt + F1 (Press)",        "Open Launcher keyboard navigation mode."), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00102   intermediate_layout->AddLayout(CreateShortKeyEntryLayout("Super + Tab",             "Switch application via Launcher."), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00103   intermediate_layout->AddLayout(CreateShortKeyEntryLayout("Super + 1 to 9",          "Same as clicking on a Launcher icon."), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00104   intermediate_layout->AddLayout(CreateShortKeyEntryLayout("Super + Shift + 1 to 9",  "Open a new window of the app."), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00105   intermediate_layout->AddLayout(CreateShortKeyEntryLayout("Super + T",               "Open the Rubbish Bin."), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00106 
00107   section_layout->AddLayout(intermediate_layout, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00108 
00109   // Add space before the line
00110   section_layout->AddView(new nux::SpaceLayout(30, 30, 30, 30), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
00111   section_layout->AddView(new nux::HSeparator(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00112   // Add space after the line
00113   section_layout->AddView(new nux::SpaceLayout(30, 30, 30, 30), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
00114 
00115 
00116   root_layout->AddView(section_layout, 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);
00117 
00118   nux::GetWindowThread ()->SetLayout(root_layout);
00119   nux::ColorLayer background(nux::Color(0xFF222222));
00120   static_cast<nux::WindowThread*>(thread)->SetWindowBackgroundPaintLayer(&background);
00121 }
00122 
00123 int main(int argc, char **argv)
00124 {
00125   // Initialize Nux.
00126   nux::NuxInitialize(0);
00127 
00128   // Create a window thread.
00129   nux::WindowThread* wt = nux::CreateGUIThread("Shortcut Keys", 640, 300, 0, &UserInterfaceInitialization, 0);
00130 
00131   // Start the main loop.
00132   wt->Run(NULL);
00133 
00134   delete wt;
00135   return 0;
00136 }