iOS: More work on checkbox wiget, fix buttons missing highlight

This commit is contained in:
UnknownShadow200 2022-04-23 09:29:16 +10:00
parent 3fad0c7404
commit 09b043e081
5 changed files with 43 additions and 34 deletions

View File

@ -132,12 +132,21 @@ void LBackend_ButtonDraw(struct LButton* w) {
#define CB_SIZE 24
#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) {
struct DrawTextArgs args;
DrawTextArgs_Make(&args, &w->text, &textFont, true);
w->width = Display_ScaleX(CB_SIZE + CB_OFFSET) + Drawer2D_TextWidth(&args);
w->height = Display_ScaleY(CB_SIZE);
w->width = Display_ScaleX(CB_SIZE + CB_OFFSET) + Drawer2D_TextWidth(&args);
w->height = Display_ScaleY(CB_SIZE);
w->OnClick = LCheckbox_OnClick;
}
/* Based off checkbox from original ClassiCube Launcher */

View File

@ -445,11 +445,8 @@ static void ColoursScreen_KeyDown(struct LScreen* s, int key, cc_bool was) {
}
}
static void ColoursScreen_ToggleBG(void* w) {
struct LCheckbox* cb = (struct LCheckbox*)w;
Launcher_Theme.ClassicBackground = !Launcher_Theme.ClassicBackground;
cb->value = Launcher_Theme.ClassicBackground;
static void ColoursScreen_ToggleBG(struct LCheckbox* w) {
Launcher_Theme.ClassicBackground = w->value;
Launcher_SaveTheme();
Launcher_Redraw();
}
@ -478,8 +475,8 @@ static void ColoursScreen_Init(struct LScreen* s_) {
LButton_Init(&s->btnBack, 80, 35, "Back");
LCheckbox_Init(&s->cbClassic, "Classic style");
s->cbClassic.OnClick = ColoursScreen_ToggleBG;
s->btnBack.OnClick = SwitchToThemes;
s->cbClassic.ValueChanged = ColoursScreen_ToggleBG;
s->btnBack.OnClick = SwitchToThemes;
}
static void ColoursScreen_Show(struct LScreen* s_) {
@ -1502,28 +1499,19 @@ static struct LWidget* settings_classic[] = {
};
#if defined CC_BUILD_MOBILE
static void SettingsScreen_LockOrientation(void* w) {
struct LCheckbox* cb = (struct LCheckbox*)w;
cb->value = !cb->value;
Options_SetBool(OPT_LANDSCAPE_MODE, cb->value);
Window_LockLandscapeOrientation(cb->value);
static void SettingsScreen_LockOrientation(struct LCheckbox* w) {
Options_SetBool(OPT_LANDSCAPE_MODE, w->value);
Window_LockLandscapeOrientation(w->value);
Launcher_Redraw();
}
#else
static void SettingsScreen_AutoClose(void* w) {
struct LCheckbox* cb = (struct LCheckbox*)w;
cb->value = !cb->value;
Options_SetBool(LOPT_AUTO_CLOSE, cb->value);
LWidget_Redraw(cb);
static void SettingsScreen_AutoClose(struct LCheckbox* w) {
Options_SetBool(LOPT_AUTO_CLOSE, w->value);
}
#endif
static void SettingsScreen_ShowEmpty(void* w) {
struct LCheckbox* cb = (struct LCheckbox*)w;
cb->value = !cb->value;
Launcher_ShowEmptyServers = cb->value;
Options_SetBool(LOPT_SHOW_EMPTY, cb->value);
LWidget_Redraw(cb);
static void SettingsScreen_ShowEmpty(struct LCheckbox* w) {
Launcher_ShowEmptyServers = w->value;
Options_SetBool(LOPT_SHOW_EMPTY, w->value);
}
static void SettingsScreen_Init(struct LScreen* s_) {
@ -1541,14 +1529,14 @@ static void SettingsScreen_Init(struct LScreen* s_) {
#if defined CC_BUILD_MOBILE
LCheckbox_Init(&s->cbExtra, "Force landscape");
s->cbExtra.OnClick = SettingsScreen_LockOrientation;
s->cbExtra.ValueChanged = SettingsScreen_LockOrientation;
#else
LCheckbox_Init(&s->cbExtra, "Close this after game starts");
s->cbExtra.OnClick = SettingsScreen_AutoClose;
s->cbExtra.ValueChanged = SettingsScreen_AutoClose;
#endif
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");
s->btnMode.OnClick = SwitchToChooseMode;

View File

@ -106,14 +106,14 @@ static void LButton_DrawHighlight(struct LButton* w, struct Bitmap* bmp, int x,
if (Launcher_Theme.ClassicBackground) {
if (w->hovered) color = activeColor;
Drawer2D_Clear(&Launcher_Framebuffer, color,
Drawer2D_Clear(bmp, color,
x + xBorder2, y + yBorder,
w->width - xBorder4, yBorder);
Drawer2D_Clear(&Launcher_Framebuffer, color,
Drawer2D_Clear(bmp, color,
x + xBorder, y + yBorder2,
xBorder, w->height - yBorder4);
} else if (!w->hovered) {
Drawer2D_Clear(&Launcher_Framebuffer, color,
Drawer2D_Clear(bmp, color,
x + xBorder2, y + yBorder,
w->width - xBorder4, yBorder);
}

View File

@ -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_DrawBackground(struct LButton* w, struct Bitmap* bmp, int x, int y);
struct LCheckbox;
struct LCheckbox {
LWidget_Layout
cc_bool value;
cc_string text;
char _textBuffer[STRING_SIZE];
void (*ValueChanged)(struct LCheckbox* w);
};
CC_NOINLINE void LCheckbox_Init(struct LCheckbox* w, const char* text);

View File

@ -654,6 +654,15 @@ static NSString* cellID = @"CC_Cell";
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 ===
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
//UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
@ -662,7 +671,7 @@ static NSString* cellID = @"CC_Cell";
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);
char descBuffer[128];
@ -742,6 +751,7 @@ void LBackend_ButtonDraw(struct LButton* w) {
*#########################################################################################################################*/
void LBackend_CheckboxInit(struct LCheckbox* w) {
UISwitch* swt = [[UISwitch alloc] init];
[swt addTarget:ui_controller action:@selector(handleValueChanged:) forControlEvents:UIControlEventValueChanged];
AssignView(w, swt);
UpdateWidgetDimensions(w);
@ -781,7 +791,7 @@ void LBackend_InputInit(struct LInput* w, int width) {
fld.backgroundColor = [UIColor whiteColor];
[fld addTarget:ui_controller action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged];
LInput_SetKeyboardType(fld, w->type);
LInput_SetKeyboardType(fld, w->inputType);
LInput_SetPlaceholder(fld, w->hintText);
AssignView(w, fld);