ui/winui/button.cpp

changeset 3
f154867f54dc
parent 0
2483f517c562
--- a/ui/winui/button.cpp	Sat Jan 27 17:50:19 2024 +0100
+++ b/ui/winui/button.cpp	Sun Jan 28 16:31:34 2024 +0100
@@ -46,13 +46,39 @@
 
 
 
-static void set_button_label(ButtonBase button, const char* label, const char* stockid) {
-	if (label) {
+static void set_button_label(ButtonBase button, const char* label, const char* stockid, const char *icon, UiLabelType type) {
+	// TODO: stockid
+
+	if (type == UI_LABEL_ICON) {
+		label = NULL;
+	}
+	else if (type == UI_LABEL_TEXT) {
+		icon = NULL;
+	}
+
+	if (label && icon) {
+		StackPanel panel = StackPanel();
+		panel.Orientation(Orientation::Horizontal);
+		panel.Spacing(5);
+		
+		panel.Children().Append(ui_get_icon(icon));
+
+		wchar_t* wlabel = str2wstr(label, nullptr);
+		TextBlock label = TextBlock();
+		label.Text(wlabel);
+		panel.Children().Append(label);
+		free(wlabel);
+
+		button.Content(panel);
+	}
+	else if (label) {
 		wchar_t* wlabel = str2wstr(label, nullptr);
 		button.Content(box_value(wlabel));
 		free(wlabel);
 	}
-	// TODO: stockid
+	else if (icon) {
+		button.Content(ui_get_icon(icon));
+	}
 }
 
 
@@ -61,7 +87,7 @@
 
 	// create button with label
 	Button button = Button();
-	set_button_label(button, args.label, args.stockid);
+	set_button_label(button, args.label, args.stockid, args.icon, args.labeltype);
 
 	// create toolkit wrapper object and register destructor
 	UIElement elm = button;
@@ -149,7 +175,7 @@
 	UiObject* current = uic_current_obj(obj);
 
 	// set label
-	set_button_label(button, args.label, args.stockid);
+	set_button_label(button, args.label, args.stockid, args.icon, args.labeltype);
 	togglebutton_register_callback(button, obj, args);
 
 	// create toolkit wrapper object and register destructor
@@ -236,7 +262,7 @@
 	UiObject* current = uic_current_obj(obj);
 
 	// set label
-	set_button_label(button, args.label, args.stockid);
+	set_button_label(button, args.label, args.stockid, args.icon, args.labeltype);
 	togglebutton_register_callback(button, obj, args);
 
 	// create toolkit wrapper object and register destructor

mercurial