added split view (Cocoa)

Fri, 13 Jun 2014 10:39:54 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 13 Jun 2014 10:39:54 +0200
changeset 51
42506e19eb6b
parent 50
22b5adeb371f
child 52
25e5390cce41

added split view (Cocoa)

application/main.c file | annotate | diff | comparison | revisions
ui/cocoa/container.h file | annotate | diff | comparison | revisions
ui/cocoa/container.m file | annotate | diff | comparison | revisions
--- a/application/main.c	Sat May 31 11:08:34 2014 +0200
+++ b/application/main.c	Fri Jun 13 10:39:54 2014 +0200
@@ -109,8 +109,10 @@
     ui_list_append(list, p3);
     ui_list_append(list, p4);
     
+    ui_sidebar(window);
     ui_table(window, list, model);
-    //ui_textarea(window, NULL);
+    ui_end(window);
+    ui_textarea(window, NULL);
     
     ui_show(window);
     ui_main();
--- a/ui/cocoa/container.h	Sat May 31 11:08:34 2014 +0200
+++ b/ui/cocoa/container.h	Fri Jun 13 10:39:54 2014 +0200
@@ -38,5 +38,7 @@
 };
 
 UiContainer* ui_window_container(UiObject *obj, NSWindow *window);
-void   ui_window_container_add(UiContainer *ct, NSView *view);
-NSRect ui_window_container_getframe(UiContainer *ct);
+
+NSRect ui_container_getframe(UiContainer *ct);
+void ui_container_add(UiContainer *ct, NSView *view);
+
--- a/ui/cocoa/container.m	Sat May 31 11:08:34 2014 +0200
+++ b/ui/cocoa/container.m	Fri Jun 13 10:39:54 2014 +0200
@@ -36,17 +36,71 @@
     UiContainer *ct = ucx_mempool_malloc(
                                          obj->ctx->mempool,
                                          sizeof(UiContainer));
-    ct->widget = (NSView*)window;
-    ct->add = ui_window_container_add;
-    ct->getframe = ui_window_container_getframe;
+    ct->widget = [window contentView];
+    ct->add = ui_container_add;
+    ct->getframe = ui_container_getframe;
     return ct;
 }
 
-void ui_window_container_add(UiContainer *ct, NSView *view) {
-    NSWindow *window = (NSWindow*)ct->widget;
-    [window setContentView:view];
+UIWIDGET ui_sidebar(UiObject *obj) {
+    UiContainer *ct = uic_get_current_container(obj);
+    NSRect frame = ct->getframe(ct);
+    
+    // create and add views
+    NSSplitView *splitview = [[NSSplitView alloc] initWithFrame:frame];
+    [splitview setVertical:YES];
+    [splitview setDividerStyle:NSSplitViewDividerStyleThin];
+    ct->add(ct, splitview);
+    
+    NSRect lframe;
+    lframe.origin.x = 0;
+    lframe.origin.y = 0;
+    lframe.size.width = 200;
+    lframe.size.height = frame.size.height;
+    
+    NSRect rframe;
+    rframe.origin.x = 0;
+    rframe.origin.y = 0;
+    rframe.size.width = frame.size.width - 201;
+    rframe.size.height = frame.size.height;
+    
+    NSView *sidebar = [[NSView alloc]initWithFrame:lframe];
+    NSView *contentarea = [[NSView alloc]initWithFrame:rframe];
+    
+    [splitview addSubview:sidebar];
+    [splitview addSubview:contentarea];
+    
+    // add ui objects for the sidebar and contentarea
+    // the sidebar is added last, so that new views are added first to it
+    UiObject *left = uic_object_new(obj, sidebar);
+    UiContainer *ct1 = ucx_mempool_malloc(
+            obj->ctx->mempool,
+            sizeof(UiContainer));
+    ct1->widget = sidebar;
+    ct1->add = ui_container_add;
+    ct1->getframe = ui_container_getframe;
+    left->container = ct1;
+    
+    UiObject *right = uic_object_new(obj, sidebar);
+    UiContainer *ct2 = ucx_mempool_malloc(
+            obj->ctx->mempool,
+            sizeof(UiContainer));
+    ct2->widget = contentarea;
+    ct2->add = ui_container_add;
+    ct2->getframe = ui_container_getframe;
+    right->container = ct2;
+    
+    uic_obj_add(obj, right);
+    uic_obj_add(obj, left);
+    
+    return splitview;
 }
 
-NSRect ui_window_container_getframe(UiContainer *ct) {
+
+NSRect ui_container_getframe(UiContainer *ct) {
     return [ct->widget frame];
 }
+
+void ui_container_add(UiContainer *ct, NSView *view) {
+    [ct->widget addSubview: view];
+}

mercurial