mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
ios: WIP on native table widget
This commit is contained in:
parent
952f8fa268
commit
aa793891cc
@ -537,6 +537,9 @@ void LBackend_SliderDraw(struct LSlider* w) {
|
||||
/*########################################################################################################################*
|
||||
*-------------------------------------------------------TableWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void LBackend_TableInit(struct LTable* w) { }
|
||||
void LBackend_TableUpdate(struct LTable* w) { }
|
||||
|
||||
void LBackend_TableReposition(struct LTable* w) {
|
||||
int rowsHeight;
|
||||
w->hdrHeight = Drawer2D_FontHeight(&Launcher_TextFont, true) + hdrYPadding;
|
||||
|
@ -46,6 +46,8 @@ void LBackend_SliderInit(struct LSlider* w, int width, int height);
|
||||
void LBackend_SliderUpdate(struct LSlider* w);
|
||||
void LBackend_SliderDraw(struct LSlider* w);
|
||||
|
||||
void LBackend_TableInit(struct LTable* w);
|
||||
void LBackend_TableUpdate(struct LTable* w);
|
||||
void LBackend_TableDraw(struct LTable* w);
|
||||
void LBackend_TableReposition(struct LTable* w);
|
||||
|
||||
|
@ -1236,9 +1236,7 @@ static void FetchResourcesScreen_UpdateProgress(struct FetchResourcesScreen* s)
|
||||
/* making request still, haven't started download yet */
|
||||
if (progress < 0 || progress > 100) return;
|
||||
|
||||
if (progress == s->sdrProgress.value) return;
|
||||
s->sdrProgress.value = progress;
|
||||
LWidget_Draw(&s->sdrProgress);
|
||||
LSlider_SetProgress(&s->sdrProgress, progress);
|
||||
}
|
||||
|
||||
static void FetchResourcesScreen_Error(struct FetchResourcesScreen* s) {
|
||||
|
@ -487,17 +487,7 @@ static int PlayersColumn_Sort(const struct ServerInfo* a, const struct ServerInf
|
||||
}
|
||||
|
||||
static void UptimeColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, struct LTableCell* cell) {
|
||||
int uptime = row->uptime;
|
||||
char unit = 's';
|
||||
|
||||
if (uptime >= SECS_PER_DAY * 7) {
|
||||
uptime /= SECS_PER_DAY; unit = 'd';
|
||||
} else if (uptime >= SECS_PER_HOUR) {
|
||||
uptime /= SECS_PER_HOUR; unit = 'h';
|
||||
} else if (uptime >= SECS_PER_MIN) {
|
||||
uptime /= SECS_PER_MIN; unit = 'm';
|
||||
}
|
||||
String_Format2(&args->text, "%i%r", &uptime, &unit);
|
||||
LTable_FormatUptime(&args->text, row->uptime);
|
||||
}
|
||||
static int UptimeColumn_Sort(const struct ServerInfo* a, const struct ServerInfo* b) {
|
||||
return b->uptime - a->uptime;
|
||||
@ -513,7 +503,7 @@ static int SoftwareColumn_Sort(const struct ServerInfo* a, const struct ServerIn
|
||||
return String_Compare(&b->software, &a->software);
|
||||
}
|
||||
|
||||
static struct LTableColumn tableColumns[5] = {
|
||||
static struct LTableColumn tableColumns[] = {
|
||||
{ "", 15, FlagColumn_Draw, NULL, false, false },
|
||||
{ "Name", 328, NameColumn_Draw, NameColumn_Sort, true, true },
|
||||
{ "Players", 73, PlayersColumn_Draw, PlayersColumn_Sort, true, true },
|
||||
@ -522,6 +512,19 @@ static struct LTableColumn tableColumns[5] = {
|
||||
};
|
||||
|
||||
|
||||
void LTable_FormatUptime(cc_string* dst, int uptime) {
|
||||
char unit = 's';
|
||||
|
||||
if (uptime >= SECS_PER_DAY * 7) {
|
||||
uptime /= SECS_PER_DAY; unit = 'd';
|
||||
} else if (uptime >= SECS_PER_HOUR) {
|
||||
uptime /= SECS_PER_HOUR; unit = 'h';
|
||||
} else if (uptime >= SECS_PER_MIN) {
|
||||
uptime /= SECS_PER_MIN; unit = 'm';
|
||||
}
|
||||
String_Format2(dst, "%i%r", &uptime, &unit);
|
||||
}
|
||||
|
||||
void LTable_GetScrollbarCoords(struct LTable* w, int* y, int* height) {
|
||||
float scale;
|
||||
if (!w->rowsCount) { *y = 0; *height = 0; return; }
|
||||
@ -633,6 +636,7 @@ void LTable_Init(struct LTable* w, struct FontDesc* rowFont) {
|
||||
for (i = 0; i < w->numColumns; i++) {
|
||||
w->columns[i].width = Display_ScaleX(w->columns[i].width);
|
||||
}
|
||||
LBackend_TableInit(w);
|
||||
}
|
||||
|
||||
void LTable_Reset(struct LTable* w) {
|
||||
@ -667,6 +671,7 @@ void LTable_ApplyFilter(struct LTable* w) {
|
||||
|
||||
w->_lastRow = -1;
|
||||
LTable_ClampTopRow(w);
|
||||
LBackend_TableUpdate(w);
|
||||
}
|
||||
|
||||
static int sortingCol;
|
||||
|
@ -212,6 +212,7 @@ void LTable_Sort(struct LTable* table);
|
||||
/* If selected row is not visible, adjusts top row so it does show. */
|
||||
void LTable_ShowSelected(struct LTable* table);
|
||||
|
||||
void LTable_FormatUptime(cc_string* dst, int uptime);
|
||||
/* Works out top and height of the scrollbar */
|
||||
void LTable_GetScrollbarCoords(struct LTable* w, int* y, int* height);
|
||||
/* Ensures top/first visible row index lies within table */
|
||||
|
@ -91,7 +91,7 @@ static CC_NOINLINE void InitFramebuffer(void) {
|
||||
static cc_uint64 lastJoin;
|
||||
cc_bool Launcher_StartGame(const cc_string* user, const cc_string* mppass, const cc_string* ip, const cc_string* port, const cc_string* server) {
|
||||
cc_string args[4]; int numArgs;
|
||||
TimeMS now;
|
||||
cc_uint64 now;
|
||||
cc_result res;
|
||||
|
||||
now = Stopwatch_Measure();
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "LBackend.h"
|
||||
#include "LWidgets.h"
|
||||
#include "LScreens.h"
|
||||
#include "LWeb.h"
|
||||
#include <mach-o/dyld.h>
|
||||
#include <sys/stat.h>
|
||||
#include <UIKit/UIPasteboard.h>
|
||||
@ -73,19 +74,6 @@ static void RemoveTouch(UITouch* t) {
|
||||
}
|
||||
|
||||
- (BOOL)isOpaque { return YES; }
|
||||
|
||||
// helpers for LBackend
|
||||
static void LBackend_HandleButton(id btn);
|
||||
static void LBackend_HandleInput(id ipt);
|
||||
|
||||
- (void)handleButtonPress:(id)sender {
|
||||
LBackend_HandleButton(sender);
|
||||
}
|
||||
|
||||
- (void)handleTextChanged:(id)sender {
|
||||
LBackend_HandleInput(sender);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static cc_bool landscape_locked;
|
||||
@ -95,6 +83,10 @@ static cc_bool landscape_locked;
|
||||
return UIInterfaceOrientationMaskLandscape;
|
||||
return [super supportedInterfaceOrientations];
|
||||
}
|
||||
|
||||
/*- (BOOL)prefersStatusBarHidden {
|
||||
|
||||
}*/
|
||||
@end
|
||||
|
||||
@implementation CCAppDelegate
|
||||
@ -308,7 +300,7 @@ void Window_DrawFramebuffer(Rect2D r) {
|
||||
rect.origin.y = WindowInfo.Height - r.Y - r.Height;
|
||||
rect.size.width = r.Width;
|
||||
rect.size.height = r.Height;
|
||||
win_handle.layer.contents = CFBridgingRelease(CGBitmapContextCreateImage(win_ctx));
|
||||
view_handle.layer.contents = CFBridgingRelease(CGBitmapContextCreateImage(win_ctx));
|
||||
// TODO always redraws entire launcher which is quite terrible performance wise
|
||||
//[win_handle setNeedsDisplayInRect:rect];
|
||||
}
|
||||
@ -556,9 +548,6 @@ static UIImage* ToUIImage(struct Bitmap* bmp) {
|
||||
return img;
|
||||
}
|
||||
|
||||
void LBackend_Init(void) {
|
||||
}
|
||||
|
||||
static void UpdateWidgetDimensions(void* widget) {
|
||||
struct LWidget* w = widget;
|
||||
UIView* view = (__bridge UIView*)w->meta;
|
||||
@ -618,22 +607,73 @@ static struct LWidget* FindWidgetForView(id obj) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void LBackend_HandleButton(id btn_obj) {
|
||||
struct LWidget* w = FindWidgetForView(btn_obj);
|
||||
static NSString* cellID = @"CC_Cell";
|
||||
@interface CCUIController : NSObject<UITableViewDataSource>
|
||||
@end
|
||||
|
||||
@implementation CCUIController
|
||||
|
||||
- (void)handleButtonPress:(id)sender {
|
||||
struct LWidget* w = FindWidgetForView(sender);
|
||||
if (w == NULL) return;
|
||||
|
||||
|
||||
struct LButton* btn = (struct LButton*)w;
|
||||
btn->OnClick(btn);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
- (void)handleTextChanged:(id)sender {
|
||||
struct LWidget* w = FindWidgetForView(sender);
|
||||
if (w == NULL) return;
|
||||
|
||||
UITextField* src = (UITextField*)sender;
|
||||
const char* str = [[src text] UTF8String];
|
||||
|
||||
struct LInput* ipt = (struct LInput*)w;
|
||||
ipt->text.length = 0;
|
||||
String_AppendUtf8(&ipt->text, str, String_Length(str));
|
||||
if (ipt->TextChanged) ipt->TextChanged(ipt);
|
||||
}
|
||||
|
||||
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
|
||||
//UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
|
||||
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellID];
|
||||
if (cell == nil) {
|
||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
|
||||
}
|
||||
|
||||
struct ServerInfo* server = Servers_Get([indexPath row]);
|
||||
char descBuffer[128];
|
||||
cc_string desc = String_FromArray(descBuffer);
|
||||
String_Format2(&desc, "%i/%i players, up for ", &server->players, &server->maxPlayers);
|
||||
LTable_FormatUptime(&desc, server->uptime);
|
||||
|
||||
cell.textLabel.text = ToNSString(&server->name);
|
||||
cell.detailTextLabel.text = ToNSString(&desc);//[ToNSString(&desc) stringByAppendingString:@"\nLine2"];
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return FetchServersTask.numServers;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static CCUIController* ui_controller;
|
||||
void LBackend_Init(void) {
|
||||
ui_controller = [[CCUIController alloc] init];
|
||||
CFBridgingRetain(ui_controller); // prevent GC TODO even needed?
|
||||
}
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
>>>>>>> b2e96605 (ios: WIP on native table widget)
|
||||
void LBackend_ButtonInit(struct LButton* w, int width, int height) {
|
||||
UIButton* btn = [[UIButton alloc] init];
|
||||
btn.frame = CGRectMake(0, 0, width, height);
|
||||
// TODO should be app_handle, because win_handle can change
|
||||
[btn addTarget:win_handle action:@selector(handleButtonPress:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[btn addTarget:ui_controller action:@selector(handleButtonPress:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
AssignView(w, btn);
|
||||
UpdateWidgetDimensions(w);
|
||||
@ -680,6 +720,7 @@ void LBackend_CheckboxDraw(struct LCheckbox* w) {
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------InputWidget--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
<<<<<<< HEAD
|
||||
static void LBackend_HandleInput(id ipt_obj) {
|
||||
struct LWidget* w = FindWidgetForView(ipt_obj);
|
||||
if (w == NULL) return;
|
||||
@ -693,13 +734,14 @@ static void LBackend_HandleInput(id ipt_obj) {
|
||||
if (ipt->TextChanged) ipt->TextChanged(ipt);
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> b2e96605 (ios: WIP on native table widget)
|
||||
void LBackend_InputInit(struct LInput* w, int width) {
|
||||
UITextField* fld = [[UITextField alloc] init];
|
||||
fld.frame = CGRectMake(0, 0, width, 30);
|
||||
fld.borderStyle = UITextBorderStyleBezel;
|
||||
fld.backgroundColor = [UIColor whiteColor];
|
||||
// TODO should be app_handle, because win_handle can change
|
||||
[fld addTarget:win_handle action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged];
|
||||
[fld addTarget:ui_controller action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged];
|
||||
|
||||
if (w->type == KEYBOARD_TYPE_INTEGER) {
|
||||
[fld setKeyboardType:UIKeyboardTypeNumberPad];
|
||||
@ -799,14 +841,21 @@ void LBackend_SliderDraw(struct LSlider* w) {
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------TableWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void LBackend_TableInit(struct LTableView* w) {
|
||||
void LBackend_TableInit(struct LTable* w) {
|
||||
UITableView* tbl = [[UITableView alloc] init];
|
||||
tbl.frame = CGRectMake(0, 0, 200, 30);
|
||||
tbl.frame = CGRectMake(0, 50, 350, 570);
|
||||
tbl.delegate = ui_controller;
|
||||
tbl.dataSource = ui_controller;
|
||||
|
||||
AssignView(w, tbl);
|
||||
UpdateWidgetDimensions(w);
|
||||
}
|
||||
|
||||
void LBackend_TableUpdate(struct LTable* w) {
|
||||
UITableView* tbl = (__bridge UITableView*)w->meta;
|
||||
[tbl reloadData];
|
||||
}
|
||||
|
||||
void LBackend_TableDraw(struct LTable* w) { }
|
||||
void LBackend_TableReposition(struct LTable* w) { }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user