Saturday, December 16th 2017, 4:32am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

gregk

Beginner

Date of registration: Mar 24th 2014

Posts: 2

1

Friday, March 28th 2014, 7:05pm

Custom Widget with child widgets

I am trying to create a custom widget for use within a dialog that has child widgets. The child widgets do not seem to be working, I am rather new to using emwin - am I doing something completely wrong?

Widget C File:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdlib.h>
#include <string.h>
#include "WIDGET.h"
#include "dialog.h"
#include "utility.h"

#define ID_BUTTON_1    (GUI_ID_USER + 0x200)

typedef WM_HMEM MYWIDGET_Handle;

/*********************************************************************
*
* MYWIDGET_Obj
*/
typedef struct {
  BUTTON_Handle hButton1;
  int NumExtraBytes;
} MYWIDGET_Obj;

const MYWIDGET_Obj MYWIDGET_Default = {
0,
0
};
static void MyWidget_Callback(WM_MESSAGE * pMsg)
{
  switch (pMsg->MsgId) {
  default:
    WINDOW_Callback(pMsg);
  }
}

static void MyWidgetButton_Callback(WM_MESSAGE * pMsg)
{
  switch (pMsg->MsgId) {
  default:
    BUTTON_Callback(pMsg);
  }
}

MYWIDGET_Handle MyWidget_CreateIndirect(const GUI_WIDGET_CREATE_INFO *pCreateInfo,
  WM_HWIN hParent, int x0, int y0, WM_CALLBACK *cb)
{
  WM_HWIN hWin;
  MYWIDGET_Obj MyWidget;
  GUI_WIDGET_CREATE_INFO CreateInfo = *pCreateInfo;
  GUI_WIDGET_CREATE_INFO ButtonCreateInfo = {0};

  MyWidget = MYWIDGET_Default;
  MyWidget.NumExtraBytes = pCreateInfo->NumExtraBytes;
  
  CreateInfo.NumExtraBytes = pCreateInfo->NumExtraBytes + sizeof(MYWIDGET_Obj);
  hWin = WINDOW_CreateIndirect(&CreateInfo, hParent, 0, 0, 0);

  WINDOW_SetBkColor(hWin, 0x00d2b996);

  ButtonCreateInfo.pName = "Button 1";
  ButtonCreateInfo.Id = ID_BUTTON_1;
  
  ButtonCreateInfo.x0 = 0;
  ButtonCreateInfo.y0 = 0;
  ButtonCreateInfo.xSize = 30;
  ButtonCreateInfo.ySize = 30;
  
  MyWidget.hButton1 = BUTTON_CreateIndirect(&ButtonCreateInfo, hWin, 0, 0, 0);
  WM_SetCallback(hWin, MyWidget_Callback);
  WM_SetCallback(MyWidget.hButton1, MyWidgetButton_Callback);
  WM_SetUserData(hWin, &MyWidget, sizeof(MYWIDGET_Obj));
  return hWin;
}


Dialog that uses custom widget:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "DIALOG.h"

typedef WM_HMEM MYWIDGET_Handle;

MYWIDGET_Handle MyWidget_CreateIndirect(const GUI_WIDGET_CREATE_INFO *pCreateInfo,
  WM_HWIN hParent, int x0, int y0, WM_CALLBACK *cb);

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_MY_WIDGET_0  (GUI_ID_USER + 0x30)

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/


/*********************************************************************
*
*       _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { WINDOW_CreateIndirect, "Widget Test", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
  { MyWidget_CreateIndirect, "", ID_MY_WIDGET_0, 100, 100, 130, 37, 0, 0, 0 },
};

/*********************************************************************
*
*       _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateTestDLG
*/
WM_HWIN CreateTestDLG(void);
WM_HWIN CreateTestDLG(void) {
  WM_HWIN hWin;

  hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  return hWin;
}

/*************************** End of file ****************************/


Thanks.

SEGGER - Adrian

Super Moderator

Date of registration: May 26th 2009

Posts: 994

2

Monday, March 31st 2014, 10:17am

Hello,

Please note that the possibility to create a custom widget type is intended for experienced users. In any case if you require a widget which actually does nothing but having a BUTTON widget as child, you can just use a simple window (WM_CreateWindow()).

Best regards,
Adrian

gregk

Beginner

Date of registration: Mar 24th 2014

Posts: 2

3

Monday, March 31st 2014, 10:40pm

No I do not intend to have a widget that does nothing but have a button as I child :) I have simplified the widget for the sake of illustrating the problem. Is there a reason a button cannot be a child of a window as in the code example?

Part of my confusion lies with <WIDGET>_CreateIndirect() - this is apparently needed for a widget in a dialog, but is not documented in AN03002. Is there a problem with the implementation of the <WIDGET>_CreateIndirect() function in the code example?


Thanks again.

SEGGER - Adrian

Super Moderator

Date of registration: May 26th 2009

Posts: 994

4

Tuesday, April 1st 2014, 9:35am

Hello,

Of course a BUTTON widget can be a child of a custom widget. I see that the way to implement a CreateIndirect() function for custom widgets is currently not explained. We will add an explanation for that in a future emWin version. For now I would recommend creating the custom widget in the dialog procedure as a reaction to the message WM_INIT_DIALOG.

Best regards,
Adrian

bsampson

Beginner

Date of registration: Dec 17th 2014

Posts: 3

5

Wednesday, December 17th 2014, 5:23pm

Any updates?

Are there any updates to this yet? I am also interested in learning how to create a custom widget's customwidget_createindirect function.

SEGGER - Adrian

Super Moderator

Date of registration: May 26th 2009

Posts: 994

6

Thursday, December 18th 2014, 9:28am

Hello,

I am afraid we currently do not have an example for a create indirect function.

Best regards,
Adrian

Similar threads