Jump to content
This Topic

In Widget Tab key press not gets in KeyDown


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

If i press Tab it will be registered in KeyUp, but not in KeyDown

#include "UltraEngine.h"

using namespace UltraEngine;

class CustomWidget : public Panel {

    CustomWidget::CustomWidget() {
        cornerradius = 8;
    }

protected:

    virtual bool Initialize(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent) {
        return Widget::Initialize(text, x, y, width, height, parent, style);
    }


    void KeyUp(const KeyCode key) override {
        if (key == KEY_TAB)
            Print("TAB UP");
    }
    bool KeyDown(const KeyCode key) override {
        if (key == KEY_TAB)
            Print("TAB DOWN");
        return true;
    }

public:


    static shared_ptr<CustomWidget> create(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent) {
        struct Struct : public CustomWidget {
        };
        auto instance = std::make_shared<Struct>();
        instance->Initialize(x, y, width, height, parent);
        return instance;
    }

};

shared_ptr<Window> window;
shared_ptr<Framebuffer> framebuffer;
shared_ptr<World> menuWold;
shared_ptr<Interface> ui;
shared_ptr<Camera> uiCamera;

shared_ptr<CustomWidget> customWidget;

void initGui() {
    auto default_font = LoadFont("Fonts\\arial.ttf");
    ui = CreateInterface(menuWold, default_font, framebuffer->GetSize());
    ui->SetRenderLayers(2);
    ui->root->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
    uiCamera = CreateCamera(menuWold, PROJECTION_ORTHOGRAPHIC);
    uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0);
    uiCamera->SetRenderLayers(2);
    uiCamera->SetClearMode(CLEAR_DEPTH);
    customWidget = CustomWidget::create(10, 10, 500, 120, ui->root);
}


int main(int argc, const char* argv[]) {
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    window = CreateWindow("Ultra Engine", 0, 0, 500, 300, displays[0], WINDOW_DEFAULT);

    //Create a world
    menuWold = CreateWorld();

    //Create a framebuffer
    framebuffer = CreateFramebuffer(window);

    initGui();

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) {
        const auto event = WaitEvent();
        ui->ProcessEvent(event);
        menuWold->Update();
        menuWold->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

The reason for this is that tab switches the focus to the next widget, but for an editable text area, I can understand why that would not be desired.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 2 weeks later...
  • Solution

I am adding a protected method to handle this:

bool Widget::KeyFilter(const KeyCode key)
{
	switch (key)
	{
	case KEY_ESCAPE:
	case KEY_ENTER:
	case KEY_TAB:
		return false;
		break;
	}
	return true;
}

You can override this to return true if KEY_TAB or KEY_ENTER are encountered.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 2 weeks later...

Sorry, checked only now. Does not work for me:

#include "Leadwerks.h"

using namespace UltraEngine;

class CustomWidget : public Panel {

    CustomWidget::CustomWidget() {
        cornerradius = 8;
    }

protected:

    virtual bool Initialize(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent) {
        return Widget::Initialize(text, x, y, width, height, parent, style);
    }

    void KeyUp(const KeyCode key) override {
        if (key == KEY_TAB)
            Print("TAB UP");
    }
    bool KeyDown(const KeyCode key) override {
        if (key == KEY_TAB)
            Print("TAB DOWN");
        return true;
    }
    bool KeyFilter(const KeyCode key) override {
        switch (key) {
        case KEY_ESCAPE:
        case KEY_ENTER:
        case KEY_TAB:
            return true;
            break;
        }
        return true;
    }

public:

    static shared_ptr<CustomWidget> create(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent) {
        struct Struct : public CustomWidget {
        };
        auto instance = std::make_shared<Struct>();
        instance->Initialize(x, y, width, height, parent);
        return instance;
    }

};

shared_ptr<Window> window;
shared_ptr<Framebuffer> framebuffer;
shared_ptr<World> menuWold;
shared_ptr<Interface> ui;
shared_ptr<Camera> uiCamera;

shared_ptr<CustomWidget> customWidget;

void initGui() {
    auto default_font = LoadFont("Fonts\\arial.ttf");
    uiCamera = CreateCamera(menuWold, PROJECTION_ORTHOGRAPHIC);
    uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0);
    uiCamera->SetRenderLayers(2);
    uiCamera->SetClearMode(CLEAR_DEPTH);
    ui = CreateInterface(uiCamera, default_font, framebuffer->GetSize());
    ui->SetRenderLayers(2);
    ui->root->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
    customWidget = CustomWidget::create(10, 10, 500, 120, ui->root);
}


int main(int argc, const char* argv[]) {
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    window = CreateWindow("Ultra Engine", 0, 0, 500, 300, displays[0], WINDOW_DEFAULT);

    //Create a world
    menuWold = CreateWorld();

    //Create a framebuffer
    framebuffer = CreateFramebuffer(window);

    initGui();

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) {
        const auto event = WaitEvent();
        ui->ProcessEvent(event);
        menuWold->Update();
        menuWold->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...