friendspanelcoolestbutone

 avatar
chamanEiqbal
c_cpp
8 months ago
3.3 kB
1
Indexable
Never
#ifndef FRIENDSPANEL_H
#define FRIENDSPANEL_H

#include <wx/wx.h>
#include <wx/scrolwin.h>
#include "database/friendsDao.h"
#include "classes/User.h"

    class FriendsPanel : public wxPanel {
    public:
        FriendsPanel(wxWindow* parent, User user) : wxPanel(parent), user_(user) {
            
            FriendsDAO dao_friends;
            vector<string> usernames = dao_friends.getFriends(user.id);

            wxBoxSizer* mainBoxSizer = new wxBoxSizer(wxVERTICAL);

            
            wxStaticText* titleLabel = new wxStaticText(this, wxID_ANY, "Chatterchum - Your Friends");
            titleLabel->SetFont(wxFont(30, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
            titleLabel->SetForegroundColour(wxColour(255, 255, 255));
            mainBoxSizer->Add(titleLabel, 0, wxTOP | wxLEFT, 10); 

            
            wxBoxSizer* boxSizer = new wxBoxSizer(wxHORIZONTAL);

            
            scrolledWindow = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL);

            
            scrolledBoxSizer = new wxBoxSizer(wxHORIZONTAL);

            // Add square panels with names to the scrolled window
            for (int i = 0; i < usernames.size(); ++i) {  
                wxPanel* squarePanel = CreateSquarePanel(usernames[i]);
                scrolledBoxSizer->Add(squarePanel, 0, wxALL, 10);
            }

            
            scrolledWindow->SetSizer(scrolledBoxSizer);

            scrolledWindow->SetMinSize(wxSize(400, -1));  
            scrolledWindow->SetScrollRate(10,0);
           
            scrolledWindow->SetBackgroundColour(wxColour(0, 0, 0));

            // Add the scrolled window to the main box sizer
            boxSizer->Add(scrolledWindow, 1, wxEXPAND);

            // Add the box sizer to the main box sizer
            mainBoxSizer->Add(boxSizer, 1, wxEXPAND);

            // Set the main box sizer as the sizer for the panel
            SetSizerAndFit(mainBoxSizer);

            // Set the background color for the main panel
            SetBackgroundColour(wxColour(0, 0, 0));
        }

    private:
        wxScrolledWindow* scrolledWindow;
        wxBoxSizer* scrolledBoxSizer;

        wxPanel* CreateSquarePanel(const wxString& name) {
            // Create a square panel
            wxPanel* panel = new wxPanel(scrolledWindow, wxID_ANY, wxDefaultPosition, wxSize(100, 100));
            panel->SetBackgroundColour(wxColour(25, 25, 25));  // Square panel background color

            // Add a text control to display the name
            wxStaticText* nameLabel = new wxStaticText(panel, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER);
            nameLabel->SetFont(wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
            nameLabel->SetForegroundColour(wxColour(100, 209, 10));  // Text color

            // Create a box sizer for the square panel with margins
            wxBoxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);
            panelSizer->Add(nameLabel, 1, wxEXPAND | wxALL, 5);  // Margins

            // Set the box sizer as the sizer for the panel
            panel->SetSizer(panelSizer);

            return panel;
        }
        User user_;
    };
#endif