Skip to content

Commit

Permalink
Merge pull request #141 from ProtonMail/ui-form-delete
Browse files Browse the repository at this point in the history
Adds uiFormDelete()
  • Loading branch information
andlabs authored Jun 15, 2016
2 parents e017c22 + 831fe1e commit ac1a515
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
32 changes: 30 additions & 2 deletions darwin/form.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (void)syncEnableStates:(int)enabled;
- (CGFloat)paddingAmount;
- (void)establishOurConstraints;
- (void)append:(NSString *)label c:(uiControl *)c stretchy:(int)stretchy;
//TODO- (void)delete:(int)n;
- (void)delete:(int)n;
- (int)isPadded;
- (void)setPadded:(int)p;
- (BOOL)hugsTrailing;
Expand Down Expand Up @@ -394,7 +394,30 @@ - (void)append:(NSString *)label c:(uiControl *)c stretchy:(int)stretchy
[fc release]; // we don't need the initial reference now
}

//TODO- (void)delete:(int)n
- (void)delete:(int)n
{
formChild *fc;
int stretchy;

fc = (formChild *) [self->children objectAtIndex:n];
stretchy = fc.stretchy;

uiControlSetParent(fc.c, NULL);
uiDarwinControlSetSuperview(uiDarwinControl(fc.c), nil);

uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), fc.oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal);
uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), fc.oldVertHuggingPri, NSLayoutConstraintOrientationVertical);

[fc.label removeFromSuperview];

[self->children removeObjectAtIndex:n];

[self establishOurConstraints];
if (stretchy) {
if ([self nStretchy] == 0)
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f));
}
}

- (int)isPadded
{
Expand Down Expand Up @@ -513,6 +536,11 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)
[f->view append:toNSString(label) c:c stretchy:stretchy];
}

void uiFormDelete(uiForm *f, int n)
{
[f->view delete:n];
}

int uiFormPadded(uiForm *f)
{
return [f->view isPadded];
Expand Down
1 change: 1 addition & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ _UI_EXTERN uiColorButton *uiNewColorButton(void);
typedef struct uiForm uiForm;
#define uiForm(this) ((uiForm *) (this))
_UI_EXTERN void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy);
_UI_EXTERN void uiFormDelete(uiForm *f, int index);
_UI_EXTERN int uiFormPadded(uiForm *f);
_UI_EXTERN void uiFormSetPadded(uiForm *f, int padded);
_UI_EXTERN uiForm *uiNewForm(void);
Expand Down
25 changes: 25 additions & 0 deletions unix/form.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

struct formChild {
uiControl *c;
int stretchy;
GtkWidget *label;
gboolean oldhexpand;
GtkAlign oldhalign;
Expand Down Expand Up @@ -55,6 +56,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)

fc.c = c;
widget = GTK_WIDGET(uiControlHandle(fc.c));
fc.stretchy = stretchy;
fc.oldhexpand = gtk_widget_get_hexpand(widget);
fc.oldhalign = gtk_widget_get_halign(widget);
fc.oldvexpand = gtk_widget_get_vexpand(widget);
Expand Down Expand Up @@ -99,6 +101,29 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)
NULL);
}

void uiFormDelete(uiForm *f, int index)
{
struct formChild *fc;
GtkWidget *widget;

fc = ctrl(f, index);
widget = GTK_WIDGET(uiControlHandle(fc->c));

gtk_widget_destroy(fc->label);

uiControlSetParent(fc->c, NULL);
uiUnixControlSetContainer(uiUnixControl(fc->c), f->container, TRUE);

if (fc->stretchy)
gtk_size_group_remove_widget(f->stretchygroup, widget);
gtk_widget_set_hexpand(widget, fc->oldhexpand);
gtk_widget_set_halign(widget, fc->oldhalign);
gtk_widget_set_vexpand(widget, fc->oldvexpand);
gtk_widget_set_valign(widget, fc->oldvalign);

g_array_remove_index(f->children, index);
}

int uiFormPadded(uiForm *f)
{
return f->padded;
Expand Down
12 changes: 12 additions & 0 deletions windows/form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)
uiWindowsControlMinimumSizeChanged(uiWindowsControl(f));
}

void uiFormDelete(uiForm *f, int index)
{
uiControl *c;

c = (*(f->controls))[index].c;
uiControlSetParent(c, NULL);
uiWindowsControlSetParentHWND(uiWindowsControl(c), NULL);
f->controls->erase(f->controls->begin() + index);
formArrangeChildren(f);
uiWindowsControlMinimumSizeChanged(uiWindowsControl(f));
}

int uiFormPadded(uiForm *f)
{
return f->padded;
Expand Down

0 comments on commit ac1a515

Please # to comment.