Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You ask a lot of questions, but none of them are sincere.. Especially since you finish it off with a dogmatic "Use them!". How about keeping an open mind, asking real questions, and give others the chance to prove you wrong (which would be beneficial to you if they succeed)?

IMO you're so stuck in the OOP mindset, that you cannot see the very simple solutions to your questions. To just pick a single example out of the many, since you don't seem to want to be proven wrong anyway..

Where do you store and how do you access all the hidden state, like keyboard focus, cursor position, editing modes, etc, that object oriented user interfaces simply expose as properties, getters or setters?

In OOP each single widget would store whether it is focused using some boolean member. In IM GUIs one just stores the ID of the widget that is focused once in some library-local data structure:

    // ui.h
    bool has_keyboard_focus(uint64_t widget_id);


    // ui.cpp
    struct UIData {
        uint64_t focused_widget_id;
        int16_t cursor_x, cursor_y;
    } ui_data;

    bool has_keyboard_focus(uint64_t widget_id) { return ui_data.focused_widget_id == widget_id; }

    // my_widget.h
    EditMode my_widget_get_edit_mode(uint64_t widget_id);

    // my_widget.cpp
    map<uint64_t /*widget_id*/, EditMode> widget_id_to_edit_mode;
    option<EditMode> my_widget_get_edit_mode(uint64_t widget_id) {
        auto itr = widget_id_to_edit_mode.find(widget_id);
        return itr != widget_id_to_edit_mode.end() ? itr->second : std::nullopt;
    }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: