mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 09:06:55 -04:00
iOS: More work on checkbox wiget, fix buttons missing highlight
This commit is contained in:
parent
3fad0c7404
commit
09b043e081
@ -132,12 +132,21 @@ void LBackend_ButtonDraw(struct LButton* w) {
|
|||||||
#define CB_SIZE 24
|
#define CB_SIZE 24
|
||||||
#define CB_OFFSET 8
|
#define CB_OFFSET 8
|
||||||
|
|
||||||
|
static void LCheckbox_OnClick(void* w) {
|
||||||
|
struct LCheckbox* cb = (struct LCheckbox*)w;
|
||||||
|
cb->value = !cb->value;
|
||||||
|
|
||||||
|
LWidget_Redraw(cb);
|
||||||
|
if (cb->ValueChanged) cb->ValueChanged(cb);
|
||||||
|
}
|
||||||
|
|
||||||
void LBackend_CheckboxInit(struct LCheckbox* w) {
|
void LBackend_CheckboxInit(struct LCheckbox* w) {
|
||||||
struct DrawTextArgs args;
|
struct DrawTextArgs args;
|
||||||
DrawTextArgs_Make(&args, &w->text, &textFont, true);
|
DrawTextArgs_Make(&args, &w->text, &textFont, true);
|
||||||
|
|
||||||
w->width = Display_ScaleX(CB_SIZE + CB_OFFSET) + Drawer2D_TextWidth(&args);
|
w->width = Display_ScaleX(CB_SIZE + CB_OFFSET) + Drawer2D_TextWidth(&args);
|
||||||
w->height = Display_ScaleY(CB_SIZE);
|
w->height = Display_ScaleY(CB_SIZE);
|
||||||
|
w->OnClick = LCheckbox_OnClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Based off checkbox from original ClassiCube Launcher */
|
/* Based off checkbox from original ClassiCube Launcher */
|
||||||
|
@ -445,11 +445,8 @@ static void ColoursScreen_KeyDown(struct LScreen* s, int key, cc_bool was) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ColoursScreen_ToggleBG(void* w) {
|
static void ColoursScreen_ToggleBG(struct LCheckbox* w) {
|
||||||
struct LCheckbox* cb = (struct LCheckbox*)w;
|
Launcher_Theme.ClassicBackground = w->value;
|
||||||
Launcher_Theme.ClassicBackground = !Launcher_Theme.ClassicBackground;
|
|
||||||
cb->value = Launcher_Theme.ClassicBackground;
|
|
||||||
|
|
||||||
Launcher_SaveTheme();
|
Launcher_SaveTheme();
|
||||||
Launcher_Redraw();
|
Launcher_Redraw();
|
||||||
}
|
}
|
||||||
@ -478,8 +475,8 @@ static void ColoursScreen_Init(struct LScreen* s_) {
|
|||||||
LButton_Init(&s->btnBack, 80, 35, "Back");
|
LButton_Init(&s->btnBack, 80, 35, "Back");
|
||||||
|
|
||||||
LCheckbox_Init(&s->cbClassic, "Classic style");
|
LCheckbox_Init(&s->cbClassic, "Classic style");
|
||||||
s->cbClassic.OnClick = ColoursScreen_ToggleBG;
|
s->cbClassic.ValueChanged = ColoursScreen_ToggleBG;
|
||||||
s->btnBack.OnClick = SwitchToThemes;
|
s->btnBack.OnClick = SwitchToThemes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ColoursScreen_Show(struct LScreen* s_) {
|
static void ColoursScreen_Show(struct LScreen* s_) {
|
||||||
@ -1502,28 +1499,19 @@ static struct LWidget* settings_classic[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined CC_BUILD_MOBILE
|
#if defined CC_BUILD_MOBILE
|
||||||
static void SettingsScreen_LockOrientation(void* w) {
|
static void SettingsScreen_LockOrientation(struct LCheckbox* w) {
|
||||||
struct LCheckbox* cb = (struct LCheckbox*)w;
|
Options_SetBool(OPT_LANDSCAPE_MODE, w->value);
|
||||||
cb->value = !cb->value;
|
Window_LockLandscapeOrientation(w->value);
|
||||||
Options_SetBool(OPT_LANDSCAPE_MODE, cb->value);
|
|
||||||
Window_LockLandscapeOrientation(cb->value);
|
|
||||||
Launcher_Redraw();
|
Launcher_Redraw();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void SettingsScreen_AutoClose(void* w) {
|
static void SettingsScreen_AutoClose(struct LCheckbox* w) {
|
||||||
struct LCheckbox* cb = (struct LCheckbox*)w;
|
Options_SetBool(LOPT_AUTO_CLOSE, w->value);
|
||||||
cb->value = !cb->value;
|
|
||||||
Options_SetBool(LOPT_AUTO_CLOSE, cb->value);
|
|
||||||
LWidget_Redraw(cb);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
static void SettingsScreen_ShowEmpty(void* w) {
|
static void SettingsScreen_ShowEmpty(struct LCheckbox* w) {
|
||||||
struct LCheckbox* cb = (struct LCheckbox*)w;
|
Launcher_ShowEmptyServers = w->value;
|
||||||
cb->value = !cb->value;
|
Options_SetBool(LOPT_SHOW_EMPTY, w->value);
|
||||||
Launcher_ShowEmptyServers = cb->value;
|
|
||||||
|
|
||||||
Options_SetBool(LOPT_SHOW_EMPTY, cb->value);
|
|
||||||
LWidget_Redraw(cb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SettingsScreen_Init(struct LScreen* s_) {
|
static void SettingsScreen_Init(struct LScreen* s_) {
|
||||||
@ -1541,14 +1529,14 @@ static void SettingsScreen_Init(struct LScreen* s_) {
|
|||||||
|
|
||||||
#if defined CC_BUILD_MOBILE
|
#if defined CC_BUILD_MOBILE
|
||||||
LCheckbox_Init(&s->cbExtra, "Force landscape");
|
LCheckbox_Init(&s->cbExtra, "Force landscape");
|
||||||
s->cbExtra.OnClick = SettingsScreen_LockOrientation;
|
s->cbExtra.ValueChanged = SettingsScreen_LockOrientation;
|
||||||
#else
|
#else
|
||||||
LCheckbox_Init(&s->cbExtra, "Close this after game starts");
|
LCheckbox_Init(&s->cbExtra, "Close this after game starts");
|
||||||
s->cbExtra.OnClick = SettingsScreen_AutoClose;
|
s->cbExtra.ValueChanged = SettingsScreen_AutoClose;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LCheckbox_Init(&s->cbEmpty, "Show empty servers in list");
|
LCheckbox_Init(&s->cbEmpty, "Show empty servers in list");
|
||||||
s->cbEmpty.OnClick = SettingsScreen_ShowEmpty;
|
s->cbEmpty.ValueChanged = SettingsScreen_ShowEmpty;
|
||||||
LButton_Init( &s->btnBack, 80, 35, "Back");
|
LButton_Init( &s->btnBack, 80, 35, "Back");
|
||||||
|
|
||||||
s->btnMode.OnClick = SwitchToChooseMode;
|
s->btnMode.OnClick = SwitchToChooseMode;
|
||||||
|
@ -106,14 +106,14 @@ static void LButton_DrawHighlight(struct LButton* w, struct Bitmap* bmp, int x,
|
|||||||
if (Launcher_Theme.ClassicBackground) {
|
if (Launcher_Theme.ClassicBackground) {
|
||||||
if (w->hovered) color = activeColor;
|
if (w->hovered) color = activeColor;
|
||||||
|
|
||||||
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
Drawer2D_Clear(bmp, color,
|
||||||
x + xBorder2, y + yBorder,
|
x + xBorder2, y + yBorder,
|
||||||
w->width - xBorder4, yBorder);
|
w->width - xBorder4, yBorder);
|
||||||
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
Drawer2D_Clear(bmp, color,
|
||||||
x + xBorder, y + yBorder2,
|
x + xBorder, y + yBorder2,
|
||||||
xBorder, w->height - yBorder4);
|
xBorder, w->height - yBorder4);
|
||||||
} else if (!w->hovered) {
|
} else if (!w->hovered) {
|
||||||
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
Drawer2D_Clear(bmp, color,
|
||||||
x + xBorder2, y + yBorder,
|
x + xBorder2, y + yBorder,
|
||||||
w->width - xBorder4, yBorder);
|
w->width - xBorder4, yBorder);
|
||||||
}
|
}
|
||||||
|
@ -63,11 +63,13 @@ CC_NOINLINE void LButton_Init(struct LButton* w, int width, int height, const ch
|
|||||||
CC_NOINLINE void LButton_SetConst(struct LButton* w, const char* text);
|
CC_NOINLINE void LButton_SetConst(struct LButton* w, const char* text);
|
||||||
CC_NOINLINE void LButton_DrawBackground(struct LButton* w, struct Bitmap* bmp, int x, int y);
|
CC_NOINLINE void LButton_DrawBackground(struct LButton* w, struct Bitmap* bmp, int x, int y);
|
||||||
|
|
||||||
|
struct LCheckbox;
|
||||||
struct LCheckbox {
|
struct LCheckbox {
|
||||||
LWidget_Layout
|
LWidget_Layout
|
||||||
cc_bool value;
|
cc_bool value;
|
||||||
cc_string text;
|
cc_string text;
|
||||||
char _textBuffer[STRING_SIZE];
|
char _textBuffer[STRING_SIZE];
|
||||||
|
void (*ValueChanged)(struct LCheckbox* w);
|
||||||
};
|
};
|
||||||
CC_NOINLINE void LCheckbox_Init(struct LCheckbox* w, const char* text);
|
CC_NOINLINE void LCheckbox_Init(struct LCheckbox* w, const char* text);
|
||||||
|
|
||||||
|
@ -654,6 +654,15 @@ static NSString* cellID = @"CC_Cell";
|
|||||||
if (ipt->TextChanged) ipt->TextChanged(ipt);
|
if (ipt->TextChanged) ipt->TextChanged(ipt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)handleValueChanged:(id)sender {
|
||||||
|
struct LWidget* w = FindWidgetForView(sender);
|
||||||
|
if (w == NULL) return;
|
||||||
|
|
||||||
|
struct LCheckbox* cb = (struct LCheckbox*)w;
|
||||||
|
if (!cb->ValueChanged) return;
|
||||||
|
cb->ValueChanged(cb);
|
||||||
|
}
|
||||||
|
|
||||||
// === UITableViewDataSource ===
|
// === UITableViewDataSource ===
|
||||||
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
|
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
|
||||||
//UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
|
//UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
|
||||||
@ -662,7 +671,7 @@ static NSString* cellID = @"CC_Cell";
|
|||||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ServerInfo* server = Servers_Get([indexPath row]);
|
struct ServerInfo* server = LTable_Get([indexPath row]);
|
||||||
struct Flag* flag = Flags_Get(server);
|
struct Flag* flag = Flags_Get(server);
|
||||||
|
|
||||||
char descBuffer[128];
|
char descBuffer[128];
|
||||||
@ -742,6 +751,7 @@ void LBackend_ButtonDraw(struct LButton* w) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void LBackend_CheckboxInit(struct LCheckbox* w) {
|
void LBackend_CheckboxInit(struct LCheckbox* w) {
|
||||||
UISwitch* swt = [[UISwitch alloc] init];
|
UISwitch* swt = [[UISwitch alloc] init];
|
||||||
|
[swt addTarget:ui_controller action:@selector(handleValueChanged:) forControlEvents:UIControlEventValueChanged];
|
||||||
|
|
||||||
AssignView(w, swt);
|
AssignView(w, swt);
|
||||||
UpdateWidgetDimensions(w);
|
UpdateWidgetDimensions(w);
|
||||||
@ -781,7 +791,7 @@ void LBackend_InputInit(struct LInput* w, int width) {
|
|||||||
fld.backgroundColor = [UIColor whiteColor];
|
fld.backgroundColor = [UIColor whiteColor];
|
||||||
[fld addTarget:ui_controller action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged];
|
[fld addTarget:ui_controller action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged];
|
||||||
|
|
||||||
LInput_SetKeyboardType(fld, w->type);
|
LInput_SetKeyboardType(fld, w->inputType);
|
||||||
LInput_SetPlaceholder(fld, w->hintText);
|
LInput_SetPlaceholder(fld, w->hintText);
|
||||||
|
|
||||||
AssignView(w, fld);
|
AssignView(w, fld);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user