Skip to content

Commit

Permalink
fix(memory): memory should be freed now always
Browse files Browse the repository at this point in the history
add(context menu): added context menu and example usage
  • Loading branch information
MurkyYT committed Feb 21, 2024
1 parent b392c83 commit e476e09
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 67 deletions.
24 changes: 24 additions & 0 deletions Demo/ControlsDemoWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@ ControlsDemoWindow::ControlsDemoWindow()
void ControlsDemoWindow::ButtonClick()
{
std::wstring res = textBox->GetText();
/*textBox->EnableHorizontalScrollbar(!textBox->HorizontalScrollbarEnabled());
textBox->EnableVerticalScrollbar(!textBox->VerticalScrollbarEnabled());*/
MessageBox(NULL, res.c_str(), L"TextBox text is", MB_OK);
}
void ControlsDemoWindow::ContextMenuOpen()
{
ContextMenu* menu = new ContextMenu();
Menu* test = new Menu(L"Test");
Menu* test2 = new Menu(L"Test2");
menu->Add(test);
menu->Add(new Separator());
menu->Add(test2);
menu->Add(new Separator());
menu->Add(test);
menu->Add(new Separator());
menu->Add(test2);
menu->Add(new Separator());
menu->Add(test);
menu->Add(new Separator());
menu->Add(test2);
menu->Add(new Separator());
menu->Add(test);
menu->Add(new Separator());
menu->Add(test2);
menu->Open();
}
void ControlsDemoWindow::RadioGroupChanged()
{
int index = group->CurrentRadioButton();
Expand Down
24 changes: 14 additions & 10 deletions Demo/ControlsDemoWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,37 @@ class ControlsDemoWindow : public Window
TextBox* textBox;
void RadioGroupChanged();
void ButtonClick();
void ContextMenuOpen();
void InitializeComponent()
{
this->Create(L"MUI Controls Demo", (DWORD)IDI_ICON1);
textBox = new TextBox(L"Test-TextBox", FALSE, 0, 0, 100, 100);
/*
* Add vertical scroll bar.
* If before window creation it shows correctly, if after, only scroll wheel works(could be a bug ? )
* If before adding to window it shows correctly, if after, only scroll wheel works(could be a bug ? )
*/
textBox->SetStyle(textBox->GetStyle() | WS_VSCROLL);
Button* button = new Button(L"Input-Box text",FALSE, 0, 100, 100, 20);
radioBlock = new TextBlock(L"Radio Index: -1", 120, 50, 100, 15);
group = new RadioGroup(L"Window Mode", 120, 70, 209, 85);
Button* button = new Button(L"Input-Box text", FALSE, 0, 100, 100, 20);
Button* button4 = new Button(L"Open contextmenu", FALSE, 0, 200, 200, 20);
RadioButton* button1 = new RadioButton(L"Fullscreen", 130, 90, 90, 15);
RadioButton* button2 = new RadioButton(L"Windowed Fullscreen", 130, 110, 140, 15);
RadioButton* button3 = new RadioButton(L"Windowed", 130, 130, 140, 15);
group->AddRadioButton(button1);
group->AddRadioButton(button2);
group->AddRadioButton(button3);
button->OnClick = std::bind(&ControlsDemoWindow::ButtonClick, this);
group->OnChange = std::bind(&ControlsDemoWindow::RadioGroupChanged, this);
this->Create(L"MUI Controls Demo", (DWORD)IDI_ICON1);
radioBlock = new TextBlock(L"Radio Index: -1", 120, 50, 100, 15);
group = new RadioGroup(L"Window Mode", 120, 70, 209, 85);
this->AddComponent(button1);
this->AddComponent(button2);
this->AddComponent(button3);
this->AddComponent(button);
this->AddComponent(button4);
this->AddComponent(textBox);
this->AddComponent(group);
this->AddComponent(radioBlock);
group->AddRadioButton(button1);
group->AddRadioButton(button2);
group->AddRadioButton(button3);
button->OnClick = std::bind(&ControlsDemoWindow::ButtonClick, this);
group->OnChange = std::bind(&ControlsDemoWindow::RadioGroupChanged, this);
button4->OnClick = std::bind(&ControlsDemoWindow::ContextMenuOpen, this);
}
};

4 changes: 1 addition & 3 deletions Demo/GridDemoWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ void GridDemoWindow::WindowClose()
{
OutputDebugString(L"Window is closed!\n");
}
void GridDemoWindow::CheckBoxClick(UIComponent* sender,EventArgs_t e)
void GridDemoWindow::CheckBoxClick()
{
if (checkBox->IsChecked()) {
//button.SetStyle(button.GetStyle() | BS_OWNERDRAW);
textBlock->SetText(L"Checked");
listView->Show();
}
else
{
//button.SetStyle(button.GetStyle() & ~BS_OWNERDRAW);
textBlock->SetText(L"UnChecked");
listView->Hide();
}
Expand Down
28 changes: 14 additions & 14 deletions Demo/GridDemoWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,45 @@ class GridDemoWindow : public Window
CheckBox* checkBox;
TextBlock* textBlock;
ListView* listView;
void WindowClose(/*UIComponent* sender, EventArgs_t e*/);
void CheckBoxClick(UIComponent* sender,EventArgs_t e);
void WindowClose();
void CheckBoxClick();
void InitializeComponent()
{
Grid* grid = new Grid();
this->Create(L"MUI Grid Demo", (DWORD)IDI_ICON1);
this->OnClose = std::bind(&GridDemoWindow::WindowClose, this);
this->SetBackroundColor(MUI::Color::PURPLE);
this->m_StaticBacgkround = MUI::Color::PURPLE;
this->m_StaticTextColor = MUI::Color::LIGHT_PURPLE;
this->m_EditBacgkround = MUI::Color::LIGHT_PURPLE;
this->m_ButtonBacgkround = MUI::Color::WHITE;
this->m_ButtonTextColor = MUI::Color::DARK_PURPLE;
grid->AddColumn(0, L"Auto");
grid->AddColumn(0, L"*");
grid->AddColumn(0, L"Auto");
Grid* grid = new Grid();
checkBox = new CheckBox(L"CheckBox", 100, 300, 70, 15);
checkBox->SetVerticalAligment(Center);
checkBox->OnClick = std::bind(&GridDemoWindow::CheckBoxClick, this, std::placeholders::_1, std::placeholders::_2);
checkBox->OnClick = std::bind(&GridDemoWindow::CheckBoxClick, this);
listView = new ListView(10, 10, 200, 200);
listView->SetHorizontalAligment(Stretch);
listView->SetVerticalAligment(Stretch);
textBlock = new TextBlock(L"", 180, 0, 70, 15);
textBlock->SetVerticalAligment(Center);
textBlock->SetText(L"Checked");
grid->AddColumn(0, L"Auto");
grid->AddColumn(0, L"*");
grid->AddColumn(0, L"Auto");
grid->AddItem(listView, 0, 1);
grid->AddItem(checkBox, 0, 2);
grid->AddItem(textBlock, 0, 0);
this->OnClose = std::bind(&GridDemoWindow::WindowClose, this);
this->Create(L"MUI Grid Demo", (DWORD)IDI_ICON1);
this->SetGrid(grid);
listView->Clear();
HICON ico = LoadIcon(this->GetHINSTACE(), MAKEINTRESOURCE(IDI_ICON1));
listView->AddIcon(ico);
listView->AddColumn(L"Test", 100);
listView->AddColumn(L"Test2", 100);
ListItem itm(0, std::vector<std::wstring> {L"TEST1", L"TEST2"});
listView->AddItem(&itm);
ListItem itm2(0, std::vector<std::wstring> {L"TEST3", L"TEST4"});
listView->AddItem(&itm2);
checkBox->SetChecked(1);
ListItem* itm = new ListItem(0, std::vector<std::wstring> {L"TEST1", L"TEST2"});
listView->AddItem(itm);
ListItem* itm2 = new ListItem(0, std::vector<std::wstring> {L"TEST3", L"TEST4"});
listView->AddItem(itm2);
checkBox->SetChecked(1);
}
};

19 changes: 12 additions & 7 deletions Demo/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ void MainWindow::OpenGridExample()
{
if (!gridDemo || gridDemo->IsHidden())
{
if (gridDemo)
delete gridDemo;
gridDemo = new GridDemoWindow();
gridDemo->Show();
}
Expand All @@ -15,13 +17,16 @@ void MainWindow::OpenGridExample()
}
void MainWindow::OpenControlsDemo()
{
if (!controlsDemo || controlsDemo->IsHidden())
{
controlsDemo = new ControlsDemoWindow();
controlsDemo->Show();
}
else
controlsDemo->Activate();

if (!controlsDemo || controlsDemo->IsHidden())
{
if(controlsDemo)
delete controlsDemo;
controlsDemo = new ControlsDemoWindow();
controlsDemo->Show();
}
else
controlsDemo->Activate();
}
void MainWindow::ShowAbout()
{
Expand Down
2 changes: 2 additions & 0 deletions Demo/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class MainWindow : public Window
void OpenGridExample();
void OpenControlsDemo();
void ShowAbout();
void ControlsDemoClosed();
void GridDemoClosed();
GridDemoWindow* gridDemo;
ControlsDemoWindow* controlsDemo;
void InitializeComponent()
Expand Down
30 changes: 18 additions & 12 deletions Demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
#include "MainWindow.h"


INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) {
(void)hPrevInstance;
(void)lpCmdLine;

MainWindow* mainWind = new MainWindow();
mainWind->Show();
INT WINAPI WinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nShowCmd
)
{
(void)hPrevInstance;
(void)lpCmdLine;

MSG msg = {};
MainWindow* mainWind = new MainWindow();
mainWind->Show();

while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
MSG msg = {};

return static_cast<int>(msg.wParam);
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return static_cast<int>(msg.wParam);
}
Loading

0 comments on commit e476e09

Please sign in to comment.