Repositioning the window #263
-
Hi, I looking at the code, I assumed that setting "left" and "top" properties of the root widget should move the window, but after some print statements in if (Widget_CheckStyleValid(widget, key_top) &&
Widget_CheckStyleValid(widget, key_left)) { doesn't evaluate to true, even though I've changed the code in int main(int argc, char **argv)
{
LCUI_Widget root, pack, btn;
LCUI_Init();
root = LCUIWidget_GetRoot();
pack = LCUIBuilder_LoadFile("helloworld.xml");
if (!pack) {
return -1;
}
Widget_SetStyleString(root, "top", "100px");
Widget_SetStyleString(root, "left", "100px");
Widget_SetStyleString(root, "width", "100px");
Widget_SetStyleString(root, "height", "100px");
Widget_Append(root, pack);
Widget_Unwrap(pack);
btn = LCUIWidget_GetById("btn");
Widget_BindEvent(btn, "click", OnBtnClick, NULL, NULL);
return LCUI_Main();
} Is there a different function I'm supposed to use? I'm sorry if It's documented somewhere and I couldn't find it |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
So it seems that |
Beta Was this translation helpful? Give feedback.
-
Ended up doing a bit of a hacky workaround, to move the window after it's been resized once, I'll move it and then ignore the remaining events. #include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include <LCUI/gui/widget.h>
#include <LCUI/gui/builder.h>
#include <LCUI/gui/widget/textview.h>
#include <LCUI/gui/widget/textedit.h>
#include <stdio.h>
#include <LCUI/display.h>
static void OnBtnClick(LCUI_Widget self, LCUI_WidgetEvent e, void *arg)
{
wchar_t str[256];
LCUI_Widget edit = LCUIWidget_GetById("edit");
LCUI_Widget txt = LCUIWidget_GetById("text-hello");
TextEdit_GetTextW(edit, 0, 255, str);
TextView_SetTextW(txt, str);
}
// Only care to run this once, so after resize is updated
// we'll never move again
static void OnReady(LCUI_Event e, void *arg) {
int* moved = (int *) e->data;
if (*moved == 1) {
return;
}
*moved = 1;
LCUI_Widget root = LCUIWidget_GetRoot();
Surface_Move(LCUIDisplay_GetSurfaceOwner(root), 0, 0);
}
int main(int argc, char **argv)
{
LCUI_Widget root, pack, btn;
LCUI_Init();
root = LCUIWidget_GetRoot();
pack = LCUIBuilder_LoadFile("helloworld.xml");
if (!pack) {
return -1;
}
Widget_AddClass(root, "test_class");
Widget_SetStyleString(root, "width", "100px");
Widget_SetStyleString(root, "height", "100px");
Widget_Append(root, pack);
Widget_Unwrap(pack);
btn = LCUIWidget_GetById("btn");
Widget_BindEvent(btn, "click", OnBtnClick, NULL, NULL);
// SelectionClear
int moved = 0;
LCUIDisplay_BindEvent(LCUI_DEVENT_RESIZE, OnReady, NULL, &moved, NULL);
return LCUI_Main();
} |
Beta Was this translation helpful? Give feedback.
Ended up doing a bit of a hacky workaround, to move the window after it's been resized once, I'll move it and then ignore the remaining events.