feat: new image widget features & fully remove icon

This commit is contained in:
Byson94
2025-12-23 14:57:52 +05:30
parent df7226d06c
commit ad79e81c50
7 changed files with 22 additions and 20 deletions

View File

@@ -15,8 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- `transition_duration` property to stack widget.
- `widget_control` utility function for dynamic widget handling.
- `text` and `show_text` property to progressbar widget.
- Use built-in GTK image rendering feature on image widget.
- Better image rendering for image widget.
- `content_fit` property to image widget.
- `can_shrink` property to image widget.
### Fixed
@@ -25,7 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
### Removed
- icon widget.
- `image_width` from image widget.
- `image_height` from image widget.
- `preserve_aspect_ratio` from image widget.
## [0.3.1] - 2025-11-01

View File

@@ -65,7 +65,6 @@ fn build_gtk_widget_from_node(
WidgetNode::Scale { props } => build_gtk_scale(props, widget_reg)?.upcast(),
WidgetNode::Progress { props } => build_gtk_progress(props, widget_reg)?.upcast(),
WidgetNode::Image { props } => build_image(props, widget_reg)?.upcast(),
WidgetNode::Icon { props } => build_icon(props, widget_reg)?.upcast(),
WidgetNode::Button { props } => build_gtk_button(props, widget_reg)?.upcast(),
WidgetNode::Label { props } => build_gtk_label(props, widget_reg)?.upcast(),
// WIDGET_NAME_LITERAL => build_gtk_literal(node)?.upcast(),

View File

@@ -1492,15 +1492,12 @@ pub(super) fn build_image(
let apply_props = |props: &Map, widget: &gtk4::Picture| -> Result<()> {
let path = get_string_prop(&props, "path", None)?;
let preserve_aspect_ratio = get_bool_prop(&props, "preserve_aspect_ratio", Some(true))?;
let can_shrink = get_bool_prop(&props, "can_shrink", Some(true))?;
let content_fit_str = get_string_prop(&props, "content_fit", Some("contain"))?;
let content_fit = parse_content_fit(&content_fit_str)?;
widget.set_content_fit(if preserve_aspect_ratio {
gtk4::ContentFit::Contain
} else {
gtk4::ContentFit::Fill
});
widget.set_can_shrink(true);
widget.set_can_grow(true);
widget.set_content_fit(content_fit);
widget.set_can_shrink(can_shrink);
if path.ends_with(".gif") {
let pixbuf_animation =

View File

@@ -322,3 +322,14 @@ unsafe fn list_interface_properties(iface_type: glib::Type) -> Vec<glib::ParamSp
props
}
/// Picture widget
pub(super) fn parse_content_fit(cf: &str) -> Result<gtk4::ContentFit> {
match cf.to_ascii_lowercase().as_str() {
"fill" => Ok(gtk4::ContentFit::Fill),
"contain" => Ok(gtk4::ContentFit::Contain),
"cover" => Ok(gtk4::ContentFit::Cover),
"scaledown" => Ok(gtk4::ContentFit::ScaleDown),
_ => Err(anyhow!("Invalid content fit: '{}'", cf)),
}
}

View File

@@ -13,7 +13,6 @@ pub enum WidgetNode {
FlowBox { props: Map, children: Vec<WidgetNode> },
Button { props: Map },
Image { props: Map },
Icon { props: Map },
Input { props: Map },
Progress { props: Map },
ComboBoxText { props: Map },
@@ -118,10 +117,6 @@ pub fn get_id_to_widget_info<'a>(
// let id = hash_props_and_type(props, "Image");
insert_wdgt_info(node, props, "Image", &[], parent_id, id_to_props)?;
}
WidgetNode::Icon { props } => {
// let id = hash_props_and_type(props, "Icon");
insert_wdgt_info(node, props, "Icon", &[], parent_id, id_to_props)?;
}
WidgetNode::Button { props } => {
// let id = hash_props_and_type(props, "Button");
insert_wdgt_info(node, props, "Button", &[], parent_id, id_to_props)?;

View File

@@ -44,7 +44,6 @@ pub fn register_all_widgets(
register_primitive!("label", Label);
register_primitive!("button", Button);
register_primitive!("image", Image);
register_primitive!("icon", Icon);
register_primitive!("input", Input);
register_primitive!("progress", Progress);
register_primitive!("combo_box_text", ComboBoxText);

View File

@@ -99,7 +99,6 @@ impl WidgetNode {
node @ WidgetNode::Label { props }
| node @ WidgetNode::Button { props }
| node @ WidgetNode::Image { props }
| node @ WidgetNode::Icon { props }
| node @ WidgetNode::Input { props }
| node @ WidgetNode::Progress { props }
| node @ WidgetNode::ComboBoxText { props }
@@ -117,7 +116,6 @@ impl WidgetNode {
WidgetNode::Label { .. } => WidgetNode::Label { props: new_props },
WidgetNode::Button { .. } => WidgetNode::Button { props: new_props },
WidgetNode::Image { .. } => WidgetNode::Image { props: new_props },
WidgetNode::Icon { .. } => WidgetNode::Icon { props: new_props },
WidgetNode::Input { .. } => WidgetNode::Input { props: new_props },
WidgetNode::Progress { .. } => WidgetNode::Progress { props: new_props },
WidgetNode::ComboBoxText { .. } => {