Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opinionated class based component approach #26

Open
mediocre9 opened this issue Jun 16, 2023 · 0 comments
Open

Opinionated class based component approach #26

mediocre9 opened this issue Jun 16, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@mediocre9
Copy link
Owner

mediocre9 commented Jun 16, 2023

Class based component pattern to build the app.

Proposed Design Architectural Style

class RootComponent : public IApplicationController {
public:
    // construct window application from here .  .  .
    RootComponent() : 
    IApplicationController("My First App", Dimension(500, 500), eng::Color.AQUA_BLACK), 
    v_menu_(nullptr), frame_(nullptr) {
        v_menu_ = new VerticalMenu();
        frame_ = new Frame();
    }
    
    // setup gui object values .  .  . 
    void setup() override {
        // for menu
        items_ = {
            {" New   ", HIGHLIGHT},
            {" File  ", DEFAULT},
            {" Edit  ", DEFAULT},
            {" View  ", DEFAULT},
        };

        v_menu_->addItems(items_);
        v_menu_->setTheme({DEFAULT, HIGHLIGHT});
        v_menu_->setPosition({0, 0});

        // for window frame
        frame_->setDimension({10, 25});
        frame_->setPosition({1, 3});
        frame_->enableShadow(true);
        frame_->setBorderType(AbstractWindow::Border::PIPE);
    }

    // update callback method . . .
    void controller() override {
        while (!v_menu_->isItemSelected()) {
            v_menu_->render();
        }

        v_menu_->restart();

        switch (v_menu_->getItemPosition()) {
        case 1:
            frame_->render();
            break;
        }
    }

    ~RootComponent() {
        delete v_menu_;
        delete frame_;
    }

private:
    std::vector<MenuItem> items_;
    Window* frame_;
    MenuBar* v_menu_;
};

int main() {
    RootComponent root;
    root.init(std::bind(&RootComponent::controller, &root));
    return 0;
}
@mediocre9 mediocre9 added the enhancement New feature or request label Jun 16, 2023
@mediocre9 mediocre9 self-assigned this Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant